kubernetes on AWS get region name in pod

6/3/2018

I am running a kubernetes cluster on AWS-ec2 and I would like to have the pod (container) know during runtime which region it's running on, how can this be done?

-- in need of help
amazon-web-services
docker
kubernetes

3 Answers

9/13/2019

Take a look at AWS Instance Metadata:

[...] instance metadata is available from your running instance, you do not need to use the Amazon EC2 console or the AWS CLI. This can be helpful when you're writing scripts to run from your instance

You can query the region of a given container querying the metadata from inside during runtime. Like this:

curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone

placement/availability-zone: The Availability Zone in which the instance launched.

-- Eduardo Baitello
Source: StackOverflow

9/13/2019

Get the details of the nodes and you will be able to see the region of the nodes

kubectl get nodes -A
-- user1044173
Source: StackOverflow

6/3/2018

There are a few suggestions in this similar question: Inject node labels into Kubernetes pod

Options:

  1. Sidecar container that queries the Kubernetes API
  2. Place a data/configuration file on each node containing the region info
-- brandon-barnett
Source: StackOverflow