Kubernetes:从Pods访问外部系统不起作用

时间:2017-05-26 08:02:31

标签: spring-boot apache-kafka kubernetes iptables minikube

我正在尝试访问 一个kubernetes pod(在minikube-VM内)到外部 Zookeeper / Kafka(kubernetes-domain之外),这基本上没有&#39工作。

首先,我有一个docker-image,它运行一个Spring-Boot应用程序,它试图在启动时连接到端口2181/9092上的Kafka-Instance。由于我创建了一个带有端点的服务,它指向应该修复路由的外部主机/ 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
&#13;
&#13;
&#13;

我检查了minikube VM上的iptables,因为它声明包被拒绝了。因此,清理无法解决问题,因为它会在幕后自动重建。

&#13;
&#13;
$ 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 

....
&#13;
&#13;
&#13;

缓解星座的另一种方法:

我用ncat -l 192.168.99.1 2181 --keep-open运行ncat 在主机上,zookeeper / Kafka应该在哪里运行 并尝试从minikube-VM连接 telnet 192.168.99.1 2181 我没有任何承诺来主持&#39; ...

那么如何解决这个问题呢? 如何添加解决iptables问题的服务? (我使用了BuildDate构建的kubernetes:&#34; 2017-05-10T15:48:59Z&#34;)

BR

1 个答案:

答案 0 :(得分:0)

当您使用Minikube时,我认为问题是因为Zookeeper / Kafka IP地址(192.168.99.1)。您可以通过执行minikube ssh并执行ip addr

来查看Minikube正在使用网络192.168.99.0/24
  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

因此,如果zookeeper / kafka应该在Minikube网络之外,则可能与IP冲突。我建议你为这个外部服务使用不同的IP(例如:192.168.200.xx)。