컨테이너 오케스트레이션 시스템 세계에서 사실상 표준에 가까운 쿠버네티스 명령어에 대해 알아보고자 하며,
기본적인 형식은 아래와 같고, 상세 설명은 추후 업데이트 예정
kubectl [command] [type] [name] [flags]
● node 조회 (약어 no)
- kubectl get node *node를 조회하고 node가 사용할 수 있는 상태인지 확인
- kubectl get node --kubeconfig admin.conf *쿠버네티스 클러스터 정보를 입력받는 옵션(--kubeconfig)
- kubectl describe nodes {name} *클러스터 안 노드 레이블에 어떤 키-값이 있는지 확인
- kubectl get nodes --show-labels
● pod 조회 (약어 po)
아래는 pod 조회 명령어로 상황에 맞게 사용할 수 있다.
- kubectl get pods -o wide
- kubectl get pods -o wide -w *-w옵션은 오브젝트 상태에 변화가 감지되면 해당 결과를 출력
- kubectl get pods -n {namespace} *n은 namespace의 약어
- kubectl describe pods {name} -n {namespace}
- kubectl get pods --all -namespaces | grep {whatever}
- kubectl describe pods {pods name} *pod 생명 주기 등 상세 내용 확인
- kubectl get pods --v=7 *디버그용 내용을 출력
- kubectl get pods -l app={name} *-l 을 사용해서 원하는 필터를 추가도 가능
- kubectl get pods -o wide -l app={name}
- kubectl get pods -o wide -l service={name}
- kubectl get pods -l environment={name},release={name}
- kubectl get pods -l app!={name} *!=를 사용하여 특정 app name 이 아닌 경우만 조회도 가능하다.
- kubectl explain pods *pod 템플릿에서 사용 하는 하위 필드가 뭐가 있는지
- kubectl explain pods.metadata *pod 템플릿에서 사용 하는 하위 필드가 뭐가 있는지+data 타입이 object 인 경우
- kubectl explain pods --recursive *pod안에 속한 모든 필드를 보고 싶은 경우
● service 조회 (약어 : svc)
- kubectl get services (svc)
- kubectl get service -n {name}
- kubectl get svc -o wide
- kubectl describe service(svc) {name}
● namespace 조회 (약어 ns)
- kubectl get namespaces
● volume 조회
- kubectl get pv *퍼시스턴트 볼륨 확인 / pv는 볼륨을 사용할 수 있게 준비하는 단계
- kubectl get pvc *퍼시스턴트 볼륨 클레임 확인 / pvc는 준비된 볼륨에서 일정 공간을 할당받는 것
● secret 조회
- kubectl get secret {name} -o yaml
- kubectl describe secret {name}
● serviceaccount 조회 (약어 : sa)
- kubectl get serviceaccount
- kubectl get serviceaccount default -o yaml
● deployment 조회 (약어 : deploy)
- kubectl get deployments
- kubectl describe deploy {name}
- kubectl describe deploy -n {name}
● damonset 조회 (약어 : ds)
디플로이먼트의 replicas가 노드수 만큼 정해져 있는 형태이다. 노드를 관리하는 파드라면 데몬셋으로 만드는 것이 효율적이다. (파드가 1개 이상 필요하지 않을때)
- kunectl get daemonset -n {namespace}
- kubectl describe daemonset -n {name}
● ingress 조회 (약어 : ing)
ingress는 고유한 주소를 제공해 사용 목적에 따라 다른 응답을 제공할 수 있고, 트래픽에 대한 L4/L7 로드 밸런서 및 보안 인증 처리
- kubectl describe ingress {name}
● clusterrole 조회
- kubectl describe clusterrole {name} *특정 네임스페이스 사용 권한이 아닌 클러스터 전체 사용 권한을 관리
● configmap 조회 (약어 : cm)
configmap은 이름 그래도 config(설정)를 목적으로 사용하는 오브젝트이다.
- kubectl describe configmap {name:coredns} -n {namespace}
● HPA(Horizontal Pod Autoscaler) 확인
CPU 사용률 기반 auto scaling
- kubectl get hpa
- kubectl top node
- kubectl top pods
● log 확인
- kubectl get pods -n monitoring
- kubectl get pods -n monitoring -c {name}
- kubectl logs {name} -n monitoring -c
- kubectl get all -n monitoring
- kubectl logs -f {pod name}
● job 확인
- kubectl describe job {name}
● helm 확인 (쿠버네티스 템플릿 관리)
- helm repo list
- helm ls
● config 확인
- kubectl config current-context
- kubectl config get-contexts {current-context name}
- kubectl config get-contexts $(kubectl config current-context) --namespace={??}
- kubectl config get-clusters
● 다중 확인
- kubectl get replicaset,pods
- kubectl get deploy,rs,rc,pods *deploy는 디플로이먼트, rs는 레플리카세트, rc는 레플리케이션 컨트롤러, pods는 파드
- kubectl get service,statefulset,pods
- kubectl get cronjobs
● pod에 접속 등
- kubectl exec -it {pod name} -- bash
- kubectl exec -it {pod name} -- /bin/bash
- (접속후) systemctl stop/start kubelet *node에 접속해서 pod의 상태를 관리하는 kubelet 종료/시작
- (접속후) systemctl restart network *nw 재시작해서 pod의 통신을 담당하는 kube-proxy에 문제 상황을 만들 수 있음
- (접속후) ls -l /audit *새로 접속한 파드의 정보가 추가됐는지 log 확인 등
● deatil 조회 방법
- kubectl config view | grep "xx"
- kubectl -n default exec {name} -c {container name} -- ls /
- kubectl get nodes -o wide --no-headers | awk '{print $6}'
- kubectl get nodes -o json | ?? *JSON 지원시
● 기타 명령어
- kubectl api-resources *약어 확인
- kubectl api-versions *사용 가능 한 API 버전 확인
- kubectl completion bash *kubectl 자동 완성 기능 제공 (TAB)
- systemctl status kubelet.service
● 기타 생성/삭제 명령어
- kubectl run {name} --image="" --port=8080 *name이라는 이름의 파드를 생성
- kubectl expose po {name} --type=NodePort *name이라는 이름의 서비스를 생성
- kubectl delete pod {name}
- kubectl delete service {name}
● docker 명령어
docker ps *컨테이너 상태 확인
docker ps -f id={name}
docker images | head -n 4(number)
'기타 > 기타' 카테고리의 다른 글
구글 크롬 드라이버 자동 업데이트 금지 (0) | 2023.01.19 |
---|