본문 바로가기

Container/Kubernetes

[K8S] pause container / Static container

# Pause container

Infra(pause) container : In a Kubernetes Pod, an infrastructure or “pause” container is first created to host the container. 

  • pod에 대한 infra(IP, hostname 등,.)을 관리 및 생성해주는 컨테이너
  • infra를 만들어주지만, 어떤 작업을 수행하지는 않는다.

# Static container

기존의 Pod 생성은 'kubectl run ~'을  API server에 전달하면, etcd 정보를 가져다가 scheduler에게 보내주고 가장 적절한 노드를 선택해서 API에게 응답하면, API가 해당 Pod를 실행해주는 구조였다.

 

Static Pod는 API에게 요청을 보내지 않는다.

kubelet 데몬이 관리하는 static pod directory에 yaml파일을 저장하면 알아서 컨테이너가 실행된다.

즉, kubelet demon에 의해 동작되는 Pod를 static pod라고 부른다.

  •  API 서버 없이 특정 노드에 있는 kubelet 데몬에 의해 직접 관리
  • /etc/kubernetes/manifests/ 디렉토리에 k8s yaml 파일을 저장 시 적용됨. (위치가 다를 수도 있음)
[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
imageMinimumGCAge: 0s
kind: KubeletConfiguration
logging:
  flushFrequency: 0
  options:
    json:
      infoBufferSize: "0"
  verbosity: 0
memorySwap: {}
nodeStatusReportFrequency: 0s
nodeStatusUpdateFrequency: 0s
rotateCertificates: true
runtimeRequestTimeout: 0s
shutdownGracePeriod: 0s
shutdownGracePeriodCriticalPods: 0s
staticPodPath: /etc/kubernetes/manifests # 참고 (변경 가능)
streamingConnectionIdleTimeout: 0s
syncFrequency: 0s
volumeStatsAggPeriod: 0s

[node2 manifests]$ pwd
/etc/kubernetes/manifests
[node2 manifests]$ cat > nginx.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
  - name: nginx-container
    image: nginx:1.14
    ports:
    - containerPort: 80
      protocol: TCP

# 스케줄러의 도움을 받지 않고 kubelet 데몬에 의해 실행이 된다.
# 노드에서 직접 파드를 동작시킬 수 있다.
[master ~]$ kubectl get pods -o wide
NAME              READY   STATUS    RESTARTS   AGE   IP         NODE    NOMINATED NODE   READINESS GATES
nginx-pod-node2   1/1     Running   0          97s   10.5.1.4   node2   <none>           <none>

👉🏻staticPodPath를 변경하고나면 반드시 kubelet Daemon을 restart 시켜 주어야 한다.

# yaml 파일을 삭제하면 pod도 삭제된다.
[node2 manifests]$ rm -rf nginx.yaml 
[node2 manifests]

[master ~]$ kubectl get pods -o wide
No resources found in default namespace.

 

 

# master의 staticPod

# k8s가 동작될 때 master에서 반드시 실행되어야 하는 컴포넌트 => staticPod 형태로 동작
[master ~]$ cd /etc/kubernetes/manifests/
[master manifests]$ ls
etcd.yaml            kube-controller-manager.yaml
kube-apiserver.yaml  kube-scheduler.yaml

 

# 만약 master에서 nginx를 staticPod로 등록하게 되면 워커노드에서 실행된다

[master manifests]$ cat 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 manifests]$ kubectl get pods -o wide
NAME              READY   STATUS    RESTARTS      AGE   IP         NODE    NOMINATED NODE   READINESS GATES
nginx-pod-node1   1/1     Running   1 (81s ago)   65s   10.5.0.6   node1   <none>           <none>
# node1에 등록됨
반응형

'Container > Kubernetes' 카테고리의 다른 글

[K8S] Pod 환경 변수 설정  (0) 2024.02.19
[K8S] Pod Resource 할당  (0) 2024.02.19
[K8S] init container  (0) 2024.02.18
[K8S] Liveness Probe (Self-healing) Pod  (1) 2024.02.16
[K8S] YAML 템플릿 및 Pod  (0) 2024.02.13