Chapter01/Kubernetes

[ Kubernetes ] 자주 쓰는 명령어

EmmaDev_v 2025. 2. 25. 11:02

 

1. kubectl get: 리소스 조회

  • 전체 파드 목록 조회:
     
    kubectl get pods
     
     
  • 특정 네임스페이스에서 파드 조회:
     
    kubectl get pods -n <namespace>
     
     
  • 전체 서비스 목록 조회:
     
    kubectl get svc
     
     
  • 특정 네임스페이스에서 서비스 조회:
     
    kubectl get svc -n <namespace>
     
     
  • 전체 디플로이먼트 조회:
     
    kubectl get deployments
     
     

2. kubectl describe: 리소스 상세 정보 조회

  • 파드 상세 정보 조회:
     
    kubectl describe pod <pod_name>
     
     
  • 디플로이먼트 상세 정보 조회:
     
    kubectl describe deployment <deployment_name>
     
     

3. kubectl logs: 파드 로그 조회

  • 특정 파드의 로그 조회:
     
    kubectl logs <pod_name>
     
     
  • 다중 컨테이너 파드에서 로그 조회:
     
    kubectl logs <pod_name> -c <container_name>
     
     

4. kubectl exec: 파드 내에서 명령 실행

  • 파드 내에서 명령어 실행:
     
    kubectl exec -it <pod_name> -- <command>
     
     
    예를 들어, 파드 내에서 bash 쉘 실행:
     
    kubectl exec -it <pod_name> -- /bin/bash

5. kubectl apply: 리소스 배포/수정

  • YAML 파일을 이용한 리소스 배포:
     
    kubectl apply -f <file_name>.yaml
     
     
  • 디플로이먼트 업데이트:
     
    kubectl apply -f <deployment_file>.yaml
     
     

6. kubectl delete: 리소스 삭제

  • 특정 파드 삭제:
     
    kubectl delete pod <pod_name>
     
     
  • 디플로이먼트 삭제:
     
    kubectl delete deployment <deployment_name>
     
     

7. kubectl create: 리소스 생성

  • 파드 생성:
     
    kubectl create -f <pod_file>.yaml
     
     
  • 서비스 생성:
     
    kubectl create -f <service_file>.yaml
     
     

8. kubectl scale: 리소스 스케일링

  • 디플로이먼트의 파드 수 조정:
     
    kubectl scale deployment <deployment_name> --replicas=<number_of_replicas>
     
     

9. kubectl get nodes: 노드 조회

  • 전체 노드 목록 조회:
     
    kubectl get nodes
     
     

10. kubectl port-forward: 로컬에서 포트 포워딩

  • 로컬에서 파드의 포트에 접속하기:
     
    kubectl port-forward pod/<pod_name> <local_port>:<pod_port>
     
     

11. kubectl top: 리소스 사용량 조회

  • 클러스터 노드의 리소스 사용량 조회:
     
    kubectl top nodes
     
     
  • 파드의 리소스 사용량 조회:
     
    kubectl top pods
     
     

12. kubectl config: 설정 관리

  • 현재 사용 중인 컨텍스트 확인:
     
    kubectl config current-context
     
     
  • 새로운 컨텍스트 설정:
     
    kubectl config use-context <context_name>
반응형