Amazon Web Service (AWS)/EKS

[EKS] Kubernetes 기본 명령어

Ssemi-Column 2022. 8. 1. 17:54
728x90

1. help : kubernetes 기본 명령어를 알려주는 명령어

kubectl --help


2. get : 무엇의 정보를 보고 싶을 때 사용하는 명령어

2-1 nodes : 노드의 정보를 보여준다.

kubectl get nodes

2-2 pods : 파드의 정보를 보여준다.

kubectl get pods

pod 값이 있다면 이렇게 표시된다.

2-3 -o wide : 정보를 더 자세하게 보여준다.

kubectl get pods -o wide

2-4 -o yaml : 정보를 yaml 파일로 보여준다.

kubectl get pod webserver -o yaml // pods 대신 pod를 쓰고 파드이름을 붙여 한개의 파드 정보만 확인 할 수 있다.


3. descride : 아주 자세한 정보를 보여준다.

kube describe node ip-192-168-1-159.ap-northeast-2.compute.internal


4. Run : 이미지를 다운받아 pod를 실행하는 명령어

kubectl run webserver --image=nginx --port 80
// 이미지를 실행하는데 다운받을 이미지 이름은 nginx이고 포트는 80번 이름은 webserver로 표시한다

 


5. delete --grace-period=0 --force : pods를 강제로 삭제하는 명령어

kubectl delete pod webserver --grace-period=0 --force


6. create deployment : run 처럼 실행되는데 1개가 아닌 여러개를 동시에 실행 시킬 수 있다.

kubectl create deployment webserver --image=nginx:1.14 --port=80 --replicas=5
// 이미지 nginx 1.14버전을 다운받아 포트를 80번, 이름을 webserver로 하여 5개를 만든다

NODE 컬럼을 보면 kubectl get nodes에 있는 데이터 3개를 사용한다.

6-1 deploy 단위로 정보를 확인 할 때

kubectl get deployments.apps

* -o wide , -o yaml 로 자세하게 볼 수 있다.


7. expose : 외부에서 접속 할 수 있게 설정하는 명령어

$ kubectl expose deployment webserver --port=80 --type=LoadBalancer
$ kubectl get services

* af2d6adf28e324cc380a94c11277a5f0-1651230088.ap-northeast-2.elb.amazonaws.com 주소로 접속하면 nginx에 접속 할 수 있다.


8. exec : 지정한 pod의 내부로 들어가는 명령어

kubectl exec webserver-67db49c9d4-qtwsx -it -- /bin/bash
//pod 단위로만 가능하기 때문에 'pod' 명령어를 빼도 된다.


9. edit : 동작 중인 리소들을 수정하는 명령어 (vi로 연결)

kubectl edit deployments.apps webserver

*spec.replicas의 값을 5에서 3으로 변경 후 저장


10. run --image --dry-run -o yaml : 실행하지 않고, 실행 할 수 있는 상태를 확인하는 명령어

kubectl run webserver --image=nginx:1.14 --port 80 --dry-run -o yaml

10-1 > : > 명령어를 사용하여 Kubernetes가 사용하는 이미지 정보를 yaml 파일로 다운로드 가능

kubectl run webserver --image=nginx:1.14 --port 80 --dry-run -o yaml > webserver-pod.yaml

실행후 수정


11 create -f : image 대신 작성했었던 쿠버네티스 yaml 파일을 가지고 pod를 생성하는 명령어

kubectl create -f webserver-pod.yaml

 

728x90
반응형
LIST