How to patch container env variable in deployment with kubectl?
Rather than kubectl patch command, you can make use of kubectl set env to update environment variable of k8s deployment.
envvalue=$(kubectl get pods -l component='somelabel' -n somenamespace -o jsonpath='{.items[*].spec.containers[*].env[?(@.name=="SOME_ENV_VARIABLE")].value}')kubectl set env deployment/my-app-deploy op=$envvalue
Hope this helps.
- op: replacepath: /spec/template/spec/containers/0/env/0/namevalue: YOUR_VARIABLE_NAME
- op: replacepath: /spec/template/spec/containers/0/env/0/valuevalue: YOUR_VARIABLE_VALUE