我在 OpenShift/Kubernetes 环境中运行 Zookeeper。StatefulSet
为了可靠地持久化配置数据,我已经设置了 zookeeper 。
我在我zoo.cfg
的主机名中配置了三台服务器,但在启动时,主机名解析失败。我验证了主机名确实可以在集群中使用 nslookup 解析。
动物园.cfg:
clientPort=2181
dataDir=/var/lib/zookeeper/data
dataLogDir=/var/lib/zookeeper/log
tickTime=2000
initLimit=10
syncLimit=2000
maxClientCnxns=60
minSessionTimeout= 4000
maxSessionTimeout= 40000
autopurge.snapRetainCount=3
autopurge.purgeInteval=0
server.1=zookeeper-0.zookeeper-headless:2888:3888
server.2=zookeeper-1.zookeeper-headless:2888:3888
server.3=zookeeper-2.zookeeper-headless:2888:3888
我的 OpenShift / Kubernetes 配置的相关部分:
# StatefulSet
- apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
labels:
app: zookeeper
name: zookeeper
spec:
serviceName: zookeeper-headless
replicas: 3
template:
metadata:
labels:
app: zookeeper
spec:
containers:
- image: 172.30.158.156:5000/os-cloud-platform/zookeeper:latest
name: zookeeper
ports:
- containerPort: 2181
protocol: TCP
name: client
- containerPort: 2888
protocol: TCP
name: server
- containerPort: 3888
protocol: TCP
name: leader-election
dnsPolicy: ClusterFirst
schedulerName: default-scheduler
# Service
- apiVersion: v1
kind: Service
metadata:
labels:
app: zookeeper
name: zookeeper
spec:
ports:
- name: client
port: 2181
protocol: TCP
targetPort: 2181
selector:
app: zookeeper
sessionAffinity: None
type: ClusterIP
- apiVersion: v1
kind: Service
metadata:
name: zookeeper-headless
labels:
app: zookeeper
spec:
ports:
- port: 2888
name: server
- port: 3888
name: leader-election
clusterIP: None
selector:
app: zookeeper
但是, OpenShift 日志显示UnknownHostException
s:
2017-10-06 10:59:18,289 [myid:] - WARN [main:QuorumPeer$QuorumServer@155] - Failed to resolve address: zookeeper-2.zookeeper-headless
java.net.UnknownHostException: zookeeper-2.zookeeper-headless: No address associated with hostname
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at java.net.InetAddress.getByName(InetAddress.java:1076)
at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.recreateSocketAddresses(QuorumPeer.java:148)
at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.<init>(QuorumPeer.java:133)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:228)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:140)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:101)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)
...
可能是什么原因?我验证了主机名(例如zookeeper-2.zookeeper-headless
)可从其他 pod 通过nslookup
.