Sie benötigen (wahrscheinlich) Lebendigkeits- und Bereitschaftssonden

Eine der häufigsten Fragen, die mir als Berater gestellt werden, lautet: "Was ist der Unterschied zwischen Lebendigkeits- und Bereitschaftsproben ?" Die nächsthäufigste Frage lautet: "Welche benötigt meine Bewerbung?"





Jeder, der diese Frage hinter Duck Duck Go ausprobiert hat, weiß, dass es nicht einfach ist, im Internet eine Antwort darauf zu finden. In diesem Artikel hoffe ich, dass ich Ihnen helfen kann, diese Fragen selbst zu beantworten. Ich werde meine Meinung darüber teilen, wie die Lebendigkeit und Bereitschaft von Sonden in Anwendungen, die in Red Hat OpenShift bereitgestellt werden, am besten genutzt werden kann . Und ich schlage keinen strengen Algorithmus vor, sondern einen allgemeinen Rahmen, mit dem Sie Ihre eigenen Architekturentscheidungen treffen können.





Um die Abstraktionen genauer zu gestalten, schlage ich vor, vier allgemeine Anwendungsbeispiele zu betrachten. Für jeden von ihnen werden wir herausfinden, ob und wie wir die Lebendigkeits- und Bereitschaftssonden konfigurieren müssen. Bevor wir zu den Beispielen übergehen, schauen wir uns diese beiden verschiedenen Arten von Beispielen genauer an.





: 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)

Feige.  1: Ein Beispiel für die Serverimplementierung zur Bereitstellung der Nginx-Statik
. 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
      
      



Feige.  Schritt 2: Implementieren eines Nginx-Servers zum Bereitstellen von Statik mit konfigurierten Bereitschaftsprüfungen
. 2: Nginx readiness

2: ( REST API)

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





. 3 . .





Feige.  3: Implementieren eines Jobservers ohne Überprüfung der Lebendigkeit.
. 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 .





Feige.  4: Implementieren eines Jobservers mit Liveness Checks
. 4: liveness

3: API

Feige.  5: SSR-Anwendung ohne Prüfung
. 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 .





Feige.  6. SSR-Anwendung mit kundenspezifischen Lebendigkeits- und Bereitschaftssonden.
. 6. SSR liveness readiness .

4:

, . , , . .





Feige.  7: Realistische Beispielanwendung in OpenShift zum Erlernen der Verwendung von Sonden.
. 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 .





Feige.  8: Schließen Sie Beispielanwendungen mit beiden konfigurierten Sonden ab.
. 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