1 2 3 4 5 |
init readiness liveness start stop |
InInit模板
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
apiVersion: v1 kind:Pod metadata: name:myapp-shooter labels: app:myapp spec: containers: - name: myapp-container image:busybox command:['sh','-c','echo The app is running! && sleep 3600'] initContainers: - name: init-myservice image:busybox command:['sh','-c','until nslookup my service;do echo waiting for myservice;sleep2;done;'] - name: init-mydb images:busybox command:['sh','-c','until nslookup mydb;do echo waiting for mydb;sleep 2;done'] |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
kind: Service apiVersion: v1 metadata: name: myservice spec: ports: - protocol: TCP port:80 targetPort:9376 --- kind: Service apiVersion: v1 metadata: name:mydb spec: ports: - protocol: TCP port: 80 targetPort: 9377 |
检测探针 – 就绪检测
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
readinessProbe #还记得pod生命周期那张图吗 apiVersion: v1 #版本 kind: Pod #kind类型为pod metadata: #原始信息 name:readliness-httpget-pod namespace: default #命名空间 spec: #描述 containers: #容器 - name: readliness-httpget-container #容器名称 image: hub.atshooter.com/k8s/nginx:v1.0 #镜像信息 imagePullPolicy: IfNotPresent #镜像的下载策略(当前策略含义是如果有的话就不下载) readinessProbe: #就绪检测 httpGet: #检测方案 httpGet port: http #端口是http 或者 80 path: /index1.html #检测路径 initialDelaySeconds: 1 #检测延时 periodSeconds: 3 #重置时间 |
检测探针 – 存活检测
livenessProbe #还记得pod生命周期那张图吗
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
apiVersion: v1 kind: Pod metadata: name:liveness-exec-pod namespace:default spec: containers: - name: liveness-exec-container image: hub.atshooter.com/k8s/nginx:v1.0 imagePullPolicy: ifNotPresent command: ["/bin/sh","-c","touch /tmp/live ;sleep 60;rm -f /tmp/live; sleep 3600"] livenessProbe: exec: command: ["test","-e","/tmp/live"] initialDelaySeconds: 3 periodSeconds: 3 |
livenessProbe httpGet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
apiVersion: v1 kind: Pod metadata: name:liveness-httpget-pod namespace: default spec: containers: - name: liveness-exec-shooter-httpGet image: hub.atshooter.com/k8s/nginx:v1.0 imagePullPolicy: ifNotPresent ports: - name: http containerPort: 80 livenessProbe: httpGet: port:http path: /index.html initialDelaySeconds: 1 periodSeconds: 3 timeoutSeconds: 10 |
livenessProbe tcp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
apiVersion:v1 kind: Pod metadata: name: probe-tcp spec: containers: - name: nginx image: hub.atshooter.com/k8s/nginx:v1.0 livenessProbe: initialDelaySeconds: 5 timeoutSeconds: 1 tcpSocket: port: 80 periodSeconds: 3 |
启动退出动作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
apiVersion: v1 kind: Pod metadata: name: lifecycle-demo spec: containers: - name: lifecycle-demo-container-shooter image: hub.atshooter.com/k8s/nginx:v1.0 lifecycle: postStart: exec: command: ["/bin/sh","-c","echo Hello from the postStart handler > /usr/share/message"] postStop: exec: command: ["/bin/sh","-c","echo Hello from the postStop handler > /usr/share/message"] |
其他补充:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
登录容器 kubectl exec [podName] -it -- /bin/sh 关于pod列表的状态解释 kubectl get pod STATUS Pending(挂起):pod已被kubernetes 系统接受,但是有一个或者多个镜像尚未创建,等待时间包括调度Pod 的时间和通过网络 下载镜像的时间,这可能要花点时间 Running :该pod已经绑定到一个节点上,Pod中的所有容器已经被创建.至少有一个容器正在运行,或者正处于启动或者重启状态 Succeeded: Pod这种的所有容器都被成功终止,并且不会再重启 Failed: pod中的所有容器都已经终止,并且至少有一个容器是因为失败终止.也就是说,容器以非0-的状态退出或者被系统终止 Unknown:因为某些原因无法取得Pod状态,通常因为与Pod所在的主机通信失败 |
- 本文固定链接: https://www.yoyoask.com/?p=2058
- 转载请注明: shooter 于 SHOOTER 发表