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

KubernetesのLimitRangeとResourceQuotaを整理した

Posted at

きっかけ

リソース管理の話題の中で、「あれ、LimitRangeResourceQuotaってどっちがどっちだっけ…?」ってなったので、自分用にまとめておきます。

結論から

  • LimitRange: 1個1個のPodContainerに対する制約
  • ResourceQuota: Namespace全体で使えるリソースの上限

LimitRangeについて

個別のPodに対して「このサイズまでね」「最低限これは指定してね」みたいな制約をかけるやつです。

設定例
apiVersion: v1
kind: LimitRange
metadata:
  name: resource-constraint
  namespace: dev
spec:
  limits:
  - max:
      memory: "2Gi"
      cpu: "1"
    min:
      memory: "128Mi"
      cpu: "100m"
    default: # デフォルトのlimitを定義する
      memory: "512Mi"
      cpu: "500m"
    defaultRequest: # デフォルトのrequestを定義する
      memory: "256Mi"
      cpu: "250m"
    type: Container

これを適用すると、

  • メモリ2Gi、CPU 1コアより大きいコンテナは作れない
  • 最低でもメモリ128Mi、CPU 100mは指定しないとエラーになる
  • 何も指定しないと自動的にデフォルトの値が入る

ResourceQuotaについて

Namespace全体で使えるリソースの総量を制限するものです。チームごとにNamespace分けてる場合、リソースの取り合いを防げます。

設定例
apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-resources
  namespace: dev
spec:
  hard:
    requests.cpu: "10"
    requests.memory: "20Gi"
    limits.cpu: "20"
    limits.memory: "40Gi"
    pods: "20"
    services: "10"
    persistentvolumeclaims: "5"

この設定だと、

  • Namespace内の全Podrequests.cpuの合計が10まで
  • Namespace内の全Podrequests.memoryの合計が20Giまで
  • Pod数は20個まで
注意点

ResourceQuotaを設定すると、Podrequestslimitsの指定が必須になります。

これだとエラーになります。

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
  - name: nginx
    image: nginx
    # resourcesの指定なし → エラーになっちゃう

まとめ

  • LimitRangeは個別のPodの上限・下限・デフォルト値を設定
  • ResourceQuotaNamespace全体のリソース総量を制限

たまに「あれ、どっちだっけ?」ってなるのでメモでした。📝

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?