pod资源的健康检查-readiness探针的httpGet使用

2022-10-15,,,,

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>

pod资源的健康检查-readiness探针的httpGet使用的相关教程结束。

《pod资源的健康检查-readiness探针的httpGet使用.doc》

下载本文的Word格式文档,以方便收藏与打印。