Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubernetes on AWS get region name in pod

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?

like image 501
in need of help Avatar asked Nov 08 '22 06:11

in need of help


2 Answers

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.

like image 106
Eduardo Baitello Avatar answered Nov 14 '22 23:11

Eduardo Baitello


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
like image 39
brandon-barnett Avatar answered Nov 14 '22 22:11

brandon-barnett