kubernetes探针配置

1.LivenessProbe(存活检查)

    LivenessProbe:表示container是否处于live状态。如果 LivenessProbe失败,LivenessProbe将会通知kubelet对应的container不健康了。随后kubelet将kill掉 container,并根据
RestarPolicy进行进一步的操作。默认情况下LivenessProbe在第一次检测之前初始化值为 Success,如果container没有提供LivenessProbe,则也认为是Success;

2.ReadinessProbe(就绪检查)

    ReadinessProbe:表示container是否以及处于可接受service请求的状态了。如 果ReadinessProbe失败,endpoints controller将会从service所匹配到的endpoint列表中移除关于这个
container的IP地址。因此对于Service匹配到的 endpoint的维护其核心是ReadinessProbe。默认Readiness的初始值是Failure,如果一个container没有提供 Readiness则被认为是Success

3.参数详解 

对于LivenessProbe和ReadinessProbe用法都一样,拥有相同的参数和相同的监测方式。【检查流程如下】

1)HTTP探针在httpGet上的配置项:
#host:主机名,默认为pod的IP。
#httpHeaders【HTTP头】:在HTTP请求中设置的自定义标头。 HTTP允许重复的请求头。
path【路径】:探针的路径。
port【端口】:端口的名称或编号。数字必须在1到65535的范围内。
scheme【协议】:用于连接主机的方案(HTTP或HTTPS)。默认为HTTP。

2)initialDelaySeconds【延迟探测时间(秒)】:用来表示初始化延迟的时间,也就是告诉监测从多久之后开始运行,单位是秒 

3)periodSeconds【执行探测频率(秒)】:监测开始后,每隔10秒执行一次 路径(健康检测页面) 监测。 

4)timeoutSeconds【超时时间(秒)】: 用来表示监测的超时时间,如果超过这个时长后,则认为监测失败(若监测路径1秒后没有返回,则认为超时) 

5)failureThreshold【不健康伐值】:当Pod成功启动且检查失败且连续达到设定次数时,放弃生存检查意味着重新启动Pod。(放弃就绪检查,Pod将被标记为未就绪。 
默认为3.最小值为1)
6)successThreshold【健康伐值】:失败后检查成功的最小连续成功次数。默认为1.活跃度必须为1。最小值为1。即监测路径健康后完成本次检查。

4.阿里云web端设置

存活检查

 就绪检查

5.yaml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: beta-es-provider-course
    appname: dev-es-provider-course
    env: beta
  name: beta-es-provider-course
  namespace: beta-es
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: beta-es-provider-course
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: beta-es-provider-course
        appname: beta-es-provider-course
        env: beta
    spec:
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - preference:
                matchExpressions:
                  - key: env-beta
                    operator: In
                    values:
                      - beta
              weight: 80
            - preference:
                matchExpressions:
                  - key: env-alpha
                    operator: In
                    values:
                      - alpha
              weight: 20
      containers:
        - image: >-
            registry.aliyuncs.com/wx-k8s/es-provider-course:beta-es-provider-course-latest
          imagePullPolicy: Always
          lifecycle:
            postStart:
              exec:
                command:
                  - /bin/sh
                  - '-c'
                  - >-
                    mkdir -p /home/mount/${HOSTNAME} && ln -s 
                    /home/mount/${HOSTNAME} 
                    /home/wx/services/es-provider-course/logs
          livenessProbe:
            failureThreshold: 5
            httpGet:
              path: /actuator/health
              port: 7005
              scheme: HTTP
            initialDelaySeconds: 300
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          name: beta-es-provider-course
          ports:
            - containerPort: 7005
              name: http
              protocol: TCP
          readinessProbe:
            failureThreshold: 5
            httpGet:
              path: /actuator/health
              port: 7005
              scheme: HTTP
            initialDelaySeconds: 300
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          resources:
            limits:
              cpu: '1'
              memory: 600Mi
            requests:
              cpu: 10m
              memory: 600Mi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /home/mount
              name: volume-service-dir
            - mountPath: /etc/localtime
              name: volume-localtime
      dnsPolicy: ClusterFirst
      imagePullSecrets:
        - name: pull-image
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
        - hostPath:
            path: /home/wx/services/beta/es-provider-course
            type: ''
          name: volume-service-dir
        - hostPath:
            path: /etc/localtime
            type: ''
          name: volume-localtime
原文地址:https://www.cnblogs.com/faithH/p/13589636.html