Here I can update the envs through kubectl patch
, then is there any method that can delete envs except re-deploy a deployment.yaml
?
$ kubectl patch deployment demo-deployment -p '{"spec":{"template":{"spec":{"containers":[{"name": "demo-deployment","env":[{"name":"foo","value":"bar"}]}]}}}}'
deployment.extensions "demo-deployment" patched
Can I delete the env "foo" through command line not using a re-deploy on the whole deployment?
Consider that containers
is an array inside an object. Arrays can only be fetched by their index
, as opposed to objects which can be fetched via key value pairs. See reference here. So there is a workaround for using index
.
Here you have env
that are placed into the container
:
spec:
containers:
- env:
- name: DEMO_GREETING
value: Hello from the environment
- name: DSADASD
value: asdsad
Here you have a command to remove the anv using index
:
kubectl patch deployments asd --type=json -p='[{"op": "remove", "path": "/spec/template/spec/containers/0/env/1"}]
And the result:
spec:
containers:
- env:
- name: DEMO_GREETING
value: Hello from the environment
This will still however restart your pod. Hope that helps!
If you are fine with redeployment then follow the below steps
envFrom:
- configMapRef:
name: app-config