You can set environment variables for containers running in a pod and in
addition, Kubernetes exposes certain runtime infos via environment variables
automatically.
Let’s launch a pod that we pass an
environment variable SIMPLE_SERVICE_VERSION with the value 1.0:
kubectl describe pod envs | grep IP:
Now, let’s verify from within the cluster if the application running in
the pod has picked up the environment variable SIMPLE_SERVICE_VERSION:
curl 172.17.0.3:9876/info
And indeed it has picked up the user-provided environment variable (the
default, response would be "version": "0.5.0").
You can check what environment variables Kubernetes itself provides
automatically (from within the cluster, using a dedicated endpoint that
the app exposes):
curl 172.17.0.3:9876/env
Alternatively, you can also use kubectl exec to connect to the
container and list the environment variables directly, there:
kubectl exec envs -- printenv
You can destroy the created pod with:
kubectl delete pod/envs
<< Previous Next >>
No comments:
Post a Comment