有没有更简单的方法将序号索引传递给 StatefulSet 环境变量?
Is there any less hacky way of passing an Ordinal Index to StatefulSet environment variable?
我正在尝试 运行 一个动物园管理员合奏,但在按照找到的官方动物园管理员图片 here 的要求将唯一 ID 作为环境变量 ZOO_MY_ID
传递时遇到问题。
我已尝试阅读此内容并发现了类似的溢出问题,但 none 似乎有效。
kubernetes statefulsets index/ordinal exposed in template
Is there a way to get ordinal index of a pod with in kubernetes statefulset configuration file?
出于某种原因,我仍然看到所有服务器的 ID 都是默认 ID 1
2019-05-24 01:38:31,648 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@847] - Notification time out: 60000
2019-05-24 01:38:31,649 [myid:1] - INFO [WorkerSender[myid=1]:QuorumCnxManager@347] - Have smaller server identifier, so dropping the connection: (2, 1)
2019-05-24 01:38:31,649 [myid:1] - INFO [WorkerReceiver[myid=1]:FastLeaderElection@595] - Notification: 1 (message format version), 1 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
2019-05-24 01:38:31,649 [myid:1] - INFO [/0.0.0.0:3888:QuorumCnxManager$Listener@743] - Received connection request /10.24.1.64:37382
2019-05-24 01:38:31,650 [myid:1] - WARN [RecvWorker:1:QuorumCnxManager$RecvWorker@1025] - Connection broken for id 1, my id = 1, error =
java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:392)
at org.apache.zookeeper.server.quorum.QuorumCnxManager$RecvWorker.run(QuorumCnxManager.java:1010)
2019-05-24 01:38:31,651 [myid:1] - WARN [RecvWorker:1:QuorumCnxManager$RecvWorker@1028] - Interrupting SendWorker
运行 下面的命令显示没有传递 ID 但是我使用这里显示的 hacky 方式:
kubectl exec -it zoo-2 -n kafka-dev printenv | grep "ZOO_"
ZOO_USER=zookeeper
ZOO_CONF_DIR=/conf
ZOO_DATA_DIR=/data
ZOO_DATA_LOG_DIR=/datalog
ZOO_LOG_DIR=/logs
ZOO_PORT=2181
ZOO_TICK_TIME=2000
ZOO_INIT_LIMIT=5
ZOO_SYNC_LIMIT=2
ZOO_AUTOPURGE_PURGEINTERVAL=0
ZOO_AUTOPURGE_SNAPRETAINCOUNT=3
ZOO_MAX_CLIENT_CNXNS=60
我不确定是否已解决:
As mentioned in the StatefulSets concept, the Pods in a StatefulSet have a sticky, unique identity. This identity is based on a unique ordinal index that is assigned to each Pod by the StatefulSet controller.
你可以找到一个例子here。
例如,您可以修改 statefulSet 规范。添加:
env:
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
您可以从中解析索引。
有关此特定主题的更多信息和讨论,您可以找到 here
希望对您有所帮助。
不太确定这有什么用,但在我的情况下这对 ZooKeeper 有用:
env:
- name: POD_ID_OF_STATEFULSET
valueFrom:
fieldRef:
fieldPath: metadata.name
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo ${POD_ID_OF_STATEFULSET##*-} > ${ZOO_DATA_DIR}/myid"]
事实证明,ZOO_MY_ID
所做的唯一一件事就是传递给 ${ZOO_DATA_DIR}/myid
文件。我正在“手动”执行此操作并在入口点之前设置文件。
我正在尝试 运行 一个动物园管理员合奏,但在按照找到的官方动物园管理员图片 here 的要求将唯一 ID 作为环境变量 ZOO_MY_ID
传递时遇到问题。
我已尝试阅读此内容并发现了类似的溢出问题,但 none 似乎有效。
kubernetes statefulsets index/ordinal exposed in template Is there a way to get ordinal index of a pod with in kubernetes statefulset configuration file?
出于某种原因,我仍然看到所有服务器的 ID 都是默认 ID 1
2019-05-24 01:38:31,648 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@847] - Notification time out: 60000
2019-05-24 01:38:31,649 [myid:1] - INFO [WorkerSender[myid=1]:QuorumCnxManager@347] - Have smaller server identifier, so dropping the connection: (2, 1)
2019-05-24 01:38:31,649 [myid:1] - INFO [WorkerReceiver[myid=1]:FastLeaderElection@595] - Notification: 1 (message format version), 1 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
2019-05-24 01:38:31,649 [myid:1] - INFO [/0.0.0.0:3888:QuorumCnxManager$Listener@743] - Received connection request /10.24.1.64:37382
2019-05-24 01:38:31,650 [myid:1] - WARN [RecvWorker:1:QuorumCnxManager$RecvWorker@1025] - Connection broken for id 1, my id = 1, error =
java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:392)
at org.apache.zookeeper.server.quorum.QuorumCnxManager$RecvWorker.run(QuorumCnxManager.java:1010)
2019-05-24 01:38:31,651 [myid:1] - WARN [RecvWorker:1:QuorumCnxManager$RecvWorker@1028] - Interrupting SendWorker
运行 下面的命令显示没有传递 ID 但是我使用这里显示的 hacky 方式:
kubectl exec -it zoo-2 -n kafka-dev printenv | grep "ZOO_"
ZOO_USER=zookeeper
ZOO_CONF_DIR=/conf
ZOO_DATA_DIR=/data
ZOO_DATA_LOG_DIR=/datalog
ZOO_LOG_DIR=/logs
ZOO_PORT=2181
ZOO_TICK_TIME=2000
ZOO_INIT_LIMIT=5
ZOO_SYNC_LIMIT=2
ZOO_AUTOPURGE_PURGEINTERVAL=0
ZOO_AUTOPURGE_SNAPRETAINCOUNT=3
ZOO_MAX_CLIENT_CNXNS=60
我不确定是否已解决:
As mentioned in the StatefulSets concept, the Pods in a StatefulSet have a sticky, unique identity. This identity is based on a unique ordinal index that is assigned to each Pod by the StatefulSet controller.
你可以找到一个例子here。
例如,您可以修改 statefulSet 规范。添加:
env:
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
您可以从中解析索引。
有关此特定主题的更多信息和讨论,您可以找到 here
希望对您有所帮助。
不太确定这有什么用,但在我的情况下这对 ZooKeeper 有用:
env:
- name: POD_ID_OF_STATEFULSET
valueFrom:
fieldRef:
fieldPath: metadata.name
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo ${POD_ID_OF_STATEFULSET##*-} > ${ZOO_DATA_DIR}/myid"]
事实证明,ZOO_MY_ID
所做的唯一一件事就是传递给 ${ZOO_DATA_DIR}/myid
文件。我正在“手动”执行此操作并在入口点之前设置文件。