kubernetes

[따배쿠] Pod - static Pod(feat. kubelet daemon)

bbiyak2da 2024. 12. 2. 15:43

static pod

  • API 서버의 도움 없이, 특정 노드에 있는 kubelet 데몬에 의해 직접 Pod 실행
    • 보통 pod 생성하기 위해 kubectl run ~ 명령어를 master node(control plane)의 REST API server에 전달하고, Master node의 REST API server가 Scheduler에게 어떤 노드에 컨테이너를 실행하면 좋을지 질문하고, 응답 받는다.
      • REST API server은 scheduler로 부터 응답받은 최적 노드의 kubelet에게 요청을 전달한다. ex) 최적 노드가 node1일 경우 node1의 kubelet
    • 하지만 stactic pod는 이러한 과정을 거치지 않고, 특정 노드에 있는 kubelet 데몬에 의해 작동된다.
  • /etc/kubernetes/manifests/ 디렉터리(static pod 디렉터리)k8s yaml 파일 저장 시 적용
    • 해당 디렉터리에 yaml 파일 저장 시, 즉시 pod 배포
    • 해당 디렉터리에 yaml 파일 삭제 시, 즉시 pod 삭제 
    • 보통 stactic pod 경로는 /etc/kubernetes/manifests/ 이지만, 경로를 확인할 수 없는 경/var/lib/kubelet/config.yaml 내 staticPodPath 값에서 확인 가능
  • 즉, 내가 원하는 node에 pod를 배포하기 위해 사용

 

예시

 

[node2]

 

# kubelet 데몬의 config 구성 파일 확인

root@node2:~# cat /var/lib/kubelet/config.yaml

apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
  anonymous:
    enabled: false
  webhook:
    cacheTTL: 0s
    enabled: true
  x509:
    clientCAFile: /etc/kubernetes/pki/ca.crt
authorization:
  mode: Webhook
  webhook:
    cacheAuthorizedTTL: 0s
    cacheUnauthorizedTTL: 0s
cgroupDriver: systemd
clusterDNS:
- 10.96.0.10
clusterDomain: cluster.local
containerRuntimeEndpoint: ""
cpuManagerReconcilePeriod: 0s
evictionPressureTransitionPeriod: 0s
fileCheckFrequency: 0s
healthzBindAddress: 127.0.0.1
healthzPort: 10248
httpCheckFrequency: 0s
imageMaximumGCAge: 0s
imageMinimumGCAge: 0s
kind: KubeletConfiguration
logging:
  flushFrequency: 0
  options:
    json:
      infoBufferSize: "0"
    text:
      infoBufferSize: "0"
  verbosity: 0
memorySwap: {}
nodeStatusReportFrequency: 0s
nodeStatusUpdateFrequency: 0s
resolvConf: /run/systemd/resolve/resolv.conf
rotateCertificates: true
runtimeRequestTimeout: 0s
shutdownGracePeriod: 0s
shutdownGracePeriodCriticalPods: 0s
staticPodPath: /etc/kubernetes/manifests
streamingConnectionIdleTimeout: 0s
syncFrequency: 0s
volumeStatsAggPeriod: 0s

 

static pod path가 /etc/kubernetes/manifests인 것을 확인 가능

 

# /etc/kubernetes/manifests에서 nginx.yaml 파일 생성

root@node2:~# cd /etc/kubernetes/manifests
root@node2:/etc/kubernetes/manifests# vi nginx.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
  - name: nginx-container
    image: nginx:1.14
    ports:
    - containerPort: 80
      protocol: TCP

 

[master]

 

# pod 확인

root@master:~# kubectl get pods -o wide
NAME              READY   STATUS    RESTARTS   AGE   IP               NODE    NOMINATED NODE   READINESS GATES
nginx-pod-node2   1/1     Running   0          73s   192.168.104.22   node2   <none>           <none>

 

master 서버에서 pod 확인 시, node2에 nginx-pod라는 이름의 pod가 생성된 것을 확인할 수 있다.

 

이렇게 특정 노드의 static pod path에서 yaml 파일을 저장 하는 순간,

해당 노드에서 자동으로 pod가 배포되는 것을 확인 가능 !!

 

완전 신기하담 ㅎㅎ

 

yaml파일 삭제 시 pod가 자동 삭제 되는지도 확인해보자 ~!

 

[node2]

 

# nginx.yaml 파일 삭제

root@node2:/etc/kubernetes/manifests# rm nginx.yaml

 

[master]

 

# pod 확인

root@master:~# kubectl get pods -o wide
No resources found in default namespace.

 

배포된 pod가 삭제된 것을 확인할 수 있다 !!

 

번외)

root@master:~# cd /etc/kubernetes/manifests
root@master:/etc/kubernetes/manifests# ls
etcd.yaml  kube-apiserver.yaml  kube-controller-manager.yaml  kube-scheduler.yaml

 

master 서버에서 /etc/kubernetes/manifests 디렉터리를 확인해보면,

etcd / api server / controller / scheduler 구성 yaml 파일이 존재한다.

 

아 그래서 해당 기능들이 master에서 자동으로 실행됐던구나 ~ 라고 확인 가능 !!

해당 기능들은 master 서버에서 static pod 형태로 실행되고 있는 것이다!


참고 영상

https://www.youtube.com/watch?v=qEu_znIYCz0&list=PLApuRlvrZKohaBHvXAOhUD-RxD0uQ3z0c&index=14