Exercise 12.1: Assign Pods Using Labels

  1. CP 노드에 연결된 터미널로 이동

  2. 노드 목록 확인

    kubectl get node
  3. 노드에 부여된 Label 확인

    kubectl get node --show-labels
  4. 노드에 부여된 Taint 확인

    kubectl get nodes \
    -o=custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect
  5. 클러스터에 생성된 모든 Pod 확인

    kubectl get pod --all-namespaces -o wide
  6. 각 Node별로 배포된 Pod 갯수 확인

    kubectl describe node | grep -E "(^Name:|^Non-terminated)"
  7. 각 노드에 Label 부여

    {
        kubectl label nodes cp status=vip
        kubectl label nodes worker status=other
    }
  8. 노드에 부여된 Label 확인

    kubectl get nodes --show-labels | grep --color 'status\|$'
  9. Pod 생성 - status=vip Label을 가진 노드에 배포

    cat <<EOF | kubectl create -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: vip
    spec:
      terminationGracePeriodSeconds: 0
      containers:
      - name: busybox
        image: busybox
        args:
        - sleep
        - "1000000"
      nodeSelector:
        status: vip  
    EOF
  10. 위에서 생성한 Pod가 어떤 노드에 배포 됐는지 확인

    kubectl get pod vip -o wide
  11. Pod 삭제

    kubectl delete pod vip
  12. Pod 생성 - 위에서 생성한 Pod와 동일한 Manifest에서 nodeSelector만 삭제

    cat <<EOF | kubectl create -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: vip
    spec:
      terminationGracePeriodSeconds: 0
      containers:
      - name: busybox
        image: busybox
        args:
        - sleep
        - "1000000"
    EOF
  13. 위에서 생성한 Pod가 어떤 노드에 배포 됐는지 확인

    kubectl get pod vip -o wide
  14. Pod 생성 - status=other Label을 가진 노드에 배포

    cat <<EOF | kubectl create -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: other
    spec:
      terminationGracePeriodSeconds: 0
      containers:
      - name: busybox
        image: busybox
        args:
        - sleep
        - "1000000"
      nodeSelector:
        status: other
    EOF
  15. 위에서 생성한 Pod가 어떤 노드에 배포 됐는지 확인

    kubectl get pod other -o wide
  16. Pod 삭제

    kubectl delete pod vip other 

Last updated