【k8s】deploy-pod-template-hash
环境
- kubernetes 1.20.4
- Spring Boot 2.5.0-M3
目标
pod-template-hash 标签是 deploy 自动给它生成 rs 和 pod 加上的。
标签的值是 rs 名称的后缀,一是让 rs 生成不重复,而是可以唯一识别 rs。
deploy 可以生成多个 rs,其中这个标签的值也会跟着变化。
不要修改此标签,否则 deploy 不能正常管理 rs 和 pod。
示例
Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: busybox
spec:
selector:
matchLabels:
app: busybox
replicas: 4
template:
metadata:
labels:
app: busybox
spec:
terminationGracePeriodSeconds: 5
containers:
- name: busybox
image: busybox:1.30.0
command: ["/bin/sh", "-c", "sleep 3600"]
查看 rs
[root@master ~]# kubectl describe rs
Name: busybox-6bd65c67cf
Namespace: default
Selector: app=busybox,pod-template-hash=6bd65c67cf
Labels: app=busybox
pod-template-hash=6bd65c67cf
Annotations: deployment.kubernetes.io/desired-replicas: 4
deployment.kubernetes.io/max-replicas: 5
deployment.kubernetes.io/revision: 1
Controlled By: Deployment/busybox
Replicas: 4 current / 4 desired
Pods Status: 4 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: app=busybox
pod-template-hash=6bd65c67cf
Containers:
busybox:
Image: busybox:1.30.0
Port: <none>
Host Port: <none>
Command:
/bin/sh
-c
sleep 3600
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 7m33s replicaset-controller Created pod: busybox-6bd65c67cf-9hz9g
Normal SuccessfulCreate 7m33s replicaset-controller Created pod: busybox-6bd65c67cf-frbcn
Normal SuccessfulCreate 7m33s replicaset-controller Created pod: busybox-6bd65c67cf-98xb7
Normal SuccessfulCreate 7m33s replicaset-controller Created pod: busybox-6bd65c67cf-6xphf
pod-template-hash 标签的值和 rs 名称后缀相同。
查看 pod
[root@master ~]# kubectl describe pod busybox-6bd65c67cf-6xphf
Name: busybox-6bd65c67cf-6xphf
Namespace: default
Priority: 0
Node: node1/192.168.56.102
Start Time: Tue, 30 Mar 2021 22:05:36 +0800
Labels: app=busybox
pod-template-hash=6bd65c67cf
Annotations: <none>
Status: Running
IP: 10.244.1.248
IPs:
IP: 10.244.1.248
Controlled By: ReplicaSet/busybox-6bd65c67cf
Containers:
busybox:
...
具有和 rs 一样的 pod-template-hash 标签。
总结
介绍了 pod-template-hash 标签的作用。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!