我有以下清单创建了名为“ test”的正在运行的吊舱
apiVersion: v1
kind: Pod
metadata:
name: hello-world
labels:
app: blue
spec:
containers:
- name: funskies
image: busybox
command: ["/bin/sh", "-c", "echo 'Hello World'"]
我想更新Pod以包含其他命令
apiVersion: v1
kind: Pod
metadata:
name: hello-world
labels:
app: blue
spec:
containers:
restartPolicy: Never
- name: funskies
image: busybox
command: ["/bin/sh", "-c", "echo 'Hello World' > /home/my_user/logging.txt"]
我尝试了什么
kubectl edit pod test
结果是什么
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
# pods "test" was not valid:
# * spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`...
我尝试过的其他方法:
更新了清单,然后运行应用-相同的问题
kubectl apply -f test.yaml
问题:更新正在运行的Pod的正确方法是什么?
您不能修改Pod的大多数属性。通常,您不想直接创建Pod。使用更高级别的控制器(例如“部署”)。
有关PodSpec注释的Kubernetes文档(重点是我的):
containers
:属于该容器的容器列表。当前无法添加或删除容器。豆荚中必须至少有一个容器。无法更新。
在所有情况下,无论如何,容器都会运行一个命令,如果要更改该命令,则需要删除并重新创建容器。在Kubernetes中,这始终意味着删除并重新创建包含的Pod。通常,您不应该使用裸Pod,但是如果您使用裸Pod,则可以使用新命令创建一个新Pod,然后删除旧Pod。删除Pod是非常常规的操作,并且各种普通的事情都会导致它发生(更新Deployment,缩小HorizontalPodAutoscaler等)。
如果您有一个Deployment而不是一个裸Pod,则可template:
以为它创建的Pod自由更改。这包括更改其command:
。这将导致Deployment使用新命令创建一个新的Pod,并在其运行后删除旧的Pod。
您在问题中显示的那种非常短暂的单命令容器不一定适合在Kubernetes中运行。如果Pod不能保持运行并处理请求,那么Job可能是更好的选择;但是Job认为它只会运行一次,如果您更改已完成Job的pod规格,我认为它不会启动新的Pod。您需要为此案例创建一个新的Job。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句