KUBERNETESサービス健康診断機能整理

5554 ワード

原文転載先https://www.itsiv.com/2020/03/30/kubernetes%e6%9c%8d%e5%8a%a1%e5%81%a5%e5%ba%b7%e6%a3%80%e6%9f%a5%e5%8a%9f%e8%83%bd%e6%a2%b3%e7%90%86/
概要
K 8 Sサービス健康診断は、準備状態検査(readiness)と生存状態検査(liveness)の2つの次元から行われる.
                。                  ,          (  ,      )     Kubernetes   。    Kubernetes           ,                  。

名詞の解釈
readiness:    HTTP    ,          。  ReadinessProbe       , Pod      。Endpoint Controller  Service Endpoint          Pod Endpoint。

liveness:    HTTP    ,  LivenessProbe          , kubelet     ,                。         LivenessProbe  , kubelet      LivenessProbe         “Success”。

シーンの操作
readiness使用シーン:
Pod     ,                      ,         ,                 ,                 ,                ,         。            pod ,             。                      ,                   ,           pod。  ,      "     "     。

liveness使用シーン:
Liveness   Kubernetes               。    liveness     fail    kill container,      restart policy  always    pod。

  :pod    :PodSpec      restartPolicy   ,      Always、OnFailure   Never 。   
Always。

検出タイプをサポート:
Kubernetes            :

exec:          ,         0       ,      ;
tcpSocket:     IP       TCP  ,               ,      ;
httpGet:

HTTP             HTTP   ,            pod     。          [200,300)  ,     。
              4xx   5xx ,   pod    。
              4xx   5xx ,  pod        ,  Kubernetes                   HTTP      。

プローブ実行戻り結果タイプ
         ,        :
Success:Container     。
Failure:Container     。
Unknown:      ,         。

プローブ構成パラメータ
    ,              liveness   readiness       :

initialDelaySeconds:                    。
periodSeconds:       。   10 ,  1 。
timeoutSeconds:      。  1 ,  1 。
successThreshold:     ,                  。    1。   liveness     1。     1。
failureThreshold:     ,                  。    3。     1。

HTTP probe      httpGet       :
host:      ,      pod   IP。      http header     “Host”       IP。
scheme:      schema,  HTTP。
path:    HTTP server   path。
httpHeaders:       header。HTTP      header。
port:               。        1   65525   。

健康診断のベストプラクティスリスト:
アプリケーション開発者は、以下のベストプラクティスに従うことを推奨します.
1:生存と準備の結果ハンドラは互いに独立したプログラムインタフェースである必要がある:
    ,   K8s          ,    2       HTTP  “  ” “  ”     ,              。

2:「生存/準備」プローブの論理をプログラムとデカップリングしないでください.
            。  K8s                       ,                   。
    /               ,      。
   “  ”             ,        ,      200,    ,   5xx  true、false。 liveness                  ,     Kubernetes     pod。        。

3:アプリケーションの準備状況の詳細を提供するために、「準備完了」プローブのプロセッサでロジックを実装します.
     K8s  pod        HTTP  。      ,                               。          ,                    。    ,        ,                        http/https   。
  :                      HTTP  ,   “ready(  )”                         。
                          ,                       。                      。                      ,         。

小さな疑問の検証:
1:                ?
2:             ?
3:    、                ?

テスト環境の説明:
k8s   :1.6+
  :nginx

準備完了検査は5秒に1回.
        readinessProbe:
          failureThreshold: 3
          httpGet:
            httpHeaders:
            - name: Host
              value: localhost
            path: /
            port: 80
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 5

生存状態検査は9秒に1回:
        livenessProbe:
          failureThreshold: 3
          httpGet:
            httpHeaders:
            - name: Host
              value: 127.0.0.1
            path: /50x.html
            port: 80
            scheme: HTTP
          initialDelaySeconds: 60
          periodSeconds: 9
          successThreshold: 1
          timeoutSeconds: 200

サービス出力ログ
サービス出力ログは次のように表示されます.

[30/Mar/2020:12:26:16 +0000] "GET / HTTP/1.1" 200 612 "-" "kube-probe/1.16" "-"     <===    
[30/Mar/2020:12:26:21 +0000] "GET / HTTP/1.1" 200 612 "-" "kube-probe/1.16" "-"     <===    

#     5    : 2020:12:26:16s  ~  21s   5s

[30/Mar/2020:12:26:24 +0000] "GET /50x.html HTTP/1.1" 200 537 "-" "kube-probe/1.16" "-" <===    

[30/Mar/2020:12:26:26 +0000] "GET / HTTP/1.1" 200 612 "-" "kube-probe/1.16" "-"     <===    
[30/Mar/2020:12:26:31 +0000] "GET / HTTP/1.1" 200 612 "-" "kube-probe/1.16" "-"     <===    

[30/Mar/2020:12:26:33 +0000] "GET /50x.html HTTP/1.1" 200 537 "-" "kube-probe/1.16" "-" <===    

#       9    :2020:12:26:24s ~ 33s    9s!   

検証結果は次のとおりです.
1:                ?
                        。

2:             ?
                 。

3:    、                ?
           ,    。

参照ドキュメント:
https://www.itsiv.com/2020/03/30/%e5%b0%b1%e7%bb%aa%e7%8a%b6%e6%80%81%e6%a3%80%e6%9f%a5readiness%e5%92%8c%e5%ad%98%e6%b4%bb%e7%8a%b6%e6%80%81%e6%a3%80%e6%9f%a5liveness/https://www.jianshu.com/p/d87a50272310https://www.codercto.com/a/40504.htmlhttps://www.cnblogs.com/wangxu01/articles/11660599.htmlhttps://blog.csdn.net/luanpeng825485697/article/details/84900620