Asking for help? Comment out what you need so we can get more information to help you!
Hello,I have a question to ask you. When I deploy a zookeeper cluster, how can I directly obtain the 0-N value behind the pod-name through the environment variables in the yaml file, for example:
I deployed a zookeeper cluster in statefuleset mode. Their pod names are zookeeper-0, zookeeper-1 and zookeeper-2. How do I get the three numbers 0, 1 and 2 in each container?
The following is how to write environment variables in my yaml file
env: - name: ZOO_SERVER_ID value: $(sub "$(hostname)" "zookeeper-") valueFrom: fieldRef: fieldPath: metadata.labels['statefulset.kubernetes.io/pod-name']
I found that I can only get the pod-name. Here is how I got it. Can anyone help me find out how to get the number?
Kubernetes version: 1.18
Cloud being used: (put bare-metal if not on a public cloud) bare metal
Installation method: kubeadm
Host OS: centos7
docker and version: 19.03
You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.