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
    

댓글

이 블로그의 인기 게시물

Using the MinIO API via curl

Install and run an FTP server using Docker

PYTHONPATH, Python 모듈 환경설정

Elasticsearch Ingest API

How to checkout branch of remote git, 깃 리모트 브랜치 체크아웃

Fundamentals of English Grammar #1

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

How to start computer vision ai

Catch multiple exceptions in Python

git 명령어