1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【kubernetes】liveness probeがfailして終了したコンテナは正常終了扱いになるが…?

Posted at

注意

通常気にする必要のなさそうな小ネタです
最後まで追いきれてません

環境

kubernetes v1.10.5

本編

liveness probeについて
https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/

failするとkubeletがコンテナをkillするというのは書いてある通りでして、この場合コンテナの終了はexitCode:0で記録されています。

    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0

その後の挙動はpodに設定されたrestart policyによります。
Alwaysの場合はひたすら再起動を繰り返します。
Neverの場合は当然そのまま終了します。
exitCodeが0の正常終了なのでステータスはCompletedでした。

NAME      READY     STATUS      RESTARTS   AGE
test      0/1       Completed   0          38s

そうするとOnfailureの場合は…?

試しに動かしてみたところ(なんかちょっとバグっぽい)謎挙動でした。
以下検証

test.yaml
apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  restartPolicy: OnFailure
  containers:
    - name: test
      image: nginx
      livenessProbe:
        httpGet:
          path: /index.html
          port: 80
        initialDelaySeconds: 5
        periodSeconds: 5
        timeoutSeconds: 1
        successThreshold: 1
        failureThreshold: 1

こんな感じのpodを立てて

$ kubectl exec test rm /usr/share/nginx/html/index.html

とやると数秒後に

0s        0s        1         test.156069c40d136031   Pod       spec.containers{test}   Normal    Killing   kubelet, ip-10-0-10-131.ap-northeast-1.compute.internal   Killing container with id docker://test:Container failed liveness probe.. Container will be killed and recreated.

このようなイベントが発生してコンテナが作り直されました。

NAME      READY     STATUS    RESTARTS   AGE
test      1/1       Running   1          1m

restartsが1になってます。
exit codeは0でもlivenessがfailした場合はrestartされるみたいですね。

ところがコンテナが作り直されるたびにindex.htmlを消し続けたところ

NAME      READY     STATUS      RESTARTS   AGE
test      0/1       Completed   3          2m

終了してしまいました
条件はきちんと追ってないのですが、どうもrestart時にbackoffが入ると終了になってしまうような感じがします。

個人的には興味がありますがrestart policyがOnfailureでliveness probeを使うというケースがないので深追いせず終了にします。

ちなみにこの辺りを見ると
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#when-should-you-use-liveness-or-readiness-probes

If you’d like your Container to be killed and restarted if a probe fails, then specify a liveness probe, and specify a restartPolicy of Always or OnFailure.

とあるのでOnfailureの場合もrestartするのが正しい挙動のようですが、繰り返すと終了することについての記述は見当たりませんでした。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?