*명령어구조
kubectl [command] [TYPE] [NAME] [flags]
[command]:자원에 실행할 명령(create, get, delete, edit…)
[TYPE]: 자원의 타입(node, pod, service…)
[NAME]: 자원의 이름
[flags]: 부가적으로 설정할 옵션(--help, -o options…)
ex) kubectl get pod webserver -o wide
*kubectl command 형식
kubectl --help
kubectl command --help
kubectl run <자원이름> <옵션>
kubectl create -f obj.yaml
kubectl apply -f obj.yaml
kubectl get <자원이름> <객체이름>
kubectl edit <자원이름> <객체이름>
kubectl describe <자원이름> <객체이름>
kubectl command EXAMPLE
kubectl api-resources
=>약어 정보 출력
kubectl get pods
=>파드 정보 확인
kubectl get nodes
=>노드 정보 확인
kubectl get nodes -o wide
=>노드정보 자세히 확인
kubectl describe node master.example.com
=>master노드의 상세정보 확인
kubectl command EXAMPLE2
kubectl run webserver --image=nginx:1.14 --port 80
=>webserver라는 컨테이너 생성(컨테이너를 1개만 생성할때 run명령어 사용)
kubectl create deployment mainui --image=httpd --replicas=3
=>mainui라는 디플로이먼트 3개 생성.(컨테이너 한번에 여러개 생성할때 create deployment 명령어 사용)
kubectl describe pod webserver
=>webserver라는 파드정보를 상세히 출력
kubectl get pods -o wide
=>파드정보 자세히 출력
kubectl get pods webserver
=>webserver파드의 정보만 출력
kubectl get deployments.apps
=>deployment정보 출력
kubectl describe deployments.apps main
=>mainui라는 디플로이먼트의 정보를 자세히 출력
kubectl get pod webserver -o yaml
=>webserver파드를 yaml형식으로 출력.
kubectl get pod webserver -o json
=>webserver파드를 json형식으로 출력.
kubectl command EXAMPLE3
kubectl exec webserver -it -- /bin/bash
=>webserver파드 내부로 접속
kubectl logs webserver
=>webserver파드의 로그 출력
kubectl port-forward webserver 8080:80
=>webserver의 80포트를 마스터노드의 8080포트로 포트포워딩
(외부에서 마스터노드:8080 접속시 webserver:80으로 포트포워딩 되어 웹페이지가 정상적으로 화면에 표시됨)
kubectl edit deployment.apps main
=>mainui라는 디플로이먼트를 수정할 수 있게 vi에디터 실행됨.
(replicas를 바꿔주고 :wq로 나오면 mainui의 개수가 변함)
kubectl command EXAMPLE4
kubectl run webserver --image=nginx:1.14 --port 80 --dry-run
=>webserver라는 파드를 드라이런 함(실행할 수 있는지 없는지 체크만 함)
kubectl run webserver --image=nginx:1.14 --port 80 --dry-run -o yaml
=>webserver파드를 yaml파일 형식으로 출력
kubectl run webserver --image=nginx:1.14 --port 80 --dry-run -o yaml > webserver.yaml
=>webserver yaml파일 생성
kubectl delete pod webserver
=>webserver파드 삭제
kubectl create -f webserver.yaml
=>yaml에 저장된 내용을 토대로 webserver파드 생성
'Kubernetes' 카테고리의 다른 글
H/W resource 관리 (0) | 2022.01.07 |
---|---|
livenessProbe (0) | 2022.01.07 |
Kubernetes namespace (0) | 2022.01.05 |
Kubernetes Component (0) | 2022.01.05 |
kubernetes 구성 (0) | 2021.12.03 |