あなたは(おそらく)活気と準備の調査が必要です

私がコンサルタントとして尋ねられる最も一般的な質問の1つは、「活気準備のサンプルの違いは何ですか?」です。次の最も一般的な質問は、「アプリケーションに必要なものはどれですか?」です。





Duck Duck Goの背後でこの質問を試したことがある人なら誰でも、インターネットでその答えを見つけるのは簡単ではないことを知っています。この記事では、これらの質問に自分で答えるのに役立つことを願っています。Red HatOpenShiftにデプロイされたアプリケーションでプローブの活性と準備をどのように使用するのが最善かについての私の意見を共有しますそして、私は厳密なアルゴリズムを提案しているのではなく、独自のアーキテクチャ上の決定を行うために使用できる一般的なフレームワークを提案しています。





抽象化をより具体的にするために、4つの一般的なアプリケーション例を検討することをお勧めします。それぞれについて、活性と準備のプローブを構成する必要があるかどうか、および必要に応じてその方法を確認します。例に移る前に、これら2つの異なるタイプのサンプルを詳しく見てみましょう。





: Kubernetes “startup” probe, OpenShift 4.5 clusters. startup probe, liveness readiness probes. startup probes.





Liveness readiness probes

Liveness () readiness () , OpenShift. , .





liveness , OpenShift’, . readiness , OpenShift’ , . , .





liveness , readiness , OpenShift , , , . , . ( - -, , , legacy-.)





. , , OpenShift.





liveness ?

Liveness OpenShift’, ( ), ( ). , OpenShift , . , OpenShift .





liveness ( ) . “” “” : “ ?”.





liveness ?

liveness , OpenShift PID 1. PID 1 , . , PID 1





PID 1 liveness , OpenShift ( ), . - . PID 1 , , , OpenShift .





, PID 1, , , liveness . init , tini dumb-init, , . , liveness , , .





readiness ?

OpenShift readiness ( ) , . , , ( ), , readiness . OpenShift , . OpenShift , , ( ) 502 , “connection refused”.





liveness , readiness ( ) . : “ ?”.





readiness ?

readiness , OpenShift , PID 1 . .





(, 502 OpenShift) , . readiness , . , , . , , , .





readiness . OpenShift' , .





, , .





: - , . - : OpenShift . liveness readiness OpenShift Container-as-a-Service, .





1: (Nginx)

イチジク。 1:Nginxスタティックを提供するためのサーバー実装の例
. 1: Nginx

, 1 - , Nginx, . , : , 200 HTTP .





liveness ?

, , . , , liveness . Nginx , (, , SELinux Nginx, ).





readiness ?

Nginx readiness . , readiness , . Nginx , , , , best practice.





readiness

, , Deployment



. , . , template.





apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: application-nginx
  name: application-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: application-nginx
  template:
    metadata:
      labels:
        app: application-nginx
    spec:
      #  Will appear below as it changes
      
      



:





    spec:
      containers:
      - image: quay.io/<username>/nginx:latest
        name: application-nginx
        imagePullPolicy: Always
        ports:
        - containerPort: 8443
          protocol: TCP
        readinessProbe:
          httpGet:
            scheme: HTTPS
            path: /index.html
            port: 8443
          initialDelaySeconds: 10
          periodSeconds: 5
      
      



イチジク。 ステップ2:構成済みの準備チェックを使用して統計を提供するためのNginxサーバーを実装する
. 2: Nginx readiness

2: ( REST API)

HTTP -, “”. “” readiness , . , liveness . , , , . , , liveness . 





. 3 . .





イチジク。 3:活性チェックなしでジョブサーバーを実装します。
. 3: liveness .

, liveness , .





liveness ? 

, . , , - . , PID 1.





PID 1, , . liveness OpenShift PID 1 . .





, . , deadlock, , , .





deadlock, /tmp/jobs.update



. shell ( exec liveness ) , , . liveness /usr/bin/my-application-jobs --alive



.





liveness ( , YAML- Deployment’a



, ):





    spec:
      containers:
      - image: quay.io/<username>/my-application-jobs:latest
        name: my-application-jobs
        imagePullPolicy: Always
        livenessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - "/usr/bin/my-application-jobs --alive"
          initialDelaySeconds: 10
          periodSeconds: 5
      
      



