4.1 Keeping pods healthy (livenessProbe)

컨테이너가 정상적으로 동작하는지 체크하고 정상적으로 동작하지 않는다면 컨테이너를 재시작하여 문제를 해결한다.

아래의 세가지 방식으로 컨테이너에 프로브를 실행한다.

mzc01-jeongsh  ~/Desktop/kube_example
 cat kubia-liveness-probe.yaml
apiVersion: v1
kind: Pod
metadata:
  name: kubia-liveness
spec:
  containers:
  - image: luksa/kubia-unhealthy
    name: kubia
    livenessProbe:
      httpGet:
        path: /
        port: 8080
 mzc01-jeongsh  ~/Desktop/kube_example
 k get po kubia-liveness
NAME             READY   STATUS    RESTARTS   AGE
kubia-liveness   1/1     Running   0          70s

이후 상태를 확인해보면 livenessProbe에 의해서 pod가 restart함을 알 수 있다.

mzc01-jeongsh  ~/Desktop/kube_example
 k describe po kubia-liveness
Name:         kubia-liveness
Namespace:    default
Priority:     0
Node:         minikube/192.168.64.3
Start Time:   Wed, 16 Jun 2021 00:37:30 +0900
Labels:       <none>
Annotations:  <none>
Status:       Running
IP:           172.17.0.23
IPs:
  IP:  172.17.0.23
Containers:
  kubia:
    Container ID:   docker://a5ae26eee2e00065cbe625480fe7bf4ee41ed8c1d2f2d95771d5ef12f7731331
    Image:          luksa/kubia-unhealthy
    Image ID:       docker-pullable://luksa/kubia-unhealthy@sha256:5c746a42612be61209417d913030d97555cff0b8225092908c57634ad7c235f7
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Wed, 16 Jun 2021 00:42:07 +0900
    Last State:     Terminated
      Reason:       Error
      Exit Code:    137
      Started:      Wed, 16 Jun 2021 00:40:16 +0900
      Finished:     Wed, 16 Jun 2021 00:42:04 +0900
    Ready:          True
    Restart Count:  2
    Liveness:       http-get http://:8080/ delay=0s timeout=1s period=10s #success=1 #failure=3
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-bdsql (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-bdsql:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-bdsql
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                  From               Message
  ----     ------     ----                 ----               -------
  Normal   Scheduled  5m28s                default-scheduler  Successfully assigned default/kubia-liveness to minikube
  Normal   Pulled     4m33s                kubelet            Successfully pulled image "luksa/kubia-unhealthy" in 53.666170217s
  Normal   Pulled     2m42s                kubelet            Successfully pulled image "luksa/kubia-unhealthy" in 2.505317303s
  Warning  Unhealthy  84s (x6 over 3m34s)  kubelet            Liveness probe failed: HTTP probe failed with statuscode: 500
  Normal   Killing    84s (x2 over 3m14s)  kubelet            Container kubia failed liveness probe, will be restarted
  Normal   Pulling    54s (x3 over 5m27s)  kubelet            Pulling image "luksa/kubia-unhealthy"
  Normal   Created    52s (x3 over 4m33s)  kubelet            Created container kubia
  Normal   Pulled     52s                  kubelet            Successfully pulled image "luksa/kubia-unhealthy" in 2.55814441s
  Normal   Started    51s (x3 over 4m33s)  kubelet            Started container kubia