您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
23、Kubernetes - 资源清单 - start、stop、相位
发布时间:2022-12-16 21:28:04编辑:雪饮阅读()
首先创建一个包含启动与停止的监听的脚本的yaml模板
[root@k8s-master01 ~]# cat lifecycle-demo.yaml
apiVersion: v1
kind: Pod
metadata:
name: lifecycle-demo
spec:
containers:
- name: lifecycle-demo-container
image: hub.atguigu.com/library/myapp:v1
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
preStop:
exec:
command: ["/bin/sh", "-c", "echo Hello from the poststop handler > /usr/share/message2"]
然后创建
[root@k8s-master01 ~]# kubectl create -f lifecycle-demo.yaml
pod/lifecycle-demo created
当pod运行了之后
[root@k8s-master01 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
lifecycle-demo 1/1 Running 0 8s
liveness-httpget-pod 0/1 Running 2 22h
可以看到启动的脚本确实执行了
[root@k8s-master01 ~]# kubectl exec lifecycle-demo -it -- /bin/sh
/ # cat /usr/share/message
Hello from the postStart handler
/ #
当然退出就进不来了,所以就不演示了哈
关键字词:Kubernetes,资源,清单,start,stop,相位