기타

쿠버네티스(Kubernetes) #2

오늘보다 더 나은 내일을 위해 2021. 11. 24. 15:25

1. 쿠버네티스 명령 도구 마스터



kubectl run mynginx --image nginx --restart Never

#             pod 이름   어떤 이미지 쓸건지           

# docker run과 비슷

 

kubectl get pod mynginx

# 잘 실행되고 있는지 확인

 

kubectl get pod mynginx -o yaml 

#     상세한 앱 정의서 확인

 

kubectl describe pod mynginx

# pod 자체의 세부 정보를 볼 수 있음 

# 위의 명령어와 비슷하지만 이벤트 정보를 추가적으로 확인 할 수 있음



kubectl exec mynginx -- apt update 

# mynginx라는 pod에 명령(apt update)를 내림

# docker exec와 비슷

 

kubectl exec mynginx -- apt install -y curl

 

kubectl exec mynginx -- curl localhost

# mynginx라는 pod안에 있는 nginx 호출

curl localhost

# 리눅스 서버 안의 nginx 호출

 

kubectl logs mynginx

# mynginx의 로그 확인

 

kubectl cp ~/.bashrc mynginx:/. 

# 현재 서버에 있는 .bashrc 파일을 mynginx root 밑으로 복수

# docker cp와 유사

 

kubectl exec mynginx -- cat /.bashrc 

# mynginx에 .bashrc파일이 있는지 확인

 

kubectl edit pod mynginx

 

kubectl delete pod mynginx



kubectl get pod --namespace kube-system # -n kube-system



kubectl label node master color=red 



kubectl get node master -oyaml | grep -A 18 labels





2.
명령어 팁

 

• 모든 것이 다 리소스

 

kubectl get <RESOURCE>

 

kubectl get namespace 

kubectl get node 

kubectl get pod



• 모든 리소스 리스트

kubectl api-resources 



• 특정 field값 추출 

kubectl get pod mynginx -o jsonpath="{ .spec.containers[0].image }"




• 자동완성 

echo "source <(kubectl completion bash)" >> ~/.bashrc 



• 사용자 인증 파일 

kubectl config view 

vim ~/.kube/config 

apiVersion: v1
kind: Config 
clusters: 
  - cluster:
        certificate-authority-data:
        server: https://127.0.0.1:6443
  name: default 
users:
  - name: default
    user:
        password: fcb41891d94b1a362cf7ccc4086c2465
        username: admin
contexts:
 - context:
        cluster: default
        user: default
    name: default
current-context: default 

• 클러스터 상태 체크 

kubectl cluster-info 



• 치트시트 

https://kubernetes.io/ko/docs/reference/kubectl/cheatsheet/