Kubernetes 명령어 정리

artp·2025년 1월 3일

kubernetes

목록 보기
5/18
post-thumbnail

Kubernetes 명령어 정리

Pod 명령어

Pod 조회

현재 클러스터에 생성된 Pod 목록을 조회합니다.

$ kubectl get pods

Pod 포트 포워딩

로컬 머신에서 특정 포트를 Pod 내부 포트로 연결합니다.

# kubectl port-forward pod/[파드명] [로컬 포트]:[Pod 포트]
$ kubectl port-forward pod/nginx-pod 80:80

Pod 삭제

특정 Pod를 삭제합니다.

# kubectl delete pod [파드명]
$ kubectl delete pod nginx-pod

Pod 디버깅

Pod 세부 정보 조회

Pod의 상세 정보를 확인합니다.

# kubectl describe pods [파드명]
$ kubectl describe pods nginx-pod

Pod 로그 확인

Pod 내부 애플리케이션에서 출력한 로그를 확인합니다.

# kubectl logs [파드명]
$ kubectl logs nginx-pod

Pod 내부 접속

Pod 내부에 접속하여 상태를 점검하거나 명령을 실행합니다.

# bash 쉘로 접속
$ kubectl exec -it nginx-pod -- bash

# sh 쉘로 접속 (bash가 없는 경우)
$ kubectl exec -it nginx-pod -- sh

매니페스트 파일 기반 리소스 생성

매니페스트 파일에 정의된 리소스를 생성합니다.

# kubectl apply -f [파일명]
$ kubectl apply -f nginx-pod.yaml

Deployment 명령어

Deployment 조회

현재 클러스터에 생성된 Deployment 목록을 조회합니다.

$ kubectl get deployment

Deployment 삭제

특정 Deployment를 삭제합니다.

# kubectl delete deployment [디플로이먼트명]
$ kubectl delete deployment spring-deployment

Service 명령어

Service 조회

현재 클러스터에 생성된 Service 목록을 조회합니다.

$ kubectl get service

Service 삭제

특정 Service를 삭제합니다.

# kubectl delete service [서비스명]
$ kubectl delete service spring-service

공통 명령어

매니페스트 파일에 적힌 리소스 생성

매니페스트 파일에 정의된 리소스(파드, 디플로이먼트, 서비스 등)를 생성합니다.

# kubectl apply -f [파일명]
$ kubectl apply -f nginx-pod.yaml

모든 리소스 삭제

클러스터 내 모든 리소스를 삭제합니다.

$ kubectl delete all --all
profile
donggyun_ee

0개의 댓글