Chat Conversation
참여자: User, QueryPie
Message 1 from User
User
Kubernetes(K8s) 기본 명령어
Message 2 from QueryPie
QueryPie
Kubernetes(K8s)는 컨테이너 오케스트레이션 플랫폼으로, kubectl CLI 도구를 통해 클러스터를 관리합니다. 다음은 가장 자주 사용되는 기본 명령어들을 카테고리별로 정리했습니다.
클러스터 정보 확인
클러스터 상태 확인
kubectl cluster-info
kubectl get nodes
kubectl get nodes -o wide
kubectl describe node <node-name>
네임스페이스 관리
kubectl get namespaces
kubectl create namespace <namespace-name>
kubectl delete namespace <namespace-name>
리소스 조회 및 관리
Pod 관리
kubectl get pods
kubectl get pods -n <namespace>
kubectl get pods -o wide
kubectl describe pod <pod-name>
kubectl logs <pod-name>
kubectl logs -f <pod-name> # 실시간 로그
kubectl exec -it <pod-name> -- /bin/bash
kubectl delete pod <pod-name>
Deployment 관리
kubectl get deployments
kubectl create deployment <name> --image=<image>
kubectl describe deployment <deployment-name>
kubectl scale deployment <deployment-name> --replicas=3
kubectl delete deployment <deployment-name>
Service 관리
kubectl get services
kubectl get svc # 축약형
kubectl expose deployment <deployment-name> --port=80 --target-port=8080
kubectl describe service <service-name>
kubectl delete service <service-name>
YAML 파일 기반 관리
리소스 생성 및 적용
kubectl apply -f <file.yaml>
kubectl apply -f <directory>/
kubectl create -f <file.yaml>
kubectl replace -f <file.yaml>
kubectl delete -f <file.yaml>
리소스 내보내기
kubectl get deployment <name> -o yaml
kubectl get pod <name> -o json
kubectl get service <name> -o yaml --export
디버깅 및 모니터링
리소스 상태 확인
kubectl get all
kubectl get events
kubectl get events --sort-by=.metadata.creationTimestamp
kubectl top nodes
kubectl top pods
포트 포워딩
kubectl port-forward pod/<pod-name> 8080:80
kubectl port-forward service/<service-name> 8080:80
설정 및 컨텍스트
컨텍스트 관리
kubectl config get-contexts
kubectl config current-context
kubectl config use-context <context-name>
kubectl config set-context <context-name> --namespace=<namespace>
설정 정보
kubectl config view
kubectl config get-clusters
유용한 옵션들
출력 형식
-o wide: 추가 정보 표시-o yaml: YAML 형식으로 출력-o json: JSON 형식으로 출력--watch또는-w: 실시간 변경사항 모니터링
필터링
--selector key=value: 라벨 선택자로 필터링--field-selector: 필드 선택자로 필터링-n <namespace>: 특정 네임스페이스 지정
도움말
kubectl --help
kubectl <command> --help
kubectl explain <resource>
이러한 명령어들을 조합하면 Kubernetes 클러스터의 대부분의 일상적인 관리 작업을 수행할 수 있습니다. 처음에는 기본적인 get, describe, logs 명령어부터 익숙해진 후 점차 고급 기능들을 활용해보시기 바랍니다.