第7章:Kubernetes Pod控制器应用进阶二

探测类型:
ExecAction、TCPSocketAction、HTTPGetAction

使用命令kubectl explain pods.spec.containers可以看到的三个主要类型;
(1)存活探针,容器是否存活;
livenessProbe
Periodic probe of container liveness. Container will be restarted if the
probe fails. Cannot be updated. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
(2)就绪探针,容器是否就绪;
readinessProbe
Periodic probe of container service readiness. Container will be removed
from service endpoints if the probe fails. Cannot be updated. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

注意:存活未必就绪;

三种方式:
 exec
One and only one of the following should be specified. Exec specifies the
action to take.

 httpGet
HTTPGet specifies the http request to perform.

 tcpSocket
TCPSocket specifies an action involving a TCP port. TCP hooks not yet
supported

(3)优雅启停;
lifecycle
Actions that the management system should take in response to container
lifecycle events. Cannot be updated.

postStart
PostStart is called immediately after a container is created. If the
handler fails, the container is terminated and restarted according to its
restart policy. Other management of the container blocks until the hook
completes. More info:
https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks

preStop
PreStop is called immediately before a container is terminated due to an
API request or management event such as liveness/startup probe failure,
preemption, resource contention, etc. The handler is not called if the
container crashes or exits. The reason for termination is passed to the
handler. The Pod’s termination grace period countdown begins before the
PreStop hooked is executed. Regardless of the outcome of the handler, the
container will eventually terminate within the Pod’s termination grace
period. Other management of the container blocks until the hook completes
or until the termination grace period is reached. More info:
https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks

Pod的YAML框架:
apiVersion:v1
kind:pod
metadata:
name:
namespace:
labels:
annotations:

spec:
containers:
-name:
image:
imagePullPolicy:(#Always、Never、IfNotPresent)
ports:
name:
containerPort:
lifecycle:
livenessProbe:
readinessProbe:
restartPolicy:(#Always、Never、OnFailture)
nodeName:
nodeSelector:
status:(只读)

示例:
apiVersion: v1
kind: Pod
metadata:
name: liveness-exec-pod
namespace: default
spec:
containers:

  • name: liveness-exec-container
    image: busybox:latest
    imagePullPolicy: IfNotPresent
    command: [“/bin/sh”,“-c”,“touch /tmp/healthy; sleep 30; rm -f /tmp/healthy; sleep 3600”]
    livenessProbe:
    exec:
    command: [“test”,“-e”,“/tmp/healthy”]
    initialDelaySeconds: 1
    periodSeconds: 3

apiVersion: v1
kind: Pod
metadata:
name: readiness-httpget-pod
namespace: default
spec:
containers:

  • name: readiness-httpget-container
    image: ikubernetes/myapp:v1
    imagePullPolicy: IfNotPresent
    ports:
  • name: http
    containerPort: 80
    readinessProbe:
    httpGet:
    port: http
    path: /index.html
    initialDelaySeconds: 1
    periodSeconds: 3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Davidwatt

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值