<p>I'm trying to run a zookeeper ensemble and am having an issue passing a unique ID as envrionment varible <code>ZOO_MY_ID</code> as required by official zookeeeper image found <a href="https://hub.docker.com/_/zookeeper" rel="nofollow noreferrer">here</a>. </p>

<p>I've tried reading about this and found similar overflow questions but none seems to be working. </p>

<p><a href="https://stackoverflow.com/questions/42521838/kubernetes-statefulsets-index-ordinal-exposed-in-template">kubernetes statefulsets index/ordinal exposed in template</a>
<a href="https://stackoverflow.com/questions/50750672/is-there-a-way-to-get-ordinal-index-of-a-pod-with-in-kubernetes-statefulset-conf">Is there a way to get ordinal index of a pod with in kubernetes statefulset configuration file?</a></p>

<p>For some reason, I am still seeing the ID for all servers to be the default id of 1</p>

<pre><code>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
</code></pre>

<p>Running the following command shows that no ID is passed however I am using the hacky way shown here: <a href="https://stackoverflow.com/a/48086813/5813215">https://stackoverflow.com/a/48086813/5813215</a></p>

<p><code>kubectl exec -it zoo-2 -n kafka-dev printenv | grep "ZOO_"</code></p>

<pre><code>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
</code></pre>

Ani Aggarwal
<p>I am not sure if it was resolved so:</p>

<blockquote>
  <p>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.</p>
</blockquote>

<p>You can find an example <a href="https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#pods-in-a-statefulset" rel="noreferrer">here</a>.</p>

<p>For example You can modify your statefulSet spec. by adding:</p>

<pre><code>   env:
      - name: MY_POD_NAME
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
</code></pre>

<p>You can parse the index out of that.</p>

<p>More information and discussion about this particular topic you can find <a href="https://github.com/kubernetes/kubernetes/issues/40651" rel="noreferrer">here</a></p>

<p>Hope this help.</p>
