Inject node labels into Kubernetes pod

后端 未结 3 1216
死守一世寂寞
死守一世寂寞 2020-12-04 02:20

I am looking to deploy services to a Kubernetes cluster running over multiple zones and would like to be able to inject the region/zone labels into my pods using environment

相关标签:
3条回答
  • 2020-12-04 02:47

    One option to achieve this is to store a custom file on each node that contains definitions of the environment variables that you want. Then you mount the folder containing the file into the container and source the file content as part of the startup of your container.

    A similar approach for Kubernetes secrets is described here: https://github.com/kubernetes/kubernetes/blob/master/docs/design/secrets.md#deferral-consuming-secrets-as-environment-variables

    0 讨论(0)
  • 2020-12-04 02:54

    I thought about was having the container query the kubernetes/AWS API to fetch this information however that would mean adding quite a lot of complexity to my containers.

    This is currently the recommended approach for getting information not available in the downward API. To avoid the additional complexity in your containers, you could use a "sidecar" with a variation on Tobias's solution. The sidecar would be an additional container in the pod, which connects to the kubernetes API, queries the information you're looking for (node labels), and writes the output to a shared volume. This could be implemented as an init container, or a sidecar that continuously syncs with the API.

    0 讨论(0)
  • 2020-12-04 03:00

    As a derivative of Tim St. Clair's answer, you may also consider writing out the pod metadata from within a PostStart container hook. Go grab the metadata you want from a well known URL. Then write it out to k8s via the API. This has the advantage that it is a one-and-done execution. No need to keep a side-car running since region and zone info won't change.

    0 讨论(0)
提交回复
热议问题