【发布时间】:2020-02-04 02:48:58
【问题描述】:
出于调试和测试目的,我想找到一种最方便的方式来启动 Kubernetes pod 并即时更改其规范。
使用命令式命令很容易启动。 运行
kubectl run nginx-test --image nginx --restart=Never
给了我我想要的东西:不受任何控制器(如 Deployment 或 ReplicaSet)管理的单个 pod。在需要时易于使用和清理。
但是,当我尝试使用
编辑规范时kubectl edit po nginx-test
我收到以下警告:
pods "nginx-test" was not valid:
* 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)
即只有有限的 Pod 规范集在运行时是可编辑的。
目前发现的选项:
-
将 Pod 规范保存到文件中:
kubectl get po nginx-test -oyaml > nginx-test.yaml用
编辑和重新创建kubectl apply -f虽然只更改一个字段有点重。
-
创建一个 Deployment 而不是单个 Pod,然后在 Deployment 本身中编辑
spec部分。缺点是:
- 需要额外的 API 对象(部署),完成后不要忘记清理
- Pod 名称以
nginx-test-xxxxxxxxx-xxxx和更少的形式自动生成 方便工作。
那么在 Pod 规范中编辑 arbitrary 字段是否有更简单的选项(或者可能是一些优雅的解决方法)? 如有任何建议,我将不胜感激。
【问题讨论】:
标签: kubernetes kubectl kubernetes-pod