반응형
실습1)
blue pod는 nginx 이미지로 배포하였으며, 각 노드에 pod가 스케줄링되어 있는 상태입니다.
p.s, node01에는 lable color=blue로 설정되어 있습니다.
controlplane ~ ➜ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
blue-7698dfcb9f-7z9dq 1/1 Running 0 19s 10.244.1.3 node01 <none> <none>
blue-7698dfcb9f-rtg9j 1/1 Running 0 19s 10.244.1.2 node01 <none> <none>
blue-7698dfcb9f-s8qns 1/1 Running 0 19s 10.244.0.4 controlplane <none> <none>
여기서, Pod를 node01에만 배치하려면 deployment에 노드 affinity를 설정하는 실습을 해보겠습니다.
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: blue
name: blue
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: blue
template:
metadata:
labels:
app: blue
spec:
containers:
- image: nginx
name: nginx
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: color
operator: In
values:
- blue
출력 결과:
모든 pod들이 node01에 배치되어 있는 것을 확인할 수 있습니다.
controlplane ~ ➜ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
blue-7cf59b987f-cwbl9 1/1 Running 0 65s 10.244.1.6 node01 <none> <none>
blue-7cf59b987f-kscgz 1/1 Running 0 65s 10.244.1.4 node01 <none> <none>
blue-7cf59b987f-nb2j4 1/1 Running 0 65s 10.244.1.5 node01 <none> <none>
실습2)
nginx 이미지와 2개의 replica로 red라는 이름의 새 배포를 생성하고 control-plane 노드에만 배치되는지 확인합니다.
컨트롤 플레인 노드에 이미 설정된 라벨 키(node-role.kubernetes.io/control-plane)를 사용하였습니다.
apiVersion: apps/v1
kind: Deployment
metadata:
name: red
spec:
replicas: 2
selector:
matchLabels:
run: nginx
template:
metadata:
labels:
run: nginx
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/control-plane
operator: Exists
출력 결과:
controlplane ~ ➜ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
blue-7cf59b987f-cwbl9 1/1 Running 0 10m 10.244.1.6 node01 <none> <none>
blue-7cf59b987f-kscgz 1/1 Running 0 10m 10.244.1.4 node01 <none> <none>
blue-7cf59b987f-nb2j4 1/1 Running 0 10m 10.244.1.5 node01 <none> <none>
red-6c897b6676-rwb44 1/1 Running 0 9s 10.244.0.7 controlplane <none> <none>
red-6c897b6676-vlbgp 1/1 Running 0 9s 10.244.0.6 controlplane <none> <none>
반응형
'클라우드(Cloud) > 쿠버네티스(Kubernetes)' 카테고리의 다른 글
[Kubernetes] kubeadm init 시, bridge-nf-call-iptables does not exist 에러 해결 (0) | 2024.06.10 |
---|---|
[Kubernetes] 쿠버네티스 리소스 제한으로 인한 OOM killed 트러블슈팅 (Resource Requirements) (0) | 2023.05.03 |
[Kubernetes] 쿠버네티스 Security Contexts 사용 예제 (0) | 2023.05.02 |
[Kubernetes] 쿠버네티스 ConfigMap 사용 예제 (0) | 2023.04.21 |