허쉬탱의 workspace

[쿠버네티스 초급] 01. 쿠버네티스 명령어 정리 본문

쿠버네티스/쿠버네티스 초급

[쿠버네티스 초급] 01. 쿠버네티스 명령어 정리

허쉬탱 2022. 7. 29. 15:32

[쿠버네티스 초급] 01. 쿠버네티스 명령어 정리

쿠버네티스 명령어를 정리합니다.

  • 조회
    • Pod 조회
    • 네임스페이스 dev에서 Pod 조회
    • 모든 네임스페이스에서 Pod 조회
    • 모든 라벨 조회
    • 특정 라벨을 가진 pod 조회
    • 조회 시 헤더 제거
    • 오브젝트 설명 문서 보기
  • 생성
    • Pod 생성
    • Pod 생성 및 커맨드 수행
    • Pod 생성하지 않고 YAML 파일만 생성
    • 서비스 생성
    • Deploy 생성 (replica=2)
  • 변경
    • replica 변경
    • Pod 에서 필드 수정

조회

Pod 조회 

kubectl get po

네임스페이스 dev에서 Pod 조회

kubectl get po -n dev

모든 네임스페이스에서 Pod 조회

kubectl get po -A

모든 라벨 조회

kubectl get po --show-labels

특정 라벨을 가진 pod 조회

kubectl get po -l env=prod,tier=frontend

조회 시 헤더 제거

kubectl get po --no-headers

오브젝트 설명 문서 보기 

kubectl explain po --recursive | less

생성 

Pod 생성 

kubectl run nginx --image=nginx --labels=tier=lb --port 8080

Pod 생성 및 커맨드 수행 

kubectl run busybox --image busybox --command sleep 1000

Pod 생성하지 않고 YAML 파일만 생성 

kubectl run nginx --image=nginx --dry-run=client -oyaml > nginx.yaml

서비스 생성 

kubectl expose pod redis --port=6379 --name redis-service
kubectl create svc clusterip redis --tcp=6379:6379

Deploy 생성 (replica=2) 

kubectl create deploy nginx --image=nginx --replicas=2

변경 

replica 변경 

kubectl scale deploy nginx --replicas=4

Pod 에서 필드 수정 

pod 는 edit 으로 수정 시 아래 항목만 수정 가능함

  • spec.containers[*].image
  • spec.initContainers[*].image
  • spec.activeDeadlineSeconds
  • spec.tolerations

따라서 이 방법보단 아래 방법으로 yaml 복제 후, 기존 pod는 삭제하고 yaml 파일 수정 후 재배포 하는 것이 좋음

kubectl get po -o yaml > new_pod.yaml
Comments