웹사이트 검색

Kubernetes에서 노드 선택기를 사용하는 방법


이 페이지에서

  1. 전제 조건
  2. 우리가 할 일\n
  3. 노드 선택기 구성
  4. 결론

Pod가 특정 노드에서만 실행되도록 제한할 수 있습니다. 포드가 착륙하는 노드에서 더 많은 제어가 필요한 상황이 있을 수 있습니다.

nodeSelector는 노드 선택 제약 조건 중 하나입니다. nodeSelector는 PodSpec의 필드입니다. 이는 nodeSelector 레이블 container.style.width=100%;var ins=document.createElement(ins);ins.id=slotId+-asloaded;ins와 라벨이 일치하는 노드에 Pod를 예약할 수 있는 간단한 Pod 예약 기능입니다. className=adsbygoogle ezasloaded;ins.dataset.adClient=pid;ins.dataset.adChannel=cid;if(ffid==2){ins.dataset.fullWidthResponsive=true;}

노드 선택에 대해 자세히 알아보려면 여기를 클릭하여 Kubernetes 공식 페이지로 이동하세요.

이 문서에서는 Pod가 마스터 노드에도 배포될 수 있도록 마스터 노드에 taint가 없도록 하겠습니다. 그런 다음 포드를 생성하여 작업자와 마스터 노드에 배포되는 것을 확인합니다. 그런 다음 마스터 노드에 레이블을 연결하고 nodeSelector만 사용하여 마스터 노드에 배포되도록 포인트 포드를 지정합니다.

전제 조건

  1. 최소 1개의 작업자 노드가 있는 Kubernetes 클러스터.
    Kubernetes 클러스터를 만드는 방법을 알아보려면 여기를 클릭하세요. 이 안내서는 AWS Ubuntu 18.04 EC2 인스턴스에서 1개의 마스터와 2개의 노드가 있는 Kubernetes 클러스터를 생성하는 데 도움이 됩니다.\n

우리가 할 일

  1. 노드 선택기 구성

노드 선택기 구성

먼저 다음 명령어를 사용하여 클러스터의 노드 세부정보를 추출합니다.

kubectl get nodes #Get nodes available in the cluster
kubectl describe nodes node01 | grep Taint #Describe node1 node to extract details regarding Taints
kubectl describe nodes master | grep Taint #Describe master node to extract details regarding Taints

위는 노드에 taint가 없음을 보여줍니다. 즉, master 또는 node01의 모든 노드에 Pod를 배치할 수 있습니다.

이제 노드 선택기가 없는 배포를 생성해 보겠습니다.

vim my-deployment-without-node-selector.yaml #Create a deployment definition
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: frontend
  name: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: frontend
  template:
    metadata:
      labels:
        app: frontend
    spec:
      containers:
      - image: httpd:2.4-alpine
        name: frontend

이제 다음 명령을 사용하여 배포를 만들 준비가 되었습니다.

kubectl get pods #Get pods available in the cluster
kubectl create -f my-deployment-without-node-selector.yaml #Create a deployment
kubectl get pods ##Get nodes available in the cluster

이제 파일을 편집하여 배포에서 복제본 수를 변경하고 변경 사항을 적용합니다.

kubectl apply -f my-deployment-without-node-selector.yaml #Apply changes made in the deployment definition file
kubectl get pods -o wide # Get more details regarding pods using -o wide option

위의 스크린샷에서 새 포드가 생성되고 마스터 노드에서도 예약되는 것을 볼 수 있습니다.

그 이유는 마스터 노드와 node01 노드 모두에 taint가 없기 때문입니다.

따라서 일정을 제한하고 포드가 마스터 노드에만 위치하도록 하려면 마스터 노드에 레이블을 생성합니다.

kubectl label nodes master on-master=true #Create a label on the master node
kubectl describe node master #Get more details regarding the master node

위의 스크린샷에서 마스터 노드에 \on-master=true\라는 레이블이 있는 것을 볼 수 있습니다.

이제 Pod가 마스터 노드에만 배포되도록 nodeSelector:on-master=true가 포함된 새 배포를 만들어 보겠습니다.

vim my-deployment-with-node-selector.yaml #Create a deployment definition file 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: streamer-v4-deployment
  labels:
    app: streamer-v4
spec:
  replicas: 2
  selector:
    matchLabels:
      app: streamer-v4
  template:
    metadata:
      labels:
        app: streamer-v4
    spec:
      containers:
      - name: streamer-v4
        image: nginx
        ports:
        - containerPort: 8880
      nodeSelector:
        on-master: "true"

이제 다음 명령을 사용하여 nodeSelector를 사용한 새 배포를 생성할 수 있습니다.

kubectl create -f my-deployment-with-node-selector.yaml #Create a deployment
kubectl get pods -o wide | grep streamer-v4-deployment #Get more details of the pods

위의 스크린샷에서 포드가 마스터 노드에만 배포된 것을 볼 수 있습니다.

이제 "replica=50"을 변경하여 Pod가 배포될 위치를 확인합니다.

vim my-deployment-with-node-selector.yaml #Change a deployment definition

아래 언급된 명령어를 사용하여 최신 변경사항을 적용합니다.

kubectl apply -f my-deployment-with-node-selector.yaml #Apply changes to the deployment

여기에서 모든 포드가 생성되고 \마스터\ 노드에만 배포되는 것을 볼 수 있습니다.

결론

이 문서에서는 label 및 nodeSelector를 사용하여 특정 노드에만 포드가 배포되도록 제한하는 방법을 살펴보았습니다.

또한 마스터 노드에 Taint가 없으면 포드가 배포될 수 있음을 확인했습니다.