
1.클러스터 상태 확인 명령어
노드 상태 확인
#클러스터 내 노드의 상태 및 역할 확인.
kubectl get nodes
출력 예시 :
NAME STATUS ROLES AGE VERSION
node-1 Ready control-plane 10d v1.27.0
node-2 Ready worker 8d v1.27.0
클러스터 정보 확인
#클러스터의 API 서버 및 DNS 정보 확인
kubectl cluster-info
2. 네임스페이스 관리
네임스페이스 목록확인
kubectl get namespaces
특정 네임스페이스에서 작업
kubectl get pods -n <namespace>
3. 리소스 조회
Pod 조회
kubectl get pods
kubectl get pods -o wide #추가 정보 포함
kubectl get pods -A #모든 네임스페이스의 Pod 조회
Deployment 조회
kubectl get deployments
Service 조회
kubectl get services
ConfigMap 또는 Secret 조회
kubectl get configmaps
kubectl get secrets
리소스의 상세 정보 조회
kubectl describe <resource-type> <resource-name>
4. 리소스 생성
리소스 적용
kubectl apply -f <file.yaml>
간단한 리소스 생성
kubectl run <pod-name> --image<image-name>
#예 : kubectl run nginx-pod --image=nginx
5. 리소스 수정
리소스 직접 수정
kubectl edit <resource-type> <resource-name>
리소스 재배포
kubectl rollout restart deployment <deployment-name>
6. 리소스 삭제
리소스 삭제
kubectl delete <resource-type> <resource-name>
YAML 파일로 리소스 삭제
kubectl delete -f <file.yaml>
모든 리소스 삭제
#현재 네임스페이스의 모든 리소스 삭제
kubectl delete all --all
7. 로그 및 디버깅
Pod 로그 확인
kubectl logs <pod-name>
kubectl logs <pod-name> -c <container-name> #특정 컨테이너 로그
Pod 상태 확인
kubectl describe pod <pod-name>
Pod에 접속
kubectl exec -it <pod-name> -- /bin/bash
8. 리소스 이벤트 확인
리소스의 최근 이벤트
kubectl get events
Pod 또는 다른 리소스의 상세 이벤트
kubectl describe pod <pod-name>
9. YAML 템플릿 생성
리소스 YAML 템플릿 생성
kubectl create deployment <deployment-name> --image=<image-name> --dry-run=client -o yaml
10. 버전 및 설정 확인
클러스터와 클라이언트 버전 확인
kubectl version --short
현재 컨텍스트 확인
kubectl config current-context
컨텍스트 목록 확인
kubectl config get-contexts