question

ChengPeng-1500 avatar image
0 Votes"
ChengPeng-1500 asked vipullag-MSFT answered

How can a Pod know which availability zone it locates?

Hi. I'm working with a StatefulSet in my AKS with 3 availability zones. In my scenario, each Pod has to know which zone it actually locates on and start the container with this config.
According to this doc (https://docs.microsoft.com/en-us/azure/aks/availability-zones#verify-node-distribution-across-zones), it seems I can only get the zone info from Pod's corresponding PV or AKS node. To achieve my goal, I think I have to call API server in an init-container to query zone info.
So is there any easier way to make zone info be accessible in the container or be set as env variables of PodSpec as

 env:
   - name: ZONE
     valueFrom:
       fieldRef:
         fieldPath: status.zone

Thanks in advance.

azure-kubernetes-service
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

vipullag-MSFT avatar image
0 Votes"
vipullag-MSFT answered

@ChengPeng-1500

As the nodes have zone labels, no need for init container.

You can use node affinity or/and taints and tolerations (taints and tolerations are optional if there no issues with other pods being scheduled on those nodes as well).

Check this document for information on scheduling a Pod using required node affinity.

Hope this helps.

Please 'Accept as answer' if the provided information is helpful, so that it can help others in the community looking for help on similar topics.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.