LoginSignup
15
12

More than 5 years have passed since last update.

kubernetesでreplicasを2にしたり、rolling-updateするとpodがpendingのままになってしまった時の対処

Posted at

rolling-update出来ないなんてkubernetesの左腕を落とされたようなもんだよ、とほほ…と渋々deploymentの更新をkubectl delete -f somedeployment.yaml && kubectl create -f somedeployment.yamlという原始的なコマンドでやっていたわけですが(もちろんダウンタイムが発生)、pendingにならない方法を見つけたので書いておきます
というかドキュメントちゃんと読んだ人は何でそんなこと知らずに使ってんだという感じなんでしょうがGitHub issueに同じような書き込みしてる英語圏の人々がたくさんいたので英語が読めないとか関係なくやつらも読んでいない(確信)

rolling-updateをした時に作成されるpodで合計数が2になったり、deployment.yamlにreplicas: 2を設定すると後から作成されるpodのステータスがpendingのままお亡くなりになってしまった疲れからか不幸にも黒塗りの高級車に追突してしまう。後輩をかばいすべての責任を負った三浦に対し、車の主、暴力団員谷岡に言い渡された示談の条件とは…。

※イメージ
Pendingしてるpodをdescribeするとこんなエラーが出ている

No nodes are available that match all of the following predicates:: Insufficient cpu (1)

理由は、kubectl describe nodes/指定node名の下の方に出てくるCPU Requestsという数値が100%を超えてしまうような設定や動作になっているためPendingのままになる

例えば小さいnode上のk8sが使っているpodがCPU Requests80%使っている場合、利用者が追加できるのは20%分のCPU Requestsしかない
APIサーバー、フロントエンドWebサーバーがそれぞれ1pod10%ずつ利用する設定になっている場合、applyやreplaceで新pod1つ追加されるだけで110%使用することになりPendingのままになる
Rolling-updateしたいなら10%を5%にしてしまえばいい

Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  CPU Requests  CPU Limits      Memory Requests Memory Limits
  ------------  ----------      --------------- -------------
  878m (87%)    248m (24%)      700816Ki (40%)  854416Ki (49%)
Events:         <none>

CPU Requestsで使用する数値設定

    1 apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1
    2 kind: Deployment
    3 metadata:
    4   name: spa-web-nginx
    5 spec:
    6   replicas: 1
    7   template:
    8     metadata:
    9       labels:
   10         app: spa-web-nginx
   11     spec:
   12       containers:
   13       - name: spa-web-nginx-container
   14         image: somerepository/spa-web-nginx-build:v6
   15         ports:
   16         - containerPort: 80
   17         resources:
   18           limits:
   19             cpu: "1"
   20           requests:
   21             cpu: 50m # デフォルト100m使っていたので半分の50mに設定する

replicasは1なのでrolling-updateしても問題なくdeploymentの更新もできる
50mにしたのでreplicasを2にしても両pods動作する(CPU Requestsギリギリだったのでrolling-updateは動かなくなる)

雑なコマンドメモ

nodeを一覧取得

kubectl get nodes

nodeのdescribe

kubectl describe nodes/nodeのNAME

deploymentの更新

kubectl apply -f somedeployment.yaml
kubectl replace -f somedeployment.yaml

所感

人権を取り戻した
疲れた、ドキュメントは各自読んでくれリンクは置く
pengingと書いてしまいペンギンしていた:penguin:

調べたページ

https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/
https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/
https://kubernetes.io/docs/tasks/administer-cluster/cpu-default-namespace/
https://stackoverflow.com/questions/45573825/pod-will-not-start-due-to-no-nodes-are-available-that-match-all-of-the-followin

15
12
1

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
15
12