2
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 3 years have passed since last update.

[Kubernetes]QoS Classの設定を確認する

Posted at

はじめに

以前リソース制御の動作を確認した際に、リソース制御を設定しているPodの方が優先度が高い動作を確認しました。

[Kubernetes]リソース制御の動作を確認する 2

「Kubernetes完全ガイド」を読み進めていくと、この優先度はQoS Classで設定されていると書かれていました。
リソース制御の動作を確認していたときは、QoS Classのことを意識していなかったので、改めてQoS Classの確認をしたいと思います。

QoS Class 概要

QoS Classはユーザが明示的に指定するものではなく、以下の条件で自動的に設定されます。

QoS Class 条件 優先度
Guaranteed Pod内のすべてのコンテナのCPUとメモリにRequests/Limitsが設定されている。かつRequests=Limitsである。 1
Burstable Pod内の1つ以上のコンテナのCPUまたはメモリにRequestsが設定されている。かつGuaranteedを満たさない 2
BestEffort Pod内のすべてのコンテナにRequests/Limitsが設定されていない 3

参考
PodにQuality of Serviceを設定する

設定の確認

実際に以下のPodを作ってQoS Classを確認します。

nginx-qos.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-guaranteed
spec:
  replicas: 2
  selector:
    matchLabels:
      env: prd
  template:
    metadata:
      labels:
        env: prd
    spec:
      containers:
        - name: nginx-guaranteed
          image: nginx:latest
          resources:
            requests:
              memory: 200Mi
              cpu: 1100m
            limits:
              memory: 200Mi
              cpu: 1100m
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-burstable
spec:
  replicas: 2
  selector:
    matchLabels:
      env: prd
  template:
    metadata:
      labels:
        env: prd
    spec:
      containers:
        - name: nginx-burstable
          image: nginx:latest
          resources:
            requests:
              cpu: 500m
            limits:
              cpu: 1500m
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-besteffort
spec:
  replicas: 2
  selector:
    matchLabels:
      env: prd
  template:
    metadata:
      labels:
        env: prd
    spec:
      containers:
        - name: nginx-besteffort
          image: nginx:latest
$ kubectl apply -f nginx-qos.yaml
deployment.apps/nginx-guaranteed created
deployment.apps/nginx-burstable created
deployment.apps/nginx-besteffort created
$ kubectl get pod -o custom-columns="NAME:{.metadata.name},QoS Class:{.status.qosClass},Node:{.spec.nodeName}"
NAME                                QoS Class    Node
nginx-besteffort-54bf789fbf-dszpx   BestEffort   k8s-worker02
nginx-besteffort-54bf789fbf-j2t9w   BestEffort   k8s-worker01
nginx-burstable-5cb9dc4547-gbx2h    Burstable    k8s-worker02
nginx-burstable-5cb9dc4547-zfdjg    Burstable    k8s-worker01
nginx-guaranteed-5b6d5c7fc5-c2t59   Guaranteed   k8s-worker02
nginx-guaranteed-5b6d5c7fc5-mk78m   Guaranteed   k8s-worker01

QoS Classが設定されていますね。

動作確認

以前、BurstableとBestEffortの優先順は確認しましたので、今回はGuaranteedとBurstableを確認します。
別ターミナルを開いてコンテナにログインして負荷をかけます。

$ kubectl exec -it nginx-burstable-5cb9dc4547-zfdjg /bin/bash
root@nginx-burstable-5cb9dc4547-zfdjg:/# yes >/dev/null &
[1] 12
root@nginx-burstable-5cb9dc4547-zfdjg:/# yes >/dev/null &
[2] 13
root@nginx-burstable-5cb9dc4547-zfdjg:/# yes >/dev/null &
[3] 14

負荷を確認します。

$ kubectl top pod | grep -e nginx-guaranteed-5b6d5c7fc5-c2t59 -e nginx-burstable-5cb9dc4547-zfdjg
nginx-burstable-5cb9dc4547-zfdjg    1467m        2Mi
nginx-guaranteed-5b6d5c7fc5-mk78m   0m           1Mi

BurstableがほぼLimitsの値(1500m)まで使ってますね。

この状態でGuaranteedにもログインして、同様に負荷をかけます。

$ kubectl exec -it nginx-guaranteed-5b6d5c7fc5-mk78m /bin/bash
root@nginx-guaranteed-5b6d5c7fc5-mk78m:/#  yes > /dev/null &
[1] 12
root@nginx-guaranteed-5b6d5c7fc5-mk78m:/#  yes > /dev/null &
[2] 13
root@nginx-guaranteed-5b6d5c7fc5-mk78m:/#  yes > /dev/null &

負荷を確認します。

$ kubectl top pod | grep -e nginx-burstable-5cb9dc4547-zfdjg -e nginx-guaranteed-5b6d5c7fc5-mk78m
nginx-burstable-5cb9dc4547-zfdjg    980m         2Mi
nginx-guaranteed-5b6d5c7fc5-mk78m   921m         2Mi

微妙。。
Guaranteedの負荷を増やしてみましたが、Limitsの1100mまではいきませんでした。

まとめ

QoS Classが設定されていることは確認できましたが、優先順が正しく動作しているかははっきりとはわかりませんでした。
検証環境のリソースが貧弱なので、差がはっきり出なかったのかなと想像しています。

2
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
2
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?