この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
Fargate for EKSでProbeが実行できるか検証してみました。
検証の背景
k8s上でサーバーレスコンテナプラットフォームを利用するための手段としてvirtual-kubeletというものが存在しています。 このvirtual-kubeletを利用するとコンテナの実行基盤としてFargateやACIなどを実行するとこができますが、Probeが使えず、コンテナの診断は自分たちで実装するしかありませんでした。
んじゃあ、Fargate for EKSではどうなってるの??というのが気になったので検証してみました。
参考
やってみた
以下の環境で確認します。
- aws cli: 1.16.296
- eksctl: 0.11.0
クラスタ作成
eksctlの0.11.0より--fargate
オプションが追加されているので、これを使ってクラスタを作成します。
$ eksctl create cluster --fargate --name eks-fargete-cluster
$ kubectl version --short
Client Version: v1.14.8
Server Version: v1.14.8-eks-b8860f
--fargate
オプションを使うことによりfargateProfileも作成されるようになります。
$ aws eks list-fargate-profiles --cluster-name eks-fargete-cluster
{
"fargateProfileNames": [
"fp-default"
]
}
k8sは以下のような状態となります。
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
fargate-ip-192-168-119-150.ap-northeast-1.compute.internal Ready <none> 25m v1.14.8-eks
fargate-ip-192-168-165-66.ap-northeast-1.compute.internal Ready <none> 26m v1.14.8-eks
$ kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-6d75bbbf58-45bmk 1/1 Running 0 26m
kube-system coredns-6d75bbbf58-9cwz8 1/1 Running 0 26m
Probeの実行
livenessProbeはコンテナの死活監視の設定です。livenessProbeに失敗するとコンテナは削除されます。 livenessを確認するため以下のPodをデプロイします。定義ファイルは公式ドキュメントのものを利用します。
コンテナは起動時に/tmp/healthy
というファイルを作成しlivenessProbeではそのファイルを監視します。30秒後に/tmp/healthy
を削除することでlivenessProbeが失敗し、コンテナが再起動されるというのが期待値になります。
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-exec
spec:
containers:
- name: liveness
image: k8s.gcr.io/busybox
args:
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
PodをデプロイしPodの状態を監視します。
$ kubectl apply -f exec-liveness.yaml
pod/liveness-exec created
kubectl$ get pods --watch
NAME READY STATUS RESTARTS AGE
liveness-exec 0/1 Pending 0 7s
liveness-exec 0/1 Pending 0 24s
liveness-exec 0/1 ContainerCreating 0 24s
liveness-exec 1/1 Running 0 27s
liveness-exec 1/1 Running 1 103s
liveness-exec 1/1 Running 2 2m58s
liveness-exec 1/1 Running 3 4m13s
定期的に再起動されておりlivenessProbeが有効であることが確認できます。イベントにもLivenessの結果が出力されてます。
$ kubectl describe pod liveness-exec
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Pulling 55s (x3 over 3m26s) kubelet, fargate-ip-192-168-191-91.ap-northeast-1.compute.internal Pulling image "k8s.gcr.io/busybox"
Normal Pulled 54s (x3 over 3m25s) kubelet, fargate-ip-192-168-191-91.ap-northeast-1.compute.internal Successfully pulled image "k8s.gcr.io/busybox"
Normal Created 54s (x3 over 3m24s) kubelet, fargate-ip-192-168-191-91.ap-northeast-1.compute.internal Created container liveness
Normal Started 53s (x3 over 3m24s) kubelet, fargate-ip-192-168-191-91.ap-northeast-1.compute.internal Started container liveness
Warning Unhealthy 10s (x9 over 2m50s) kubelet, fargate-ip-192-168-191-91.ap-northeast-1.compute.internal Liveness probe failed: cat: can't open '/tmp/healthy': No such file or directory
Normal Killing 10s (x3 over 2m40s) kubelet, fargate-ip-192-168-191-91.ap-northeast-1.compute.internal Container liveness failed liveness probe, will be restarted
まとめ
Fargate for EKSでProbeは問題なく使えそうです!!