카타코더 k8s - Liveness and Readiness Healthchecks

1 개요[ | ]

카타코더 Kubernetes - Liveness and Readiness Healthchecks
카타코더 Kubernetes
# 🔗 제목
카타코더 Kubernetes/1 e
🡵 카타코더 k8s - Launch A Single Node Cluster
🡵 카타코더 k8s - Launch a multi-node cluster using Kubeadm
🡵 카타코더 k8s - Deploy Containers Using Kubectl
🡵 카타코더 k8s - Deploy Containers Using YAML
🡵 카타코더 k8s - Deploy Guestbook Web App Example
🡵 카타코더 k8s - Networking Introduction
🡵 카타코더 k8s - Create Ingress Routing
🡵 카타코더 k8s - Liveness and Readiness Healthchecks
🡵 카타코더 k8s - Getting Started With CRI-O and Kubeadm
🡵 카타코더 k8s - Running Stateful Services on Kubernetes

2 Launch Cluster[ | ]

master:~$ cat deploy.yaml
kind: List
apiVersion: v1
items:
- kind: ReplicationController
  apiVersion: v1
  metadata:
    name: frontend
    labels:
      name: frontend
  spec:
    replicas: 1
    selector:
      name: frontend
    template:
      metadata:
        labels:
          name: frontend
      spec:
        containers:
        - name: frontend
          image: katacoda/docker-http-server:health
          readinessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 1
            timeoutSeconds: 1
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 1
            timeoutSeconds: 1
- kind: ReplicationController
  apiVersion: v1
  metadata:
    name: bad-frontend
    labels:
      name: bad-frontend
  spec:
    replicas: 1
    selector:
      name: bad-frontend
    template:
      metadata:
        labels:
          name: bad-frontend
      spec:
        containers:
        - name: bad-frontend
          image: katacoda/docker-http-server:unhealthy
          readinessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 1
            timeoutSeconds: 1
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 1
            timeoutSeconds: 1
- kind: Service
  apiVersion: v1
  metadata:
    labels:
      app: frontend
      kubernetes.io/cluster-service: "true"
    name: frontend
  spec:
    type: NodePort
    ports:
    - port: 80
      nodePort: 30080
    selector:
      app: frontend
master:~$ kubectl apply -f deploy.yaml
replicationcontroller/frontend created
replicationcontroller/bad-frontend created
service/frontend created

3 Readiness Probe[ | ]

master:~$ cat deploy.yaml | grep livenessProbe: -A5
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 1
            timeoutSeconds: 1
--
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 1
            timeoutSeconds: 1
master:~$ kubectl get pods --selector="name=bad-frontend"
NAME                 READY     STATUS    RESTARTS   AGE
bad-frontend-kjfq4   0/1       Running   2          1m
master:~$ kubectl describe pod $pod
Name:               bad-frontend-kjfq4
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               master/172.17.0.42
Start Time:         Sat, 23 Mar 2019 17:32:40 +0000
Labels:             name=bad-frontend
Annotations:        <none>
Status:             Running
IP:                 10.32.0.4
Controlled By:      ReplicationController/bad-frontend
Containers:
  bad-frontend:
    Container ID:   docker://4435dbab9e93a077a0bb7a765100521ea1c0d242d281d53c021d62ffa973cf6b
    Image:          katacoda/docker-http-server:unhealthy
    Image ID:       docker-pullable://katacoda/docker-http-server@sha256:bea95c69c299c690103c39ebb3159c39c5061fee1dad13aa1b0625e0c6b52f22
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Sat, 23 Mar 2019 17:33:43 +0000
    Last State:     Terminated
      Reason:       Error
      Exit Code:    2
      Started:      Sat, 23 Mar 2019 17:33:13 +0000
      Finished:     Sat, 23 Mar 2019 17:33:42 +0000
    Ready:          False
    Restart Count:  2
    Liveness:       http-get http://:80/ delay=1s timeout=1s period=10s#success=1 #failure=3
    Readiness:      http-get http://:80/ delay=1s timeout=1s period=10s#success=1 #failure=3
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-pf6lw (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-pf6lw:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-pf6lw
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  1m                 default-scheduler  Successfully assigned default/bad-frontend-kjfq4 to master
  Normal   Pulling    1m                 kubelet, master    pulling image "katacoda/docker-http-server:unhealthy"
  Normal   Pulled     1m                 kubelet, master    Successfully pulled image "katacoda/docker-http-server:unhealthy"
  Warning  Unhealthy  28s (x6 over 1m)   kubelet, master    Liveness probe failed: HTTP probe failed with statuscode: 500
  Normal   Killing    28s (x2 over 58s)  kubelet, master    Killing container with id docker://bad-frontend:Container failed liveness probe.. Container will be killed and recreated.
  Normal   Pulled     28s (x2 over 57s)  kubelet, master    Container image "katacoda/docker-http-server:unhealthy" already present on machine
  Normal   Created    27s (x3 over 1m)   kubelet, master    Created container
  Normal   Started    27s (x3 over 1m)   kubelet, master    Started container
  Warning  Unhealthy  20s (x7 over 1m)   kubelet, master    Readiness probe failed: HTTP probe failed with statuscode: 500
master:~$ kubectl get pods --selector="name=frontend"
NAME             READY     STATUS    RESTARTS   AGE
frontend-vdfjg   1/1       Running   0          2m

4 Liveness Probe[ | ]

aster $ kubectl get pods --selector="name=frontend"
NAME             READY     STATUS    RESTARTS   AGE
frontend-vdfjg   1/1       Running   0          2m
master:~$ pod=$(kubectl get pods --selector="name=frontend" --output=jsonpath={.items..metadata.name})
master:~$ kubectl exec $pod -- /usr/bin/curl -s localhost/unhealthy
master:~$
master:~$ kubectl get pods --selector="name=frontend"
NAME             READY     STATUS    RESTARTS   AGE
frontend-vdfjg   1/1       Running   0          2m
master:~$ kubectl get pods --selector="name=frontend"
NAME             READY     STATUS    RESTARTS   AGE
frontend-vdfjg   0/1       Running   0          3m
master:~$ kubectl get pods --selector="name=frontend"
NAME             READY     STATUS    RESTARTS   AGE
frontend-vdfjg   1/1       Running   1          3m
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}