4.8.4. Pod 토폴로지 분배 제약 조건에 대한 구성 예
함께 그룹화할 Pod, 분산되는 토폴로지 도메인 및 허용 가능한 불일치를 지정할 수 있습니다.
다음 예제에서는 Pod 토폴로지 분배 제약 조건 구성을 보여줍니다.
영역에 따라 지정된 라벨과 일치하는 Pod를 배포하는 예
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
region: us-east
spec:
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
region: us-east
matchLabelKeys:
- my-pod-label
containers:
- image: "docker.io/ocpqe/hello-pod"
name: hello-pod
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: [ALL]
- 1
- 두 토폴로지 도메인 간 최대 Pod 수 차이입니다. 기본값은
1이고 값0은 지정할 수 없습니다. - 2
- 노드 라벨의 키입니다. 이 키 및 동일한 값이 있는 노드는 동일한 토폴로지에 있는 것으로 간주됩니다.
- 3
- 분배 제약 조건을 충족하지 않는 경우 Pod를 처리하는 방법입니다. 기본값은 스케줄러에 Pod를 예약하지 않도록 지시하는
DoNotSchedule입니다. Pod를 계속 예약하기 위해ScheduleAnyway로 설정하지만 스케줄러는 클러스터의 불균형이 더 심해지지 않도록 불일치에 따라 우선순위를 부여합니다. - 4
- 이 라벨 선택기와 일치하는 Pod는 제약 조건을 충족하기 위해 분배될 때 계산되고 그룹으로 인식됩니다. 라벨 선택기를 지정해야 합니다. 그러지 않으면 일치하는 Pod가 없습니다.
- 5
- 이
Pod사양도 나중에 올바르게 계산되도록 하려면 해당 라벨을 이 라벨 선택기와 일치하도록 설정해야 합니다. - 6
- 분배를 계산할 Pod를 선택하는 Pod 레이블 키 목록입니다.
단일 Pod 토폴로지 분배 제약 조건의 예
kind: Pod
apiVersion: v1
metadata:
name: my-pod
labels:
region: us-east
spec:
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
region: us-east
containers:
- image: "docker.io/ocpqe/hello-pod"
name: hello-pod
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: [ALL]
이전 예제에서는 하나의 Pod 토폴로지 분배 제약 조건을 사용하여 Pod 사양을 정의합니다. region 레이블이 지정된 Pod와 일치합니다. us-east 는 영역에 배포되고, 1 의 스큐를 지정하고, 이러한 요구 사항을 충족하지 않는 경우 Pod를 예약하지 않습니다.
여러 Pod 토폴로지 분배 제약 조건을 보여주는 예
kind: Pod
apiVersion: v1
metadata:
name: my-pod-2
labels:
region: us-east
spec:
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
topologySpreadConstraints:
- maxSkew: 1
topologyKey: node
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
region: us-east
- maxSkew: 1
topologyKey: rack
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
region: us-east
containers:
- image: "docker.io/ocpqe/hello-pod"
name: hello-pod
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: [ALL]
이전 예제에서는 두 개의 Pod 토폴로지 분배 제약 조건이 있는 Pod 사양을 정의합니다. 둘 다 region: us-east 레이블이 지정된 Pod와 일치하고, 불일치를 1 로 지정하고, 이러한 요구 사항을 충족하지 않는 경우 Pod를 예약하지 않습니다.
첫 번째 제약 조건에서는 사용자 정의 라벨 node를 기반으로 Pod를 배포하고, 두 번째는 제약 조건에서는 사용자 정의 라벨 rack을 기반으로 Pod를 배포합니다. Pod를 예약하려면 두 제약 조건을 모두 충족해야 합니다.