본문 바로가기
IT/Docker.K8S

K8S 기본 명령어 모음(kubectl 옵션)

by 성준하이 2024. 5. 2.
반응형
Get
# default namespace의 pod조회 
$ kubectl get pods

# 모든 namespace의 pod조회
$ kubectl get pods --all-namespaces

# pod 정보 자세히 보기 
$ kubectl get pod -o wide

# pod watch mode로 보기 
$ kubectl get pod -w

# default namespace의 deployment조회
$ kubectl get deploy

# 모든 namespace의 모든 deployment조회
$ kubectl get deploy --all-namespaces

# default namespace의 service조회
$ kubectl get service
$ kubectl get svc

# 모든 namespace의 모든 service조회
$ kubectl get service --all-namespaces
$ kubectl get svc --all-namespaces

#node 조회
$ kubectl get node
Create
# test.yaml파일 작성 후 create하면 yaml파일의 내용이 생성
$ kubectl create -f test.yaml 

# yaml파일의 문법이 맞는지 확인하기 
$ kubectl create -f test.yaml --dry-run=client

# 명령어로 create 후 yaml 파일로 만들기
$ kubectl create deploy test-deploy --image=nginx --dry-run=client -o yaml > nginx.yaml
Delete
#test.yaml 파일로 생성된 내용 삭제
$ kubectl delete -f test.yaml

# 모든 자원 삭제 
$ kubectl delete all --all

# 원하는 파드만 삭제 
$ kubectl get pod
$ kubectl delete {pod이름}
Describe
# node 정보
$ kubectl get nodes
$ kubectl describe nodes {node이름}

# pod 정보
$ kubectl get pods
$ kubectl describe pod {pod이름}
Exec
# Pod에 bash로 들어가기
$ kubectl get pods
$ kubectl exec -it {pod이름} /bin/bash

# 특정 Pod에서 curl 실행하기
$ kubectl get pods
$ kubectl exec {pod이름} -- curl localhost:8080
Log
# 특정 pod의 로그 확인
$ kubectl get pods
$ kubectl logs {pod이름}

# 특정 pod의 로그 tail 
$ kubectl get pods
$ kubectl logs -f {pod이름}

 

반응형

댓글