readiness ?

readiness . , readiness OpenShift , . , . readiness . . 4 liveness .





イチジク。 4:活性チェックを使用したジョブサーバーの実装
. 4: liveness

3: API

イチジク。 5:チェックなしのSSRアプリケーション
. 5: SSR -

SSR: HTML- , . Spring Boot, PHP, Ruby on Rails, Django, Node.js, .





liveness ?

, liveness , , . , liveness , , .





liveness exec, shell, , - . . , PID , , :





        livenessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - "[ -f /run/my-application-web.pid ] && ps -A | grep my-application-web"
          initialDelaySeconds: 10
          periodSeconds: 5
      
      



readiness ?

readiness . readiness OpenShift , , . , , , , , , .





, OpenShift , . readiness , , OpenShift, :





        readinessProbe:
          httpGet:
            scheme: HTTPS
            path: /healthz
            port: 8443
          initialDelaySeconds: 10
          periodSeconds: 5
      
      



, YAML :





apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: backend-service
  name: backend-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: backend-service
  template:
    metadata:
      labels:
        app: backend-service
    spec:
      containers:
      - image: quay.io/<username>/backend-service:latest
        name: backend-service
        imagePullPolicy: Always
        ports:
        - containerPort: 8443
          protocol: TCP
        readinessProbe:
          httpGet:
            scheme: HTTPS
            path: /healthz
            port: 8443
          initialDelaySeconds: 10
          periodSeconds: 5
      
      



6 SSR liveness readiness .





イチジク。 6.カスタマイズされた活性および準備プローブを備えたSSRアプリケーション。
. 6. SSR liveness readiness .

4:

, . , , . .





イチジク。 7:プローブの使用法を学習するためのOpenShiftのリアルなサンプルアプリケーション。
. 7: OpenShift .

, :





  • : REST API . , , , REST API.





  • Nginx: : (, JavaScript CSS). TLS- (Transport Layer Security) , URL. .





  • : , . , . , , .





:





  • : . - , .





  • . « - » (FIFO) . , .





:





  • Nginx TLS- . , HTTP. . volume space. , .





  • . , . , .





, . HTTP 8080 HTTPS 8443 readiness . liveness , , . , Kubelet', «»:





# Pod One - Application Server and Nginx
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: my-application-web
  name: my-application-web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-application-web
  template:
    metadata:
      labels:
        app: my-application-web
    spec:
      containers:
      - image: quay.io/<username>/my-application-nginx:latest
        name: my-application-nginx
        imagePullPolicy: Always
        ports:
        - containerPort: 8443
          protocol: TCP
        livenessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - "[ -f /run/nginx.pid ] && ps -A | grep nginx"
          initialDelaySeconds: 10
          periodSeconds: 5
        readinessProbe:
          httpGet:
            scheme: HTTPS
            path: /index.html
            port: 8443
          initialDelaySeconds: 10
          periodSeconds: 5
      - image: quay.io/<username>/my-application-app-server:latest
        name: my-application-app-server
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
          protocol: TCP
        livenessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - "/usr/bin/my-application-web --alive"
          initialDelaySeconds: 10
          periodSeconds: 5
        readinessProbe:
          httpGet:
            scheme: HTTP
            path: /healthz
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 5

# Pod Two - Jobs Server
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: my-application-jobs
  name: my-application-jobs
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-application-jobs
  template:
    metadata:
      labels:
        app: my-application-jobs
    spec:
      containers:
      - image: quay.io/<username>/my-application-jobs:latest
        name: my-application-jobs
        imagePullPolicy: Always
        livenessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - "/usr/bin/my-application-jobs --alive"
          initialDelaySeconds: 10
          periodSeconds: 5
      
      



8 .





イチジク。 8:両方のプローブを構成した完全なサンプルアプリケーション。
. 8: .

liveness readiness ?

, , . HTTP- , , , , , , OpenShift . , , .





HTTP endpoint, , liveness readiness endpoint. endpoint , , endpoint .





Liveness readiness OpenShift.  . liveness OpenShift, . readiness OpenShift .





, “” , . , , .





. , liveness , readiness . , .





, . - (SOA), . , readiness ? . / , , .





, . - ! . .








All Articles