How can a Pod know which availability zone it locates?

Cheng Peng 66 Reputation points
2021-03-25T06:52:46.89+00:00

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://learn.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
Azure Kubernetes Service
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,459 questions
0 comments No comments
{count} votes

Accepted answer
  1. vipullag-MSFT 26,492 Reputation points Moderator
    2021-03-25T09:17:38.933+00:00

    @Cheng Peng

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.