L'une des questions les plus fréquemment posées en tant que consultant est: "Quelle est la différence entre les échantillons de vivacité et de préparation ?" La question suivante la plus courante est: "De quels éléments mon application a-t-elle besoin?"
Quiconque a essayé cette question derrière Duck Duck Go sait qu'il n'est pas facile de trouver une réponse sur Internet. Dans cet article, j'espère pouvoir vous aider à répondre vous-même à ces questions. Je partagerai mon opinion sur la meilleure façon d'utiliser la vivacité et la disponibilité des sondes dans les applications déployées dans Red Hat OpenShift . Et je ne suggère pas un algorithme rigoureux, mais plutôt un cadre général que vous pouvez utiliser pour prendre vos propres décisions architecturales.
Pour rendre les abstractions plus spécifiques, je suggère d'examiner quatre exemples d'application généraux. Pour chacun d'eux, nous découvrirons si nous devons configurer les sondes de vivacité et de préparation, et si nécessaire, comment. Avant de passer aux exemples, examinons de plus près ces deux types d'échantillons différents.
: 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, . , : , 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: ( REST API)
HTTP -, “”. “” readiness , . , liveness . , , , . , , 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 .
3: API
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 .
4:
, . , , . .
, :
: 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 .
liveness readiness ?
, , . HTTP- , , , , , , OpenShift . , , .
HTTP endpoint, , liveness readiness endpoint. endpoint , , endpoint .
Liveness readiness OpenShift. . liveness OpenShift, . readiness OpenShift .
, “” , . , , .
. , liveness , readiness . , .
, . - (SOA), . , readiness ? . / , , .
, . - ! . .