DevOps

CKA 예제 리마인더 - 8. Node Affinity

Vince_rf 2024. 10. 29. 00:21

node01 노드에 color=blue 라벨을 추가하세요

나의 답안 )

kubectl label nodes node01 color=blue

Solution )

 

나의 답안과 같음

blue라는 이름의 nginx이미지를 사용하는 레플리카 3개의 디플로이를 생성하세요

나의 답안 )

blue-deploy.yaml 생성

apiVersion: apps/v1
kind: Deployment
metadata:
  name: blue
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80



kubectl apply -f blue-deploy.yaml

Solution )

나의 답안과 같음


디플로이에 Node Affinity를 추가하세요

Name: blue

Replicas: 3

Image: nginx

NodeAffinity: requiredDuringSchedulingIgnoredDuringExecution

Key: color

value: blue

나의 답안 )

spec.template.spec 아래에 

spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: color
                operator: In
                values:
                - blue



affinity 추가

kubectl apply -f blue-deploy.yaml

Solution ) 
나의 답안과 같음

새로운 디플로이를 만드세요

Name: red
Replicas: 2
Image: nginx
label key: node-role.kubernetes.io/control-plane

나의 답안 )
kubectl cp blue-deploy.yaml red-deploy.yaml

kubectl describe node controlplane

lable key node-role.kubernetes.io/control-plane 확인 node-role.kubernetes.io/control-plane=

vim red-deploy.yaml

metadata.name red로 수정

spec.replicas 2로 수정

spec.template.spec.affinity 수정

      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: node-role.kubernetes.io/control-plane
                operator: In
                value:
                - ""



로 할까 생각했지만

controlplane의 키값에 밸류가 비어있고 키 값이 존재하기만 하면 되는 Exsist Operator를 사용함


      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: node-role.kubernetes.io/control-plane
                operator: Exists




kubectl apply -f red-deploy.yaml

 

Solution )

나의 답안과 같음