Mayur Sharma:
Hi , are we not allowed to set/change the env variables on running pod using imperative commands?
In configMap practice lab, Question 5, I am trying to change the environment variable on running pod using below command and getting the error,
root@controlplane:~# kubectl set env pod/webapp-color APP_COLOR=green
error: failed to patch env update to pod template: Pod “webapp-color” is invalid: spec: Forbidden: pod updates may not change fields other than spec.containers[*].image
, spec.initContainers[*].image
, spec.activeDeadlineSeconds
or spec.tolerations
(only additions to existing tolerations)
As per the Kubectl command reference, I see examples for deployment but not for pods
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#-em-env-em-
Mayank:
I think you can not edit running pod definition. You have to recreate it. I will also watch out for other’s response.
Mayur Sharma:
@Mayank AS of now, I have saved the output of get, update yaml, delete existing, create new one.
Mayank:
thats correct. I do the same.
Himanshu Sharma:
It’s by design you can not edit a running pod.
Mayank:
Edit a POD
Remember, you CANNOT edit specifications of an existing POD other than the below.
• spec.containers[].image
• spec.initContainers[].image
• spec.activeDeadlineSeconds
• spec.tolerations
Source: lecture 39
Mayur Sharma:
Thanks all for the comments.
I asked this doubt as there is a kubernetes documentation to set the env variables for deployments and RS,
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#-em-env-em-
May be the reason is that these high level objects always restart the pod in case of change.
It’s feed in my mind now