Kubernetes:当使用“最新"版本时,kubectl apply不会更新pod.标签 [英] Kubernetes: kubectl apply does not update pods when using "latest" tag
问题描述
我正在使用kubectl apply
更新我的Kubernetes吊舱:
I'm using kubectl apply
to update my Kubernetes pods:
kubectl apply -f /my-app/service.yaml
kubectl apply -f /my-app/deployment.yaml
以下是我的service.yaml:
Below is my service.yaml:
apiVersion: v1
kind: Service
metadata:
name: my-app
labels:
run: my-app
spec:
type: NodePort
selector:
run: my-app
ports:
- protocol: TCP
port: 9000
nodePort: 30769
下面是我的deployment.yaml:
Below is my deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
selector:
matchLabels:
run: my-app
replicas: 2
template:
metadata:
labels:
run: my-app
spec:
containers:
- name: my-app
image: dockerhubaccount/my-app-img:latest
ports:
- containerPort: 9000
protocol: TCP
imagePullSecrets:
- name: my-app-img-credentials
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
第一次运行良好,但是在随后的运行中,我的广告连播没有得到更新.
This works fine the first time, but on subsequent runs, my pods are not getting updated.
我在 https://github.com/kubernetes/kubernetes/上阅读了建议的解决方法issues/33664 ,即:
kubectl patch deployment my-app -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
我能够运行以上命令,但无法为我解决问题.
I was able to run the above command, but it did not resolve the issue for me.
我知道我可以通过手动将image标签从"latest"更改为另一个标签来触发pod更新,但是我想确保无需检查Docker Hub就能获得最新的image.
I know that I can trigger pod updates by manually changing the image tag from "latest" to another tag, but I want to make sure I get the latest image without having to check Docker Hub.
任何帮助将不胜感激.
推荐答案
结果是我误解了我从链接中给出的解决方法命令.
Turns out I misunderstood the workaround command I gave from the link.
我认为这是一次配置我的部署的命令,可以将以后所有的kubectl apply
命令都视为更新我的Pod的触发器.
I thought it was a one-time command that configured my deployment to treat all future kubectl apply
commands as a trigger to update my pods.
实际上,每次我要更新Pod时,我都只需要运行命令:
I actually just had to run the command every time I wanted to update my pods:
kubectl patch deployment my-app -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
非常感谢所有帮助过的人!
Many thanks to everyone who helped!
这篇关于Kubernetes:当使用“最新"版本时,kubectl apply不会更新pod.标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!