Verificación de estado de la configuración de K8S

Documento oficial: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/

Uno, estrategia de reinicio

Always:  当容器终止后,总是重启,默认策略
OnFailure: 当容器异常退出(退出状态码非0)时,才重启容器
Never: 当容器终止退出,从不重启容器

2. Hay dos tipos de controles de salud

2.1.livenessProbe(存活检查)

Si la verificación falla, el contenedor será eliminado y operado de acuerdo con la estrategia de reinicio del Pod.

2.2.readinessProbe(就绪检查)

Si la verificación falla, los K8 eliminarán el Pod de los puntos finales del servicio

Tres, tres métodos de inspección

httpGet: 发送HTTP请求,返回200-400范围状态码表示成功
exec: 执行Shell命令返回状态码为0表示成功
tcpSocket: 发起TCP Socket建立成功

Cuatro, ejemplo

Inserte la descripción de la imagen aquí

initialDelaySeconds: 第一次启动Pod后等待多久时间开始健康检查
periodSeconds: 健康检查的周期

Cinco, archivo yaml completo

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: web
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      restartPolicy: Always
      containers:
      - image: nginx
        imagePullPolicy: IfNotPresent
        name: web
        ports:
        - containerPort: 80
        livenessProbe:
          tcpSocket:
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5
        readinessProbe:
          httpGet:
            path: /index.html
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: web
  name: web
spec:
  ports:
  - port: 80
    protocol: TCP
  selector:
    app: web
  type: NodePort

Supongo que te gusta

Origin blog.csdn.net/anqixiang/article/details/108653828
Recomendado
Clasificación