Kubernetes Describe 명령어

KubernetesBeginner
지금 연습하기

소개

Kubernetes 의 describe 명령어는 Kubernetes 리소스에 대한 상세 정보를 확인하는 강력한 도구입니다. describe 명령어를 사용하면 리소스 상태, 이벤트, 레이블, 어노테이션 등을 포함한 다양한 정보를 볼 수 있습니다. 이는 Kubernetes 클러스터에서 문제를 해결하는 데 유용할 수 있습니다.

이것은 가이드 실험입니다. 학습과 실습을 돕기 위한 단계별 지침을 제공합니다.각 단계를 완료하고 실무 경험을 쌓기 위해 지침을 주의 깊게 따르세요. 과거 데이터에 따르면, 이것은 초급 레벨의 실험이며 완료율은 98%입니다.학습자들로부터 100%의 긍정적인 리뷰율을 받았습니다.

Minikube 시작 및 클러스터 확인

Kubernetes 를 사용하기 전에 실행 중인 클러스터가 필요합니다. Minikube 는 가벼운 로컬 Kubernetes 클러스터를 제공합니다.

  1. 프로젝트 디렉토리로 이동:

    터미널을 열고 기본 작업 디렉토리로 이동합니다.

    cd /home/labex/project
  2. Minikube 시작:

    Minikube 를 시작하여 클러스터를 초기화합니다.

    minikube start
    • Minikube 는 단일 노드 Kubernetes 클러스터를 생성합니다. 이 단계는 몇 분 정도 걸릴 수 있습니다.
  3. Minikube 상태 확인:

    Minikube 가 성공적으로 시작되었는지 확인합니다.

    minikube status

    apiserverkubelet과 같은 구성 요소가 Running으로 나열되어 있는지 확인합니다.

  4. Kubernetes 구성 확인:

    kubectl이 Minikube 클러스터에 연결되어 있는지 확인합니다.

    kubectl cluster-info

    API 서버 및 기타 구성 요소에 대한 세부 정보를 표시합니다.

Minikube 가 시작에 실패하면 minikube delete를 사용하여 재설정하고 다시 시도하십시오.

kubectl describe 명령어 탐색

kubectl describe 명령어는 특정 리소스 또는 리소스 그룹에 대한 상세 정보를 표시하는 데 사용됩니다. 리소스의 구성, 상태 및 관련 이벤트에 대한 통찰력을 제공합니다.

kubectl describe에 사용 가능한 옵션을 보려면 다음 명령을 실행하십시오.

kubectl describe -h

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

Show details of a specific resource or group of resources.

Print a detailed description of the selected resources, including related resources such as events or controllers. You
may select a single object by name, all objects of that type, provide a name prefix, or label selector. For example:

  $ kubectl describe TYPE NAME_PREFIX

will first check for an exact match on TYPE and NAME_PREFIX. If no such resource exists, it will output details for
every resource that has a name prefixed with NAME_PREFIX.

Use "kubectl api-resources" for a complete list of supported resources.

Examples:
  ## Describe a node
  kubectl describe nodes kubernetes-node-emt8.c.myproject.internal

  ## Describe a pod
  kubectl describe pods/nginx

  ## Describe a pod identified by type and name in "pod.json"
  kubectl describe -f pod.json

  ## Describe all pods
  kubectl describe pods

  ## Describe pods by label name=myLabel
  kubectl describe po -l name=myLabel

  ## Describe all pods managed by the 'frontend' replication controller
  ## (rc-created pods get the name of the rc as a prefix in the pod name)
  kubectl describe pods frontend

Pod 정보 확인 (kubectl describe)

이 단계에서는 describe 명령을 사용하여 Kubernetes Pod 에 대한 정보를 보는 방법을 배우게 됩니다.

  1. 레플리카의 템플릿으로 사용될 간단한 Pod 를 생성합니다. 다음 내용으로 myapp-pod.yaml이라는 파일을 생성합니다.

    apiVersion: v1
    kind: Pod
    metadata:
      name: myapp-pod
    spec:
      containers:
        - name: myapp-container
          image: nginx
          ports:
            - containerPort: 80

    다음 명령을 사용하여 Pod 를 생성합니다.

    kubectl apply -f myapp-pod.yaml
  2. 그런 다음 Pod 를 설명합니다.

    kubectl describe pod myapp-pod

이 명령은 상태, 레이블, 주석, 이벤트 등을 포함하여 지정된 Pod 에 대한 자세한 정보를 검색합니다.

Deployment 정보 확인 (kubectl describe)

이 단계에서는 describe 명령을 사용하여 Kubernetes Deployment 에 대한 정보를 보는 방법을 배우게 됩니다.

  1. 다음 내용으로 myapp-deployment.yaml이라는 파일을 생성합니다.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: myapp-deployment
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: myapp-deployment
      template:
        metadata:
          labels:
            app: myapp-deployment
        spec:
          containers:
            - name: myapp-container
              image: nginx:latest
              ports:
                - containerPort: 80

    다음 명령을 사용하여 Deployment 를 생성합니다.

    kubectl apply -f myapp-deployment.yaml
  2. Deployment 를 설명합니다.

    kubectl describe deployment myapp-deployment

이 명령은 상태, 레이블, 주석, 이벤트 등을 포함하여 지정된 Deployment 에 대한 자세한 정보를 검색합니다.

Service 정보 확인 (kubectl describe)

이 단계에서는 describe 명령을 사용하여 Kubernetes Service 에 대한 정보를 보는 방법을 배우게 됩니다.

  1. 다음 내용으로 myapp-service.yaml이라는 파일을 생성합니다.

    apiVersion: v1
    kind: Service
    metadata:
      name: myapp-service
    spec:
      selector:
        app: myapp-deployment
      ports:
        - protocol: TCP
          port: 80
          targetPort: 80

    다음 명령을 사용하여 Service 를 생성합니다.

    kubectl apply -f myapp-service.yaml
  2. 다음 명령을 사용하여 Service 를 설명합니다.

    kubectl describe service myapp-service

이 명령은 상태, 레이블, 주석, 이벤트 등을 포함하여 지정된 Service 에 대한 자세한 정보를 검색합니다.

요약

이 랩에서는 Kubernetes describe 명령을 사용하여 Kubernetes 리소스에 대한 자세한 정보를 보는 방법을 배웠습니다. Pod, Deployment 및 Service 를 설명하는 방법을 배웠습니다.