【k8s】Pod-readinessGates
环境
- kubernetes 1.20.4
- Spring Boot 2.5.0-M3
目标
除了之前学习过的四种条件外,readinessGates 可以自定义 Pod 条件信息。
示例
Pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: spring-k8s
spec:
readinessGates:
- conditionType: my-condition
containers:
- name: spring-k8s
image: jiangbo920827/spring-k8s:liveness
ports:
- containerPort: 8080
查看
[root@master ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
spring-k8s 1/1 Running 0 8s 10.244.2.185 node2 <none> 0/1
[root@master ~]# kubectl get pod spring-k8s -o json | jq .status.conditions
[
{
"lastProbeTime": null,
"lastTransitionTime": "2021-03-28T10:01:51Z",
"status": "True",
"type": "Initialized"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-03-28T10:01:51Z",
"message": "corresponding condition of pod readiness gate \"my-condition\" does not exist.",
"reason": "ReadinessGatesNotReady",
"status": "False",
"type": "Ready"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-03-28T10:01:52Z",
"status": "True",
"type": "ContainersReady"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-03-28T10:01:51Z",
"status": "True",
"type": "PodScheduled"
}
]
可以看到 Read 条件因为我们自定义的条件不满足而变成了 False。
由于状态字段不能通过 kubectl 命令进行修改,所以只能使用 API 的方式修改。
开放 API 端点
[root@master ~]# kubectl proxy --accept-hosts=".*" --address=0.0.0.0
Starting to serve on [::]:8001
更新 readinessGates
[root@master ~]# curl http://localhost:8001/api/v1/namespaces/default/pods/spring-k8s/status -X PATCH -H "Content-Type: application/json-patch+json" -d '[{"op": "add", "path": "/status/conditions/-", "value": {"type": "my-condition", "status": "True", "lastProbeTime": null}}]'
查看 readinessGates
[root@master ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
spring-k8s 1/1 Running 0 5m37s 10.244.2.186 node2 <none> 1/1
[root@master ~]# kubectl get pod spring-k8s -o json | jq .status.conditions
[
{
"lastProbeTime": null,
"lastTransitionTime": null,
"status": "True",
"type": "my-condition"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-03-28T10:20:53Z",
"status": "True",
"type": "Initialized"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-03-28T10:26:22Z",
"status": "True",
"type": "Ready"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-03-28T10:20:55Z",
"status": "True",
"type": "ContainersReady"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-03-28T10:20:53Z",
"status": "True",
"type": "PodScheduled"
}
]
总结
介绍了 Pod 的 readinessGates 字段,通过条件的方式,可以自定义 Read 状态的时间。
附录
分类:
Kubernetes
【推荐】国内首个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框架的用法!