kubernetes

[따배쿠] kubectl command

bbiyak2da 2024. 11. 9. 16:00

kubectl command

** kubectl [명령] [오브젝트]

- kubectl get nodes : 노드 정보 불러오기

- kubectl get nodes -o wide : 노드 정보 자세히 불러오기

- kubectl describe [노드이름] :  노드 정보 더 자세히 불러오기

 

- kubectl get pod : pod 정보 불러오기

- kubectl get pod -o wide : pod 정보 자세히 불러오기

- kubectl exec [파드이름] -it -- /bin/bash : pod에 접속

- kubectl port-forward [파드이름] [포트]:[포트] : pod 포트 포워딩

 

- kubectl create deployment [이름] --image=[이미지] : deployment 생성

kubectl create deployment mainui --image=httpd:latest --replicas=3

 

- kubectl get deployments : deployment 정보 확인

root@master:~# kubectl get deployments
NAME     READY   UP-TO-DATE   AVAILABLE   AGE
mainui   3/3     3            3           53m

 

- kubectl edit deployments [deployments 이름] : 현재 동작중인 pod를 수정하고 싶을 때,, 사용 !! vi editor와 연결됨

kubectl edit deployments mainui

 

- kubectl run [pod 이름] [이미지] [포트] --dry-run : 이미 존재하는 pod의 실행 상태를 확인하고 싶을 때 --dry-run 옵션 

kubectl run webserver --image=ngix:1.14 --port 80 --dry-run

 


- kubectl run [pod 이름] [이미지] [포트] --dry-run -o yaml : 이미 존재하는 pod의 yaml 파일을 확인하고 싶을 때

root@master:~# kubectl run webserver --image=ngix:1.14 --port 80 --dry-run -o yaml
W1109 06:39:31.033697   34258 helpers.go:703] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: webserver
  name: webserver
spec:
  containers:
  - image: ngix:1.14
    name: webserver
    ports:
    - containerPort: 80
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

 

- kubectl run [pod 이름] [이미지] [포트] --dry-run -o yaml > [yaml 이름].yaml : 해당 pod의 yaml 파일을 로컬에 옮겨오고 싶을 때

root@master:~# kubectl run webserver --image=ngix:1.14 --port 80 --dry-run -o yaml > webserver-pod.yaml
W1109 06:46:03.336627   36319 helpers.go:703] --dry-run is deprecated and can be replaced with --dry-run=client.
root@master:~# ls
webserver-pod.yaml

 

- kubectl create -f [yaml 파일] : yaml 파일로 pod 생성

root@master:~# kubectl create -f webserver-pod.yaml
pod/webserver created

 

- kubectl delete [리소스 타입] [리소스 이름] : 리소스 삭제

root@master:~# kubectl delete pod webserver
pod "webserver" deleted

 

- kubectl explain [리소스 타입] : 리소스 정보 설명

root@master:~# kubectl explain pod

 

결론) run과 create 차이

 

pod 생성 방법에는 run, create가 있다.

  • run으로 pod를 생성하면 단일 파드 1개만 생성되고 관리된다.
  • create 명령어로 yaml 파일을 통해 pod를 생성할 수도 있다.
  • create 명령어로 단일 파드뿐만 아니라, deployment(관리 그룹)을 통해 복수 파드를 생성 할 수 있다.

기타

- history : 리눅스 명령어 히스토리