Search

Commands

기본 명령어
kubectl get pods # Pod 목록 조회 kubectl get nodes # Node 목록 조회 kubectl get services # Service 목록 조회 kubectl get deployments # Deployment 목록 조회 kubectl describe pod [pod-name] # Pod 상세 정보 조회 kubectl logs [pod-name] # Pod 로그 조회 kubectl exec -it [pod-name] -- /bin/bash # Pod 내부 접속
Shell
복사
리소스 생성 및 관리
kubectl create -f [yaml-file] # YAML 파일로 리소스 생성 kubectl apply -f [yaml-file] # YAML 파일 적용 (생성 또는 업데이트) kubectl delete pod [pod-name] # Pod 삭제 kubectl delete -f [yaml-file] # YAML 파일에 정의된 리소스 삭제
Shell
복사
네임스페이스 관련
kubectl create namespace [name] # 네임스페이스 생성 kubectl get pods -n [namespace] # 특정 네임스페이스의 Pod 조회 kubectl config set-context --current --namespace=[name] # 기본 네임스페이스 변경
Shell
복사
스케일링
kubectl scale deployment [name] --replicas=3 # Deployment 스케일 조정 kubectl autoscale deployment [name] --min=2 --max=5 --cpu-percent=80 # HPA 설정
Shell
복사
파드 재시작
kubectl rollout restart deployment [deployment-name] # Deployment를 사용하는 경우 kubectl delete pod [pod-name] # 특정 파드만 직접 삭제하여 재시작 kubectl delete pods --all -n [namespace-name] # 특정 네임스페이스 모든 파드 재시작
Shell
복사
업데이트 및 롤백
kubectl set image deployment/[name] container=[new-image] # 이미지 업데이트 kubectl rollout status deployment/[name] # 롤아웃 상태 확인 kubectl rollout history deployment/[name] # 롤아웃 히스토리 조회 kubectl rollout undo deployment/[name] # 이전 버전으로 롤백
Shell
복사
모니터링 및 디버깅
kubectl top nodes # Node 리소스 사용량 조회 kubectl top pods # Pod 리소스 사용량 조회 kubectl logs -f [pod-name] # Pod 로그 실시간 조회 kubectl port-forward [pod-name] 8080:80 # 포트 포워딩
Shell
복사
ConfigMap 및 Secret
kubectl create configmap [name] --from-file=[path] # ConfigMap 생성 kubectl create secret generic [name] --from-literal=key=value # Secret 생성
Shell
복사
노드 관리
kubectl get nodes --show-labels # Node 라벨 조회 kubectl taint nodes [node-name] key=value:NoSchedule # Node에 taint 설정 kubectl cordon [node-name] # Node 스케줄링 비활성화 kubectl drain [node-name] # Node 드레인
Shell
복사
고급 디버깅
kubectl debug [pod-name] -it --image=busybox # 디버깅 컨테이너 실행 kubectl api-resources # 사용 가능한 API 리소스 조회 kubectl explain [resource] # 리소스 스펙 설명 kubectl get events --sort-by=.metadata.creationTimestamp # 이벤트 시간순 조회
Shell
복사
컨텍스트 및 클러스터 관리
kubectl config get-contexts # 사용 가능한 컨텍스트 조회 kubectl config use-context [context-name] # 컨텍스트 변경 kubectl config view # kubeconfig 설정 조회
Shell
복사
RBAC 관리
kubectl create role [name] --verb=get --resource=pods # Role 생성 kubectl create rolebinding [name] --role=[role-name] --user=[user-name] # RoleBinding 생성 kubectl auth can-i get pods # 권한 확인
Shell
복사
네트워킹
kubectl get ingress # Ingress 목록 조회 kubectl get networkpolicy # NetworkPolicy 목록 조회 kubectl get endpoints # Endpoint 목록 조회
Shell
복사