GAミント至上主義

Web Monomaniacal Developer.

GKEでPODが立ち上がらなくなったときの調査方法

Google CONTAINER ENGINE(以下GKE)ではreplicasの値で簡単にPODを増やせる。


https://cloud.google.com/container-engine/cloud.google.com


でも、なぜかStatusがPendingのままのPODが出るときがある。

※kcはkubectlのエイリアス

% kc get po
NAME READY STATUS RESTARTS AGE
arms-2765276764-o4c8l 1/1 Running 0 21d
arms-2765276764-owzgw 1/1 Running 0 21d
arms-2765276764-tkvdw 1/1 Running 0 21d
gopub-3058232056-emfwd 0/1 Pending 0 9m
gopub-3058232056-h6aan 1/1 Running 0 9m
gopub-3058232056-qiz9u 1/1 Running 0 11m
r2bq-95534634-4ptzf 1/1 Running 0 19d
rabbitmq-3083250092-8jj79 1/1 Running 0 75d
redis-pd-1996650620-p1o6f 1/1 Running 0 160d
revelation-749222209-qqguw 1/1 Running 0 16m
revelation-worker-3204269062-t1vyn 1/1 Running 0 15m
table-manager-1264182560-txkwf 1/1 Running 1 21d

今回、gopub-3058232056-emfwdがいつまで経ってもPendingだった。

おそらくリソース不足なんだけど、詳細が欲しい。

そんなときは、kubectlでイベントを取得する。

kubectl get events
また省略形の
kubectl get ev
で表示できる

% kc get ev (git)-[master]
LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT TYPE REASON SOURCE MESSAGE15m 15m 1 gopub-2970282743-agna1 Pod spec.containers{gopub} Normal Killing {kubelet gke-oceanus-asia-b-default-pool-0eeece87-38ht} Killing
container with docker id f23ac3bcf97a: Need to kill pod.
15m 15m 1 gopub-2970282743 ReplicaSet Normal SuccessfulDelete {replicaset-controller } Deleted
pod: gopub-2970282743-agna1
44s 13m 39 gopub-3058232056-emfwd Pod Warning FailedScheduling {default-scheduler } pod (go
pub-3058232056-emfwd) failed to fit in any node
fit failure on node (gke-oceanus-asia-b-default-pool-0eeece87-38ht): Insufficient cpu
fit failure on node (gke-oceanus-asia-b-default-pool-0eeece87-m6i1): Insufficient cpu

20s 13m 10 gopub-3058232056-emfwd Pod Warning FailedScheduling {default-scheduler } pod (gopub-3058232056-emfwd) failed to fit in any node
fit failure on node (gke-oceanus-asia-b-default-pool-0eeece87-m6i1): Insufficient cpu
fit failure on node (gke-oceanus-asia-b-default-pool-0eeece87-38ht): Insufficient cpu

13m 13m 1 gopub-3058232056-h6aan Pod Normal Scheduled {default-scheduler } Successfully assigned gopub-3058232056-h6aan to gke-oceanus-asia-b-default-pool-0eeece87-38ht
13m 13m 1 gopub-3058232056-h6aan Pod spec.containers{gopub} Normal Pulled {kubelet gke-oceanus-asia-b-default-pool-0eeece87-38ht} Container image "asia.gcr.io/oceanus-dev/gopub:v20170328-02" already present on machine
13m 13m 1 gopub-3058232056-h6aan Pod spec.containers{gopub} Normal Created {kubelet gke-oceanus-asia-b-default-pool-0e


今回は下記の内容から、Insufficient cpu→CPUが不足という原因がわかった。

44s 13m 39 gopub-3058232056-emfwd Pod Warning FailedScheduling {default-scheduler } pod (go
pub-3058232056-emfwd) failed to fit in any node
fit failure on node (gke-oceanus-asia-b-default-pool-0eeece87-38ht): Insufficient cpu
fit failure on node (gke-oceanus-asia-b-default-pool-0eeece87-m6i1): Insufficient cpu

原因が分かれば、クラスタの数を上げるかノードのマシンタイプをアップグレードするか、またはPODを増やすのを諦めるかすれば良い。


クラスタの数は、コマンドなり、クラウドコンソールなりで簡単に数字をいじるだけで変更できるけど、マシンタイプは新しく作り直す必要があるので大変。

またノードの数が5つを超えると料金がかかったりした記憶があるので注意。

今回のgopubサーバーはGo言語で初めて作ったサーバーで、一つ消費メモリ4~7M程度で動いてるので、たくさん動かせるかと思ったけど、n1-standard-1×2ではそろそろ限界が来てしまったよう。

追記

kubectl describe pod {POD ID}

でも似たような結果を取得できる