참고 문서: kubernetes.io/assign-pod-node
보통은 스케줄러가 자동으로 리소스를 파악하고 파드를 배치하지만 특정 노드에 파드를 배포하고 싶거나 다른 두 개의 서비스를 동일한 노드에 배포하고 싶을 경우와 같이 파드 배포에 대한 제어가 필요할 때 사용함
노드 레이블을 명시하여 특정 노드로 파드를 배포함
예시 1. 파드 생성 시
pod.yml
- Name: red
- Image: nginx
- NodeAffinity: requiredDuringSchedulingIgnoredDuringExecution
- Key: color
- values: blue
apiVersion: v1
kind: Pod
metadata:
name: red
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: color
operator: In
values:
- blue
containers:
- name: red
image: nginx
예시 2. 디플로이먼트 생성 시
deployment.yml:
- Name: red
- Replicas: 2
- Image: nginx
- NodeAffinity: requiredDuringSchedulingIgnoredDuringExecution
- Key: node-role.kubernetes.io/control-plane
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: red
name: red
spec:
replicas: 2
selector:
matchLabels:
app: red
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: red
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/control-plane
operator: Exists
containers:
- image: nginx
imagePullPolicy: Always
name: nginx