EKS - Get availability zone of pod deployment from within pod

0

In my EKS cluster, I have a few node groups that cover availability zone A and B. The pods running on the nodes are consumers/producers on various Kafka topics (MSK). There isn't any internal communication between the pods.

I have two brokers for the MSK cluster, one in each availability zone that the pods use.

I am concerned that since the pods can be deployed in either availability zone, I might be unknowingly charged for data that is being transferred between the availability zones as the pod doesn't have a preference to which broker it talks to

To avoid this, I am thinking of having the pod select the broker server to talk to once it has started, and to do this it needs to know what availability zone the underlying node its been deployed on.

I was imagining that it would be possible to have the deployment pull the zone information like any other spec field e.g. https://docs.microsoft.com/en-us/answers/questions/330925/how-can-a-pod-know-which-availability-zone-it-loca.html but that isn't a valid field.

I have tried hitting the ec2 metadata ip address like the link below but since its a pod with its own IP on the node, I assume this mechanism doesn't work. https://www.quora.com/How-do-I-find-out-in-which-availability-zone-a-AWS-EC2-server-is

None of the field listed https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#podspec-v1-core seem to have any field that could identify this.

Is there a way of doing this? Or is there a better way of networking the pods/node groups?

已提問 2 年前檢視次數 4206 次
1 個回答
1
已接受的答案

EC2 Instance Metadata Service v2 can be leveraged to get the AZ details. Amazon EKS supports containers to access instance metadata using the IMDSv2 format. https://aws.amazon.com/about-aws/whats-new/2020/08/amazon-eks-supports-ec2-instance-metadata-service-v2/

AWS
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南