Kubernetes:kubectl apply 在使用“最新"时不会更新 Pod;标签 [英] Kubernetes: kubectl apply does not update pods when using "latest" tag
问题描述
我正在使用 kubectl apply
来更新我的 Kubernetes pod:
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
下面是我的部署.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%
这第一次运行良好,但在后续运行中,我的 Pod 没有得到更新.
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.
我知道我可以通过手动将图像标签从最新"更改为另一个标签来触发 pod 更新,但我想确保我获得最新的图像而无需检查 Docker Hub.
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屋!