Pod-hook:
postStart:1.$ $ vim preStart-hook.yaml---apiVersion: v1kind: Podmetadata: name: hook-demo1 labels: app: hookspec: containers: - name: hook-demo1 image: nginx ports: - name: webport containerPort: 80 lifecycle: postStart: exec: command: ["/bin/sh", "-c", "echo Hello from the postStart Hander > /usr/share/message"] $ kubectl exec hook-demo1 -i -t /bin/bash preStop:2.强制删除$ kubectl delete pod hook-demo1 --force --grace-period=0$ vim preStop-hook.yaml---apiVersion: v1kind: Podmetadata: name: hook-demo2 labels: app: hookspec: containers: - name: hook-demo2 image: nginx ports: - name: webport containerPort: 80 volumeMounts: - name: message mountPath: /usr/share lifecycle: preStop: exec: command: ["/bin/sh", "-c", "echo Hello from the postStop Hander > /usr/share/message"] volumes: - name: message hostPath: path: /tmp普通的pod是不能被调度到master节点上面来的存活探针:liveness probe$ vim liveness-exec.yaml---apiVersion: v1kind: Podemetadata: name: liveness-exec labels: app: livenessspec: containers: - name: liveness images: busybox args: - /bin/sh - -c - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600 livenessProbe: exec: command: - cat - /tmp/healthy initialDelaySeconds: 5 periodSeconds: 5 初始化容器-initcontainer$ vim initpod1.yaml---apiVersion: v1kind: Podmetadata: name: init-pod labels: app: initspec: initContainers: - name: init-myservice image: busybox command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; done;'] - name: image: busybox command: ['sh', '-c', 'until nslookup mydb; do echo waiting for mydb; sleep 2; done;'] containers: - name: main-container image: busybox command: ['sh', '-c', 'echo The app is running! && sleep 3600']