• k8s 存活探针(健康检查)


    重启策略 (RestartPolicy )

    Always:当容器终止退出后,总是重启容器,默认策略。
    OnFailure:当容器异常退出(退出状态码非0)时,才重启容器。
    Never:当容器终止退出,从不重启容器。
     
    probe有以下两种类型:
    livenessProbe:如果检查失败,将杀死容器,根据Pod的restartPolicy来操作。
    readinessProbe: 如果检查失败,Kubernetes会把Pod从service endpoints中剔除
     
    Probe支持以下三种检查方法:
    httpGet:发送HTTP请求,返回200-400范围状态码为成功。
    exec:执行Shell命令返回状态码是0为成功。
    tcpSocket:发起TCP Socket建立成功。
     
     

    方法一 httpGet

    nginx使用httpGet健康检查的方法
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      minReadySeconds: 1
      progressDeadlineSeconds: 60
      revisionHistoryLimit: 2
      strategy:
        type: RollingUpdate
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 1
      template:
        metadata:
          name: nginx
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.19
            ports:
            - containerPort: 80
            resources:
              requests:
                memory: "500Mi"
                cpu: "250m"
              limits: 
                memory: "500Mi" 
                cpu: "500m"
            livenessProbe:
               httpGet:
                 path: /
                 port: 80
               initialDelaySeconds: 10  #pod启动10秒执行第一次检查
               periodSeconds: 5         #第一次检查后每隔5秒检查一次
            volumeMounts:
            - name: html
              mountPath: /usr/share/nginx/html
          volumes:
          - name: html
            hostPath:
              path: /home/k8s/data/nginx
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
    spec:
      type: NodePort
      ports:
       - port: 8080
         nodePort: 30080
      selector:
        app: nginx
     

    方法二:tcpSocket

    nginx使用tcpSocket健康检查的方法
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      minReadySeconds: 1
      progressDeadlineSeconds: 60
      revisionHistoryLimit: 2
      strategy:
        type: RollingUpdate
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 1
      template:
        metadata:
          name: nginx
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.19
            ports:
            - containerPort: 80
            resources:
              requests:
                memory: "500Mi"
                cpu: "250m"
              limits: 
                memory: "500Mi" 
                cpu: "500m"
            livenessProbe:
               tcpSocket:
                 port: 80
               initialDelaySeconds: 10
               periodSeconds: 5
            volumeMounts:
            - name: html
              mountPath: /usr/share/nginx/html
          volumes:
          - name: html
            hostPath:
              path: /home/k8s/data/nginx
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
    spec:
      type: NodePort
      ports:
       - port: 8080
         nodePort: 30080
      selector:
        app: nginx
     

  • 相关阅读:
    ASP.NET MVC 几种 Filter 的执行过程源码解析
    C#中的线程二(BeginInvoke和Invoke)
    C#中的线程一(委托中的异步)
    C#比较dynamic和Dictionary性能
    C#微信公众平台开发—高级群发接口
    js 关闭浏览器
    切图神器 --- Assistor
    切图 -- cutterman
    mac上用teamviewer远程windows输入问题
    A quick introduction to HTML
  • 原文地址:https://www.cnblogs.com/xuewenlong/p/13322787.html
Copyright © 2020-2023  润新知