k8s pod完整生命周期
[root@master01 pod_init]# cat pod-all-life-cycles.yaml
apiVersion: v1 kind: Pod metadata: name: init-pod-1 namespace: default labels: app: ini-pod dev: pro spec: initContainers: - name: init-1 image: nginx:1.16.0 imagePullPolicy: IfNotPresent command: ["/bin/sh"] args: ["-c", "echo hello-1; sleep 3"] - name: init-2 image: nginx:1.16.0 imagePullPolicy: IfNotPresent command: ["/bin/sh"] args: ["-c", "echo hello-2; sleep 5"] containers: - name: init-pod-01 image: nginx:1.16.0 imagePullPolicy: IfNotPresent ports: - name: tcp80 containerPort: 80 - name: tcp443 containerPort: 443 lifecycle: postStart: exec: command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"] preStop: exec: command: ["/bin/sh","-c","nginx -s quit; while killall -0 nginx; do sleep 1; done"] startupProbe: httpGet: path: / port: 80 initialDelaySeconds: 5 periodSeconds: 5 successThreshold: 1 failureThreshold: 3 timeoutSeconds: 5 readinessProbe: exec: command: ["/bin/sh","-c","sleep 2"] initialDelaySeconds: 4 periodSeconds: 4 successThreshold: 1 failureThreshold: 4 timeoutSeconds: 4 livenessProbe: tcpSocket: port: 80 initialDelaySeconds: 3 periodSeconds: 3 successThreshold: 1 failureThreshold: 3 timeoutSeconds: 3
pod 基础操作
#1 # 启动pod apply yaml [root@master01 pod_init]# kubectl apply -f pod-all-life-cycles.yaml # 停止pod apply yaml [root@master01 pod_init]# kubectl delete -f pod-all-life-cycles.yaml --force --grace-period=0
# 强制删除 pod 参数 --force --grace-period=0
[root@master01 pod_init]# kubectl delete pods init-pod-1 --force --grace-period=0
# 查看pod 详细信息 [root@master01 pod_init]# kubectl describe pod init-pod-1 # 实时监控pop创建过程信息 [root@master01 pod_init]# kubectl get pod -o wide -w