• K8S哲学 - probe 探针


    探针分类:

    liveness probe

    readiness probe

    startup probe

    1. Liveness Probe:用于检查容器是否还在运行。如果 Liveness Probe 失败,Kubernetes 会杀死容器,然后根据你的重启策略来决定是否重新启动容器。常见的做法是使用与 Readiness Probe 相同的低成本 HTTP 端点,但是设置更高的 failureThreshold,这样可以确保在 Pod 被强制杀死之前,它会被观察到为 not-ready 一段时间。

    2. Readiness Probe:用于检查容器是否准备好接受流量。一个 Pod 被认为是 ready 的,当且仅当它的所有容器都是 ready 的。这个信号的一个用途是控制哪些 Pod 被用作 Service 的后端。当一个 Pod 不是 ready 的,它会从 Service 的负载均衡器中移除。

    3. Startup Probe:用于检查容器应用程序是否已经启动。如果配置了这样的探针,那么在它成功之前,Liveness Probe 和 Readiness Probe 不会开始,确保这些探针不会干扰应用程序的启动。这可以用于对慢启动的容器进行 Liveness 检查,避免它们在启动并运行之前被 kubelet 杀死。

    探测方式

    HTTPGetAction

    TCPSocketAction

    ExecAction

    每种探针都可以使用以下三种方式之一进行检查:

    • HTTP GET:对容器的一个 HTTP 服务器发起一个 GET 请求。如果服务器返回的状态码在 200 到 399 之间,那么探针就是成功的。

    • TCP Socket:尝试打开容器的一个 TCP 端口。如果端口已经打开,那么探针就是成功的。

    • Exec:在容器中执行一个命令。如果命令返回 0,那么探针就是成功的。

     

    ERROR: The Pod "app" is invalid: spec.containers[0].livenessProbe.successThreshold: Invalid value: 3: must be 1

    对于 Liveness 探针,successThreshold 的值必须为 1。这是因为 Liveness 探针只需要一次成功的探测就能确定容器是存活的。所以,你需要将 successThreshold 的值改为 1。

    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. name: 'app'
    5. labels:
    6. name: 'zs'
    7. age: '18'
    8. spec:
    9. containers:
    10. - name: 'probe-po'
    11. image: nginx:1.14.2
    12. livenessProbe:
    13. httpGet:
    14. path: /index.html
    15. port: 80
    16. initialDelaySeconds: 5
    17. periodSeconds: 5
    18. timeoutSeconds: 5
    19. failureThreshold: 3
    20. successThreshold: 1

    这时 如果将 index.html 改成 index1.html 

     livenessProbe 采用 tcpSocket

    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. name: 'app'
    5. labels:
    6. name: 'zs'
    7. age: '18'
    8. spec:
    9. containers:
    10. - name: 'probe-po'
    11. image: nginx:1.14.2
    12. livenessProbe:
    13. # httpGet:
    14. # path: /index1.html
    15. # port: 80
    16. # initialDelaySeconds: 5
    17. # periodSeconds: 5
    18. # timeoutSeconds: 5
    19. # failureThreshold: 3
    20. # successThreshold: 1
    21. tcpSocket:
    22. port: 80
    23. periodSeconds: 5
    24. successThreshold: 1
    25. failureThreshold: 3

    livenessProbe 采用 exec

    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. name: 'app'
    5. labels:
    6. name: 'zs'
    7. age: '18'
    8. spec:
    9. containers:
    10. - name: 'probe-po'
    11. image: nginx:1.14.2
    12. livenessProbe:
    13. # httpGet:
    14. # path: /index1.html
    15. # port: 80
    16. # initialDelaySeconds: 5
    17. # periodSeconds: 5
    18. # timeoutSeconds: 5
    19. # failureThreshold: 3
    20. # successThreshold: 1
    21. # tcpSocket:
    22. # port: 89
    23. # periodSeconds: 5
    24. # successThreshold: 1
    25. # failureThreshold: 3
    26. exec:
    27. command: ['cat', '/usr/share/nginx/html/index.html']
    28. # - cat
    29. # - /usr/share/nginx/html/index.html
    30. successThreshold: 1
    31. failureThreshold: 3
    32. timeoutSeconds: 3
    33. periodSeconds: 3

    改成 index1.html

    配置 livenessProbe readinessProbe startupProbe

    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. name: 'app'
    5. labels:
    6. name: 'zs'
    7. age: '18'
    8. spec:
    9. containers:
    10. - name: 'probe-po'
    11. image: nginx:1.14.2
    12. livenessProbe:
    13. # httpGet:
    14. # path: /index1.html
    15. # port: 80
    16. # initialDelaySeconds: 5
    17. # periodSeconds: 5
    18. # timeoutSeconds: 5
    19. # failureThreshold: 3
    20. # successThreshold: 1
    21. # tcpSocket:
    22. # port: 89
    23. # periodSeconds: 5
    24. # successThreshold: 1
    25. # failureThreshold: 3
    26. exec:
    27. command: ['cat', '/usr/share/nginx/html/index1.html']
    28. # - cat
    29. # - /usr/share/nginx/html/index.html
    30. successThreshold: 1
    31. failureThreshold: 3
    32. timeoutSeconds: 3
    33. periodSeconds: 3
    34. readinessProbe:
    35. httpGet:
    36. path: /index.html
    37. port: 80
    38. failureThreshold: 3
    39. successThreshold: 1
    40. timeoutSeconds: 3
    41. periodSeconds: 3
    42. startupProbe:
    43. httpGet:
    44. path: /index.html
    45. port: 80
    46. failureThreshold: 3
    47. successThreshold: 1
    48. timeoutSeconds: 3
    49. periodSeconds: 3

  • 相关阅读:
    #define 宏定义看这一篇文章就够了
    德博能源、西门子能源、霍尼韦尔等出席2023中国可持续生物燃料峰会
    SQL教程之作为 SQL 数据分析师给初学者的5个技巧提升
    接口自动化框架脚手架-参数化工具的实现
    无人机的发展
    【多目标进化优化】多目标进化算法的收敛性
    C++奇迹之旅:深入思考拷贝构造函数
    Pandas数据结构
    Oxygen Publishing Engine V26.0
    计算机操作系统 第五章 虚拟存储器(1)
  • 原文地址:https://blog.csdn.net/gu2022_3_5_21_23/article/details/137956696