LoginSignup
0
0

More than 3 years have passed since last update.

AKS で Cluster の Autoscaler を実行する②

Posted at

前回はマニフェストファイルで Autoscaler が定義できることを見てきました。
前回記事はこちら ⇒ AKS で Cluster の Autoscaler を実行する
https://qiita.com/komiyasa/items/96ed53772a52e78722a1

今回の記事では作成したマニフェストファイルを深掘りしていきます。

Node 数の上限下限を設定する

Pending 状態の Pod があれば上限がなく Node を増やしてしまうのは困ります。そのため、マニフェストファイルで Node の数の上限を設定しています。具体的には以下の部分の --node=1:5:default で設定しています。この場合は Node の最小数が1、最大数が5に設定しています。

autoscaler.yaml
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cluster-autoscaler
  template:
    metadata:
      labels:
        app: cluster-autoscaler
    spec:
      serviceAccountName: cluster-autoscaler
      containers:
      - image: gcr.io/google-containers/cluster-autoscaler:v1.3.5
        imagePullPolicy: Always
        name: cluster-autoscaler
        resources:
          limits:
            cpu: 100m
            memory: 300Mi
          requests:
            cpu: 100m
            memory: 300Mi
        command:
        - ./cluster-autoscaler
        - --v=3
        - --logtostderr=true
        - --cloud-provider=azure
        - --skip-nodes-with-local-storage=false
        - --nodes=1:5:default

ここで上限を超えるレプリカセットを作成する宣言をしてみます。kubectl scale deployment nginx --replicas=XX でレプリカセットの数を宣言しデプロイすることが可能です。実際に動かしてみます。

$ kubectl scale deployment nginx --replicas=16
deployment.extensions/nginx scaled

16 のレプリカセットをデプロイする宣言をしました。Pod がどうなっているか kubectl get po コマンドで確認してみます。

$ kubectl get po
NAME                    READY   STATUS    RESTARTS   AGE
nginx-5d7cb88cc-2n8nz   0/1     Pending   0          93s
nginx-5d7cb88cc-4z98t   0/1     Pending   0          93s
nginx-5d7cb88cc-52k86   0/1     Pending   0          93s
nginx-5d7cb88cc-5w9qz   0/1     Pending   0          93s
nginx-5d7cb88cc-62cbc   0/1     Pending   0          93s
nginx-5d7cb88cc-88l9z   0/1     Pending   0          93s
nginx-5d7cb88cc-cndn4   0/1     Pending   0          4m46s
nginx-5d7cb88cc-cxgpr   0/1     Pending   0          93s
nginx-5d7cb88cc-d9v4p   0/1     Pending   0          93s
nginx-5d7cb88cc-g2gb9   0/1     Pending   0          93s
nginx-5d7cb88cc-hk797   0/1     Pending   0          93s
nginx-5d7cb88cc-kfscq   0/1     Pending   0          93s
nginx-5d7cb88cc-lk2ds   1/1     Running   0          4m46s
nginx-5d7cb88cc-n7ppb   0/1     Pending   0          93s
nginx-5d7cb88cc-p5jtl   0/1     Pending   0          93s
nginx-5d7cb88cc-xzqcc   0/1     Pending   0          93s

Pod は合計で16作成されていますが、Pending のものが多いです。Cluster Autoscaler はこの状態をどのようにとらえているかは、kubectl log コマンドで確認できます。このコマンドを実行するには、Autoscaler の名前が必要です。kubectl get po -n kube-system|grep cluster-autoscaler で確認します。

$ kubectl get po -n kube-system|grep cluster-autoscale
cluster-autoscaler-fb96bcd-jrw7l        1/1     Running   0          7m23s

このコマンドを実行することで。Pod cluster-autoscaler が問題なく動いていることが確認できます。このあとで kubectl logs -n kube-system cluster-autoscaler-fb96bcd-jrw7l を実行します。実行結果では、先ほど上限として設定した5つの Node をスケールしようとしていることが分かります。kubectl get nodes で結果を確認します。(Scale を実行しているため、少し時間を置く必要がります。)

$ kubectl get nodes
NAME                                STATUS   ROLES   AGE     VERSION
aks-nodepool1-20100757-vmss000000   Ready    agent   52m     v1.13.12
aks-nodepool1-20100757-vmss000001   Ready    agent   3m22s   v1.13.12
aks-nodepool1-20100757-vmss000002   Ready    agent   24s     v1.13.12
aks-nodepool1-20100757-vmss000003   Ready    agent   24s     v1.13.12
aks-nodepool1-20100757-vmss000004   Ready    agent   24s     v1.13.12

では Pod の数はどうでしょうか。

$ kubectl get po
NAME                    READY   STATUS    RESTARTS   AGE
nginx-5d7cb88cc-6c7gt   0/1     Pending   0          5m9s
nginx-5d7cb88cc-98mjf   0/1     Pending   0          5m9s
nginx-5d7cb88cc-b6fd9   0/1     Pending   0          5m9s
nginx-5d7cb88cc-ffc26   1/1     Running   0          5m9s
nginx-5d7cb88cc-gct7w   0/1     Pending   0          5m9s
nginx-5d7cb88cc-h2zx4   0/1     Pending   0          5m9s
nginx-5d7cb88cc-k6mh6   1/1     Running   0          5m9s
nginx-5d7cb88cc-krtth   0/1     Pending   0          5m9s
nginx-5d7cb88cc-m4qgw   0/1     Pending   0          5m9s
nginx-5d7cb88cc-mwcvl   0/1     Pending   0          5m9s
nginx-5d7cb88cc-ngp97   1/1     Running   0          12m
nginx-5d7cb88cc-p2dlj   0/1     Pending   0          5m9s
nginx-5d7cb88cc-q28zw   0/1     Pending   0          5m9s
nginx-5d7cb88cc-q64vf   1/1     Running   0          5m9s
nginx-5d7cb88cc-qwh57   0/1     Pending   0          5m9s
nginx-5d7cb88cc-r6lw9   1/1     Running   0          12m

まだ Pending の Pod があることが分かります。つまり、マニフェストファイルで Autoscale を定義することで上限が設定され、その上限を超える場合は Pending の Pod があっても Autoscale を実施しない、ということが分かりました。

次回の記事では、逆の Node スケールインの方法についてみていきたいと思います。

参考

Horizontal Pod Autoscaling
https://github.com/kubernetes/community/blob/master/contributors/design-proposals/autoscaling/horizontal-pod-autoscaler.md

Horizontal Pod Autoscaler Walkthrough
https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/

Azure Kubernetes Service (AKS) でのアプリケーションの需要を満たすようにクラスターを自動的にスケーリング
https://docs.microsoft.com/ja-jp/azure/aks/cluster-autoscaler

0
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
0
0