pod资源的健康检查-readiness探针的httpGet使用
livenessProbe:健康状态检查,周期性检查服务是否存活,检查结果失败,将重启容器
readinessProbe:可用性检查,周期性检查服务是否可用,不可用将从service的endpoints中移除
同一个容器中,可以同时使用livenessProbe,readinessProbe。
都是使用httpGet方式,livenessProbe探针检测容器监控状态,readinessProbe探针服务可以性
[root@k8s-master1 tanzhen]# cat nginx-deploy2-httpGet.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: readiness
spec:
replicas: 1
selector:
matchLabels:
app: readiness
version: v1
template:
metadata:
labels:
app: readiness
version: v1
spec:
containers:
- name: readiness
image: centos-nginx:1.23.0
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 5
periodSeconds: 10
创建deployment
[root@k8s-master1 tanzhen]# kubectl apply -f nginx-deploy2-httpGet.yaml
deployment.apps/readiness created
创建svc,
[root@k8s-master1 tanzhen]# cat svc.yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
name: readiness-svc
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: readiness
version: v1
type: NodePort
status:
loadBalancer: {}
[root@k8s-master1 tanzhen]# kubectl apply -f svc.yaml
service/readiness-svc created
describe查询svc资源,可以看到Endpoints已经加入一个pod资源,如果探针检测到服务异常,就会吧对应的pod资源从Endpoints中剔除
[root@k8s-master1 tanzhen]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 10d
my-dep NodePort 10.103.136.43 <none> 80:31644/TCP 8d
readiness-svc NodePort 10.108.113.163 <none> 80:30663/TCP 10m
[root@k8s-master1 tanzhen]#
[root@k8s-master1 tanzhen]#
[root@k8s-master1 tanzhen]# kubectl describe svc readiness-svc
Name: readiness-svc
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=readiness,version=v1
Type: NodePort
IP: 10.108.113.163
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30663/TCP
Endpoints: 10.244.2.20:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
分类:
kubernetes
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了