Anda (mungkin) membutuhkan probe keaktifan dan kesiapan

Salah satu pertanyaan paling umum yang saya tanyakan sebagai konsultan adalah: "Apa perbedaan antara sampel liveness dan readiness ?" Pertanyaan paling umum berikutnya adalah: "Yang mana yang dibutuhkan aplikasi saya?"





Siapapun yang telah mencoba pertanyaan ini di balik Duck Duck Go tahu bahwa tidak mudah untuk menemukan jawabannya di internet. Pada artikel ini, saya harap saya dapat membantu Anda menjawab pertanyaan-pertanyaan ini sendiri. Saya akan membagikan pendapat saya tentang cara terbaik menggunakan keaktifan dan kesiapan probe dalam aplikasi yang digunakan di Red Hat OpenShift . Dan saya tidak menyarankan algoritme yang ketat, melainkan kerangka umum yang dapat Anda gunakan untuk membuat keputusan arsitektural Anda sendiri.





Untuk membuat abstraksi lebih spesifik, saya sarankan untuk melihat empat contoh penerapan umum. Untuk masing-masing, kita akan mencari tahu apakah kita perlu mengkonfigurasi probe keaktifan dan kesiapan, dan jika perlu, bagaimana caranya. Sebelum beralih ke contoh, mari kita lihat lebih dekat dua jenis sampel ini.





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

Ara.  1: Contoh implementasi server untuk melayani statika 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
      
      



Ara.  Langkah 2: Menerapkan Server Nginx untuk Melayani Statika dengan Pemeriksaan Kesiapan yang Dikonfigurasi
. 2: Nginx readiness

2: ( REST API)

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





. 3 . .





Ara.  3: Menerapkan server pekerjaan tanpa pemeriksaan kehidupan.
. 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 .





Ara.  4: Menerapkan Server Pekerjaan dengan Pemeriksaan Kehidupan
. 4: liveness

3: API

Ara.  5: Aplikasi SSR tanpa pemeriksaan apapun
. 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 .





Ara.  6. Aplikasi SSR dengan probe keaktifan dan kesiapan yang disesuaikan.
. 6. SSR liveness readiness .

4:

, . , , . .





Ara.  7: Aplikasi contoh realistis di OpenShift untuk mempelajari penggunaan probe.
. 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 .





Ara.  8: Lengkapi aplikasi sampel dengan kedua probe dikonfigurasi.
. 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