나의 잡다한 노트 및 메모

실무에서 알아야 할 kubectl 명령어 모음 본문

DevOps/쿠버네티스

실무에서 알아야 할 kubectl 명령어 모음

peanutwalnut 2025. 9. 15. 17:17

📌 1. 리소스 조회

 
kubectl get nodes # 노드 상태 확인 kubectl get pods -A # 모든 네임스페이스의 파드 조회 kubectl get pods -n <ns> -o wide # 파드 상세 (노드, IP 등 추가 정보) kubectl get svc -n <ns> # 서비스 확인 kubectl get all -n <ns> # 해당 네임스페이스의 모든 리소스

📌 2. 리소스 상세 확인 & 디버깅

 
kubectl describe pod <pod> -n <ns> # 파드 상세 이벤트/상태 확인 kubectl logs <pod> -n <ns> # 파드 로그 확인 kubectl logs <pod> -c <container> # 특정 컨테이너 로그 kubectl exec -it <pod> -n <ns> -- sh # 파드 안으로 들어가서 쉘 실행 kubectl top pod -n <ns> # 파드 CPU/메모리 사용량 kubectl top node # 노드 리소스 사용량

📌 3. 배포/업데이트

 
kubectl apply -f app.yaml # 선언적 배포 kubectl delete -f app.yaml # 리소스 삭제 kubectl set image deploy/myapp myapp=myimage:v2 -n <ns> # 이미지 롤링 업데이트 kubectl rollout status deploy/myapp -n <ns> # 배포 진행 상태 확인 kubectl rollout undo deploy/myapp -n <ns> # 이전 버전으로 롤백

📌 4. 네임스페이스 관리

 
kubectl get ns # 네임스페이스 목록 kubectl create ns dev # 네임스페이스 생성 kubectl config set-context --current --namespace=dev # 기본 ns 변경

📌 5. 노드/스케줄링 제어

 
kubectl cordon <node> # 노드에 새 파드 스케줄 금지 kubectl drain <node> --ignore-daemonsets --delete-emptydir-data # 파드 퇴거 kubectl uncordon <node> # 다시 스케줄 가능 kubectl taint nodes <node> key=value:NoSchedule # 노드에 taint 적용 kubectl taint nodes <node> key=value:NoSchedule- # taint 제거

📌 6. config/context 관리

 
kubectl config view --minify | grep name: # 현재 context 확인 kubectl config get-contexts # context 목록 kubectl config use-context <context> # context 전환 kubectl config set-context --current --namespace=<ns> # 기본 ns 설정

📌 7. 유용한 옵션

  • -o yaml : 리소스를 YAML 형태로 출력 → 다른 클러스터에 재적용 가능
    kubectl get pod <pod> -n <ns> -o yaml
  • -o jsonpath : 특정 값만 추출
    kubectl get pod <pod> -n <ns> -o jsonpath='{.status.podIP}'
  • -w : watch 모드 (변화 실시간 확인)
    kubectl get pods -n <ns> -w

 

 

'DevOps > 쿠버네티스' 카테고리의 다른 글

kind, apiVersion  (1) 2025.09.16
Pod를 생성할 때 내부 흐름  (0) 2025.09.15
DB를 k8s에서 쓰는게 좋은 생각인가?  (0) 2025.02.11
쿠버네티스 노드 관리  (1) 2024.11.17
[K8S] Multi container pods design patterns  (1) 2024.11.17