健康检查

Kubernetes自带的探针分为两种

存活探针 和 就绪探针

存活探针通过以下3种方式检查容器是否健康

  1. 通过 HTTP GET 请求,期望返回的response code 200-399
  2. TCP 套接字连接成功
  3. Exec 调用命令,退出代码 为 0
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 30

未通过 存活探针 检查的容器,会被重启,也只会被重启

就绪探针的检查方式相同 HTTP、命令、TCP , 但是就绪探针不会重启容器,而是避免这个容器接收请求

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 30
        readinessProbe:
          httpGet:
            path: /
            port: 801
            scheme: HTTP
          initialDelaySeconds: 30

Send a Message