Kubernetes Set 명령어

KubernetesBeginner
지금 연습하기

소개

Kubernetes 의 set 명령어는 기존 Kubernetes 리소스의 구성을 수정할 수 있는 다재다능한 도구입니다. 이 명령어를 사용하면 YAML 파일을 직접 편집하지 않고도 컨테이너 이미지를 업데이트하고 리소스 요청 및 제한을 구성하는 등 다양한 조정을 수행할 수 있습니다. 이는 리소스 관리를 단순화하고 운영 효율성을 향상시킵니다.

이 랩을 완료하면 다음을 이해하게 됩니다:

  • Kubernetes 클러스터를 시작합니다.
  • Deployment 의 컨테이너 이미지를 업데이트합니다.
  • Deployment 에 대한 리소스 요청 및 제한을 구성합니다.
  • 관련 명령어를 사용하여 Deployment 의 레이블과 주석을 수정합니다.

이 랩은 초보자를 위해 설계되었으며, Kubernetes 도구가 설치된 Ubuntu Linux 시스템에서 작업한다고 가정합니다. Kubernetes 에 대한 사전 경험은 필요하지 않습니다.

Kubernetes 클러스터 시작

Kubernetes 리소스와 상호 작용하기 전에 Kubernetes 클러스터가 실행 중인지 확인하십시오. 이 랩에서는 단일 노드 Kubernetes 클러스터를 설정하기 위해 Minikube 를 사용합니다.

  1. 터미널을 열고 Minikube 를 시작합니다:

    minikube start
    

    이렇게 하면 로컬 Kubernetes 클러스터가 초기화됩니다. Minikube 는 자동으로 적절한 리소스를 할당하지만, 필요에 따라 --cpus--memory와 같은 플래그를 사용하여 사용자 정의할 수 있습니다.

  2. Minikube 가 실행 중인지 확인합니다:

    kubectl cluster-info
    

    출력에서 클러스터가 작동 중임을 확인합니다.

Deployment 생성

클러스터가 실행되면 nginx 이미지를 사용하여 hello-world라는 간단한 Kubernetes deployment 를 생성합니다.

  1. 다음 명령을 실행하여 deployment 를 생성합니다:

    kubectl create deployment hello-world --image=nginx
    

    이 명령어는 nginx 컨테이너의 레플리카 1 개로 hello-world라는 deployment 를 생성합니다.

  2. deployment 가 성공적으로 생성되었는지 확인합니다:

    kubectl get deployments
    

    출력을 확인하여 hello-world가 deployment 목록에 나타나는지 확인합니다.

kubectl set 명령어 탐색

kubectl set 명령어는 애플리케이션 리소스를 구성하고 수정하기 위한 여러 하위 명령어를 제공합니다. 환경 변수, 컨테이너 이미지 및 리소스 설정과 같은 특정 측면을 관리하는 데 도움이 됩니다.

  1. 사용 가능한 kubectl set 하위 명령어를 보려면 다음 명령을 실행합니다:

    kubectl set -h
    

    다음 출력을 볼 수 있습니다:

    Configure application resources.
    
    These commands help you make changes to existing application resources.
    
    Available Commands:
      env              Update environment variables on a pod template
      image            Update the image of a pod template
      resources        Update resource requests/limits on objects with pod templates
      selector         Set the selector on a resource
      serviceaccount   Update the service account of a resource
      subject          Update the user, group, or service account in a role binding or cluster role binding
    
    Usage:
      kubectl set SUBCOMMAND [options]
    
    Use "kubectl --help" for more information about a given command. Use "kubectl options" for a list of global command-line options (applies to all commands).
    

    kubectl set을 사용하는 방법을 이해하기 위해 사용 가능한 하위 명령어와 해당 설명을 검토하십시오.

  2. 필요에 따라 kubectl set --help를 사용하여 각 하위 명령어에 대한 추가 세부 정보를 탐색합니다.

컨테이너 이미지 업데이트

다음으로, hello-world deployment 의 컨테이너 이미지를 특정 버전으로 업데이트합니다.

  1. kubectl set 명령어를 사용하여 컨테이너 이미지를 nginx:1.19.10으로 업데이트합니다:

    kubectl set image deployment/hello-world nginx=nginx:1.19.10
    

    이 명령어는 hello-world deployment 의 nginx 컨테이너를 업데이트합니다.

  2. 컨테이너 이미지를 쿼리하여 이미지 업데이트를 확인합니다:

    kubectl get deployment hello-world -o jsonpath='{.spec.template.spec.containers[0].image}'
    

    출력이 nginx:1.19.10을 표시하는지 확인합니다.

리소스 요청 및 제한 설정

리소스 관리는 Kubernetes deployment 에 필수적입니다. hello-world deployment 에 대한 리소스 요청 및 제한을 설정합니다.

  1. CPU 및 메모리 요청 및 제한을 구성합니다:

    kubectl set resources deployment/hello-world --limits=cpu=1,memory=512Mi --requests=cpu=500m,memory=256Mi
    

    이 명령어는 리소스 요청을 500m CPU 및 256Mi 메모리로, 제한을 1 CPU 및 512Mi 메모리로 설정합니다.

  2. deployment 를 설명하여 리소스 설정을 확인합니다:

    kubectl describe deployment hello-world
    

    출력에서 LimitsRequests 섹션을 확인하여 구성을 확인합니다.

Deployment 라벨 수정

레이블은 Kubernetes 리소스를 분류하고 구성하는 데 도움이 됩니다. kubectl label 명령어를 사용하여 deployment 에 레이블을 추가하거나 수정합니다.

  1. environment=development 레이블을 hello-world deployment 에 추가합니다:

    kubectl label deployment hello-world environment=development
    

    이 명령어는 deployment 에 새로운 레이블을 추가합니다.

  2. 레이블이 적용되었는지 확인합니다:

    kubectl get deployment hello-world --show-labels
    

    LABELS 열에서 environment=development 레이블을 확인합니다.

Deployment 어노테이션 업데이트

어노테이션은 Kubernetes 리소스에 메타데이터를 제공합니다. kubectl annotate 명령어를 사용하여 deployment 에 어노테이션을 추가하거나 업데이트합니다.

  1. owner=team-alpha 어노테이션을 hello-world deployment 에 추가합니다:

    kubectl annotate deployment hello-world owner=team-alpha
    

    이 명령어는 deployment 에 어노테이션을 추가합니다.

  2. 어노테이션이 적용되었는지 확인합니다:

    kubectl describe deployment hello-world
    

    Annotations 섹션에서 owner=team-alpha를 확인합니다.

요약

이 랩에서는 Kubernetes set 명령어를 사용하여 deployment 를 효과적으로 관리하는 방법을 배웠습니다. 다음을 수행했습니다:

  • Kubernetes 클러스터를 시작했습니다.
  • deployment 를 생성했습니다.
  • 컨테이너 이미지를 업데이트했습니다.
  • 리소스 요청 및 제한을 구성했습니다.
  • 적절한 명령어를 사용하여 레이블과 어노테이션을 수정했습니다.

이러한 기술은 Kubernetes 애플리케이션을 효율적으로 관리하는 데 필수적입니다.