[英]How to patch container env variable in deployment with kubectl?
When I want to exctract the current value of some container env variabe I could use jsonpath with syntax like:当我想提取一些容器环境变量的当前值时,我可以使用 jsonpath 的语法如下:
kubectl get pods -l component='somelabel' -n somenamespace -o \
jsonpath='{.items[*].spec.containers[*].env[?(@.name=="SOME_ENV_VARIABLE")].value}')
That will return me the value of env varialbe with the name SOME_ENV_VARIABLE
.这将返回名为SOME_ENV_VARIABLE
的 env varialbe 的值。 Pod section with container env variables in json will look like this: json 中带有容器环境变量的 Pod 部分将如下所示:
"spec": {
"containers": [
{
"env": [
{
"name": "SOME_ENV_VARIABLE",
"value": "some_value"
},
{
"name": "ANOTHER_ENV_VARIABLE",
"value": "another_value"
}
],
When I want to patch some value in my deployment I'm using commands with syntax like:当我想在我的部署中修补一些值时,我使用的命令的语法如下:
kubectl -n kube-system patch svc kubernetes-dashboard --type='json' -p="[{'op': 'replace', 'path': '/spec/ports/0/nodePort', 'value': $PORT}]"
But how can I patch a variable with 'op': 'replace'
in cases where I need to use expression like env[?(@.name=="SOME_ENV_VARIABLE")]
?但是,如果我需要使用像env[?(@.name=="SOME_ENV_VARIABLE")]
这样的表达式,如何使用'op': 'replace'
修补变量? Which syntax I should use?我应该使用哪种语法?
Rather than kubectl patch command, you can make use of kubectl set env to update environment variable of k8s deployment.您可以使用kubectl set env来更新 k8s 部署的环境变量,而不是kubectl patch命令。
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.希望这可以帮助。
他们中的大多数都没有提供正确的命令,只是使用简单=>
kubectl set env deployment/deploy_name APP_VERSION=value -n namespace
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.