I created EKS cluster and now i need to add http_proxy/http_proxies and no_proxy as environment variable to all 300 deployments. I created a config map with the variables. Is there a way to update all pods simultaneously without doing it one by one? And if yes how can i do it? My config map name is proxy-environment-variables.
Thank you for the help and assistance!
BR,
Martin
Name: proxy-environment-variables
Namespace: kube-system
Labels: <none>
Annotations: <none>
Data
====
HTTPS_PROXY:
----
http://10.16.11.10:8080
HTTP_PROXY:
----
http://10.16.11.10:8080
NO_PROXY:
----
169.254.169.254,127.0.0.1,localhost,10.0.0.0/8
http_proxy:
----
http://10.16.11.10:8080
https_proxy:
----
http://10.16.11.10:8080
no_proxy:
----
169.254.169.254,127.0.0.1,localhost,10.0.0.0/8
BinaryData
====
Events: <none>
You can use the set env
to update the environment variable into the deployment:
kubectl set env deployment --all --from=configmap/my-env-config
Example: The following example is demonstrating if there are multiple deployments, how to add env variables to their pods.
// I have the following deployments:
kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
dep-1 1/1 1 1 5m21s
dep-2 1/1 1 1 41m
dep-4 1/1 1 1 3m17s
// their respective pods:
kubectl get pod
NAME READY STATUS RESTARTS AGE
dep-1-84fcdf5-wblsm 1/1 Running 0 2m8s
dep-2-84fcdf5-qfbd5 1/1 Running 0 3m4s
dep-4-6cf4dcf794-wk476 1/1 Running 0 4s
// my config map:
apiVersion: v1
data:
HTTP_PROXY: https://1.2.3.4:1234
kind: ConfigMap
metadata:
creationTimestamp: "2022-05-04T16:52:00Z"
name: my-env-config
namespace: default
resourceVersion: "1002232"
uid: c8606312-90c6-45cf-86f0-f4f874f19909
// HTTP_PROXY env variable is already set in dep-1
kubectl exec -it dep-1-84fcdf5-wblsm -- printenv HTTP_PROXY
https://1.2.3.4:1234
// HTTP_PROXY env variable is already set in dep-2
kubectl exec -it dep-2-84fcdf5-qfbd5 -- printenv HTTP_PROXY
https://1.2.3.4:1234
// HTTP_PROXY env variable is not set in dep-4, this is our focus
kubectl exec -it dep-4-6cf4dcf794-wk476 -- printenv HTTP_PROXY
command terminated with exit code 1
// SOLUTION: Setting env for all the deployments(--all
) from a config map called my-env-config
)
kubectl set env deployment --all --from=configmap/my-env-config
deployment.apps/dep-4 env updated
//Note the age of the pods, only dep-4's pod age is altered
kubectl get pod
NAME READY STATUS RESTARTS AGE
dep-1-84fcdf5-wblsm 1/1 Running 0 3m40s
dep-2-84fcdf5-qfbd5 1/1 Running 0 4m36s
dep-4-59d5cfd48d-2tbbm 1/1 Running 0 5s
// now HTTP_PROXY is set in dep-4's pod.
kubectl exec -it dep-4-59d5cfd48d-2tbbm -- printenv HTTP_PROXY
https://1.2.3.4:1234