问题描述
使用K8仪表板的 Edit 添加到吊舱spec.containers
中的env
元素不会保存.有人知道问题出在哪里吗?
The env
element added in spec.containers
of a pod using K8 dashboard's Edit doesn't get saved. Does anyone know what the problem is?
还有其他方法可以将环境变量添加到吊舱/容器中吗?
Is there any other way to add environment variables to pods/containers?
通过使用nano编辑文件来执行此操作时出现此错误:
I get this error when doing the same by editing the file using nano:
# pods "EXAMPLE" was not valid:
# * spec: Forbidden: pod updates may not change fields other than `containers[*].image` or `spec.activeDeadlineSeconds`
谢谢.
推荐答案
并非所有字段都可以更新.在对象的kubectl explain
输出中有时会提到这一事实(并且您收到的错误列出了可以更改的字段,因此其他字段可能无法更改).
Not all fields can be updated. This fact is sometimes mentioned in the kubectl explain
output for the object (and the error you got lists the fields that can be changed, so the others probably cannot).:
$ kubectl explain pod.spec.containers.env
RESOURCE: env <[]Object>
DESCRIPTION:
List of environment variables to set in the container. Cannot be updated.
EnvVar represents an environment variable present in a Container.
如果您使用部署对象部署Pod,则可以更改那个对象中的环境变量与kubectl edit
一起使用,因为部署将推出具有变量更改的Pod的更新版本,并杀死没有该变量的较旧的Pod.显然,该方法不会更改Pod的位置,但这是获得所需内容的一种方法.
If you deploy your Pods using a Deployment object, then you can change the environment variables in that object with kubectl edit
since the Deployment will roll out updated versions of the Pod(s) that have the variable changes and kill the older Pods that do not. Obviously, that method is not changing the Pod in place, but it is one way to get what you need.
您的另一个选择可能是使用 ConfigMaps .如果使用卷插件方法安装ConfigMap 和,则编写应用程序时要注意卷的更改并在更改时使用新设置重新加载自身,这可能是一个选择(或者至少是您可能对您有用的其他想法).
Another option for you may be to use ConfigMaps. If you use the volume plugin method for mounting the ConfigMap and your application is written to be aware of changes to the volume and reload itself with new settings on change, it may be an option (or at least give you other ideas that may work for you).
这篇关于Kubernetes部署:编辑Pod的YAML文件的“规范"失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!