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】ノードに均等にPodを配置する topologySpreadConstraints

Last updated at Posted at 2025-04-04

topologySpreadConstraints

DeploymentなどのPodテンプレートに指定することで、Podがスケジュールされるときに、指定したトポロジキー(例えばノードやAZ)に対して偏りなく配置されるよう制約をかけるものです。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: netshoot
spec:
  selector:
    matchLabels:
      app: netshoot
  replicas: 3
  template:
    metadata:
      labels:
        app: netshoot
    spec:
      topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: "kubernetes.io/hostname"
          whenUnsatisfiable: ScheduleAnyway
          labelSelector:
            matchLabels:
              app: netshoot
      containers:
        - name: netshoot
          image: nicolaka/netshoot
          command: ["sleep", "infinity"]
          resources:
            limits:
              cpu: "125m"
              memory: "100Mi"
            requests:
              cpu: "125m"
              memory: "100Mi"

パラメータ 意味

  • maxSkew
    各トポロジ単位(ノードなど)でのPod数の最大の偏り幅。
    例:1なら「多いところと少ないところで1個までの差」しか許さない。
  • topologyKey
    分散対象の単位となるノードラベルを指定します。
    • kubernetes.io/hostname : ノード単位
    • topology.kubernetes.io/zone : AZ単位
  • whenUnsatisfiable
    制約を満たせないときの動作。
    • DoNotSchedule:Podのスケジューリングを拒否
    • ScheduleAnyway:偏ってもスケジューリングする
  • labelSelector
    このラベルセレクタに一致するPodが分散対象となります。分散対象となるPodのラベルセレクター。
    例えば、app: my-app のPodを分散対象にする。
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?