我正在尝试在kubernetes pod(在 minikube-VM 内)访问外部Zookeeper/Kafka(在 kubernetes-domain 外),这基本上是行不通的。
首先,我有一个 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
我检查了 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
我得到“没有 rotue to host”...
那么如何解决这个问题?如何添加解决 iptables- 问题的服务?(我使用了来自 BuildDate:"2017-05-10T15:48:59Z" 的 kubernetes 构建)
BR