您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
21、Kubernetes - 资源清单 - 探针
发布时间:2022-12-14 22:51:34编辑:雪饮阅读()
Step1
就绪检测
首先编写就绪检测的yaml如
[root@k8s-master01 ~]# cat readinessProbe-httpget.yaml
apiVersion: v1
kind: Pod
metadata:
name : readiness-httpget-pod
namespace: default
spec:
containers:
- name: readiness-httpget-container
image: hub.atguigu.com/library/myapp:v1
imagePullPolicy: IfNotPresent
readinessProbe:
httpGet:
port: 80
path: /index1.html
initialDelaySeconds: 1
periodSeconds : 3
这里用到的镜像是我们本地harbor上次推送进去的那个镜像
可以看到我们新加的这个pod是运行了,但是未就绪
[root@k8s-master01 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
myapp-pod 1/1 Running 1 23h
readiness-httpget-pod 0/1 Running 0 89s
那么我们进入该pod的容器中编写一个符合上面就绪检测里面的path的文件,然后退出pod
[root@k8s-master01 ~]# kubectl exec readiness-httpget-pod -it -- /bin/sh
/ # echo "123" >> /usr/share/nginx/html/index1.html
/ # exit
再次查看刚才新建的pod既能运行,又能就绪了
[root@k8s-master01 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
myapp-pod 1/1 Running 1 23h
readiness-httpget-pod 1/1 Running 0 5m7s
Step2
先将目前所有的pod和我们昨天新增的两个svc清理掉,用意可能只是为了减轻负担
[root@k8s-master01 ~]# kubectl delete pod --all
pod "myapp-pod" deleted
pod "readiness-httpget-pod" deleted
[root@k8s-master01 ~]# kubectl delete svc mydb myservice
service "mydb" deleted
service "myservice" deleted
然后在建立存活检测的yaml
[root@k8s-master01 ~]# cat liveness-exec-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: liveness-exec-pod
namespace: default
spec:
containers:
- name: liveness-exec-containers
image: busybox
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","touch /tmp/live ; sleep 60; rm -rf /tmp/live; sleep 3600"]
livenessProbe:
exec:
command: ["test","-e","/tmp/live"]
initialDelaySeconds: 1
periodSeconds: 3
然后创建起来,然后本集完
[root@k8s-master01 ~]# kubectl create -f liveness-exec-pod.yaml
pod/liveness-exec-pod created
关键字词:Kubernetes,资源,清单,探针