我试图在kubernetes pod内(minikube vm内)访问外部zookeeper/kafka(kubernetes域外),这基本上不起作用。
首先,我有一个docker映像,它运行一个spring引导应用程序,并在启动时尝试连接端口2181/9092上的kafka示例。因为我创建了一个带有端点的服务,该端点指向应该修复路由的外部主机/ip,但不幸的是它没有。
以下是服务/端点的定义
apiVersion: v1
kind: Service
metadata:
name: ext-kafka
namespace: default
spec:
clusterIP: None
ports:
- port: 2181
name: zk
protocol: TCP
targetPort: 2181
- port: 9092
name: kafka
protocol: TCP
targetPort: 9092
---
apiVersion: v1
kind: Endpoints
metadata:
name: ext-kafka
namespace: default
subsets:
- addresses:
# 192.168.99.1 is the external IP
- ip: 192.168.99.1
ports:
- port: 2181
name: zk
- port: 9092
name: kafka
#
# HERE ARE THE DEPLOYMENTS/DEFINITIONS THAT THE SERVICES ARE INSTALLED
#
[root@centos1 work]# kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ext-kafka None <none> 2181/TCP,9092/TCP 2d
...
[root@centos1 work]# kubectl get endpoints
NAME ENDPOINTS AGE
ext-kafka 192.168.99.1:2181,192.168.99.1:9092 2d
我检查了minikube vm上的iptables,因为它指出包被拒绝了。所以清理并不能解决问题,因为它会在幕后自动重新创建。
$ iptables -L
....
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
KUBE-FIREWALL all -- anywhere anywhere
KUBE-SERVICES all -- anywhere anywhere /* kubernetes service portals */
...
Chain KUBE-FIREWALL (2 references)
target prot opt source destination
DROP all -- anywhere anywhere /* kubernetes firewall for dropping marked packets */ mark match 0x8000/0x8000
Chain KUBE-SERVICES (1 references)
target prot opt source destination
....
REJECT tcp -- anywhere anywhere /* default/server-command: has no endpoints */ ADDRTYPE match dst-type LOCAL tcp dpt:30021 reject-with icmp-port-unreachable
REJECT tcp -- anywhere 10.0.0.240 /* default/server-command: has no endpoints */ tcp dpt:webcache
....
另一种缓解星座问题的方法是:
我和你一起跑ncat ncat -l 192.168.99.1 2181 --keep-open
在主机上,zookeeper/kafka应该在其中运行并尝试从minikube vm与 telnet 192.168.99.1 2181
我有'没有轮班主持'。。。
那么如何解决这个问题呢??如何添加服务,解决iptables问题我使用了builddate的kubernetes构建:“2017-05-10t15:48:59z”)
比尔
1条答案
按热度按时间os8fio9y1#
当您使用minikube时,我认为问题是因为zookeeper/kafka的ip地址(192.168.99.1)。您可以看到minikube正在网络192.168.99.0/24上工作
minikube ssh
执行ip addr
```3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:97:6c:ed brd ff:ff:ff:ff:ff:ff
inet 192.168.99.100/24 brd 192.168.99.255 scope global dynamic eth1
valid_lft 798sec preferred_lft 798sec
inet6 fe80::a00:27ff:fe97:6ced/64 scope link
valid_lft forever preferred_lft forever