05-16 00:01
Recent Posts
Recent Comments
관리 메뉴

miinsun

[CKA] CKA 알아둬야 하는 명령어 본문

Infra/Kubernetes

[CKA] CKA 알아둬야 하는 명령어

miinsun 2023. 12. 4. 23:51

알아둬야 하는 명령어

$ kubectl explain replicaset

 

=> 리소스에대한 설명과 어떤 필드를 써야하는지 디테일을 알려줌

 

$ kubectl get pods --selector env=dev

=> 라벨로 궁금한 pods 만 검색

 

$ kubectl taint nodes controlplane node-role.kubernetes.io/control-plane:NoSchedule

=> taint 주기

 

$ kubectl taint nodes controlplane node-role.kubernetes.io/control-plane:NoSchedule-

=> taint 없애기

  • 여기서 taint는 노드에 관해, NoSchedule 제한을 주겠다는 것
  • taint를 무시하기 위해서는, pod에 tolerations 옵션을 줘야함

 

Drain

특정 노드에서 실행 중인 파드를 다른 노드로 이동시키고, 그 노드를 비활성화하여 새로운 파드가 스케줄링되지 않도록 합니다.

노드를 비활성화 함

$ kubectl drain <node-name>

 

UnCordon

비활성화한 노드를 다시 활성화하려면 kubectl uncordon 명령어를 사용할 수 있습니다

$ kubectl uncordon node-1

이렇게 하면 노드가 다시 스케줄링될 수 있게 되어 새로운 파드가 해당 노드에 스케줄링될 수 있습니다.

 

Label 붙이기

# Update pod 'foo' with the label 'unhealthy' and the value 'true'
$ kubectl label pods foo unhealthy=true

 

Static Pods 의 유무 확인하는 방법

$ kubectl get pods --all-namespaces

다음 명령어를 치고, 파드 이름 뒤에 ‘-controlplane’ 가 붙여있으면 static pods

 

명령어가 있는 Static Pods 한번에 생성하는 명령어

$ kubectl run --restart=Never --image=busybox static-busybox --dry-run=client -o yaml --command -- sleep 1000 > /etc/kubernetes/manifests/static-busybox.yaml

 

node01의 kubelet 설정파일 확인하는 방법

대체로 설정파일 위치는 --kubeconfig=/etc/kubernetes/kubelet.conf 에 있음

root@node01:~# ps -ef |  grep /usr/bin/kubelet 
root        4147       1  0 14:05 ?        00:00:00 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --pod-infra-container-image=registry.k8s.io/pause:3.9
root        4773    4733  0 14:05 pts/0    00:00:00 grep /usr/bin/kubelet

 

node01의 static pod 설정 위치 확인 하는 방법

kubelet의 설정파일에서 staticPodPath을 확인 가능하다.

root@node01:~# grep -i staticpod /var/lib/kubelet/config.yaml
staticPodPath: /etc/just-to-mess-with-you

 

Cluster 버전 확인하는 방법

$ kubectl get nodes
NAME           STATUS   ROLES           AGE   VERSION
controlplane   Ready    control-plane   96m   v1.26.0
node01         Ready    <none>          95m   v1.26.0
Comments