apiVersion: v1
kind: Pod
metadata:
name: kubernetes-nodeselector-pod
spec:
containers:
- name: kubernetes-nodeselector-pod
image: arisu1000/simple-container-app:latest
ports:
- containerPort: 8080
nodeSelector:
disktype: hdd
YAML
복사
scheduling/nodeselector.yaml
위 yaml 파일을 apply 하면 파드 상태가 Pending이다. .spec.nodeSelector.disktype 필드 값 hdd는 노드 레이블의 설정인 ssd와 달라서 실행할 노드가 없기 때문이다.
따라서 hdd를 ssd로 변경 후 다시 실행한다.
apiVersion: v1
kind: Pod
metadata:
name: kubernetes-nodeselector-pod
spec:
containers:
- name: kubernetes-nodeselector-pod
image: arisu1000/simple-container-app:latest
ports:
- containerPort: 8080
nodeSelector:
disktype: ssd
YAML
복사
scheduling/nodeselector.yaml
12.2 어피니티와 안티 어피니티
12.2.1 노드 어피니티
apiVersion: v1
kind: Pod
metadata:
name: kubernetes-nodeaffinity-pod
spec:
containers:
- name: kubernetes-nodeaffinity-pod
image: arisu1000/simple-container-app:latest
ports:
- containerPort: 8080
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: beta.kubernetes.io/os
operator: In
values:
- linux
- window
- key: disktype
operator: Exists
# - key: core
# operator: Gt
# values:
# - "4"
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 10
preference:
matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- worker-node01
YAML
복사
scheduling/node-affinity.yaml
12.2.2 파드의 어피니티와 안티 어피니티
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-cache
spec:
selector:
matchLabels:
app: store
replicas: 2
template:
metadata:
labels:
app: store
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- store
topologyKey: "kubernetes.io/hostname"
containers:
- name: redis-server
image: redis:3.2-alpine
YAML
복사
scheduling/pod-antiaffinity.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-server
spec:
selector:
matchLabels:
app: web-store
replicas: 2
template:
metadata:
labels:
app: web-store
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- web-store
topologyKey: "kubernetes.io/hostname"
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- store
topologyKey: "kubernetes.io/hostname"
containers:
- name: web-app
image: nginx:1.12-alpine
YAML
복사
scheduling/pod-antiaffinity.yaml