개발/기타
[kubernetes] k8s kubectl 명령어 정리
wwwnghks
2024. 7. 18. 15:56
Kubernetes 명령어 정리
버전 정보
kubectl version
리소스 및 서비스, 등 yaml 파일 적용
kubectl apply -f
deployment, service, pod 조회
kubectl get deployments -o wide
kubectl get services -o wide
kubectl get pods -o wide
-o wide 는 생략해도 된다. 더 많은 정보를 보기 위해 옵션으로 사용 가능.
약어로 전체적으로 간략하게 확인하려면 아래 명령어도 사용가능.
kubectl get deploy,svc,pods
pod 접속
kubectl exec -it 파드명 /bin/bash
예시
kubectl exec -it test-ubuntu-deployment-5554899f76-z77md /bin/bash
pod 로그 확인
kubectl logs -f 파드명
예시
kubectl logs -f test-ubuntu-deployment-5554899f76-z77md
-f 는 빼도 된다. 로그 파일의 마지막 부분을 지속적으로 모니터링하는 데 사용됩니다.
pod 재시작
kubectl delete pod 파드명
예시
kubectl delete pod test-ubuntu-deployment-5554899f76-z77md
기본적으로 파드를 삭제하면, 다시 재생성하기 때문에 재시작된다.
kubectl rollout restart 등으로도 사용한다.