kubectl 명령어 정리

kubectl 명령어 정리

1. 클러스터 정보 확인

  • 클러스터 정보 출력

    kubectl cluster-info
    
  • 현재 컨텍스트 확인

    kubectl config current-context
    
  • 컨텍스트 목록 확인

    kubectl config get-contexts
    

2. 리소스 조회

  • 전체 네임스페이스에서 모든 파드 조회

    kubectl get pods --all-namespaces
    
  • 특정 네임스페이스에서 파드 조회

    kubectl get pods -n <namespace>
    
  • 디테일한 정보와 상태 출력

    kubectl describe pod <pod-name> -n <namespace>
    
  • 서비스 조회

    kubectl get svc
    
  • 노드 조회

    kubectl get nodes
    

3. 리소스 생성 및 삭제

  • 매니페스트 파일로 리소스 생성

    kubectl apply -f <file.yaml>
    
  • 리소스 삭제

    kubectl delete -f <file.yaml>
    
  • 특정 리소스 삭제

    kubectl delete pod <pod-name> -n <namespace>
    

4. 파드 조작

  • 파드 로그 확인

    kubectl logs <pod-name> -n <namespace>
    
  • 파드 내 컨테이너 쉘 접속

    kubectl exec -it <pod-name> -n <namespace> -- /bin/bash
    
  • 파드 상태 실시간 확인 (워치)

    kubectl get pods -w -n <namespace>
    

5. 배포(Deployment) 관련

  • 배포 상태 조회

    kubectl get deployments
    
  • 배포 롤아웃 상태 확인

    kubectl rollout status deployment/<deployment-name> -n <namespace>
    
  • 배포 롤백

    kubectl rollout undo deployment/<deployment-name> -n <namespace>
    
  • 배포 스케일 조정 (레플리카 수 변경)

    kubectl scale deployment/<deployment-name> --replicas=<num> -n <namespace>
    

6. 네임스페이스 관련

  • 네임스페이스 생성

    kubectl create namespace <namespace-name>
    
  • 네임스페이스 삭제

    kubectl delete namespace <namespace-name>
    
  • 네임스페이스 변경

    kubectl config set-context --current --namespace=<namespace-name>
    

7. 기타 유용한 옵션

  • YAML, JSON 출력

    kubectl get pods -o yaml
    kubectl get pods -o json
    
  • 리소스 레이블로 필터링

    kubectl get pods -l app=myapp
    
  • 특정 필드만 출력

    kubectl get pods -o custom-columns=NAME:.metadata.name,STATUS:.status.phase
    

댓글

이 블로그의 인기 게시물

PYTHONPATH, Python 모듈 환경설정

You can use Sublime Text from the command line by utilizing the subl command

git 명령어

[gRPC] server of Java and client of Typescript

[Ubuntu] Apache2.4.x 설치

Create topic on Kafka with partition count, 카프카 토픽 생성하기

리눅스의 부팅과정 (프로세스, 서비스 관리)

Auto-populate a calendar in an MUI (Material-UI) TextField component

The pierce selector in Puppeteer