본문 바로가기
CS/인프라

[인프라] kubeadm 설치 2 - kubelet에 cgroup driver 설정을 왜 맞추어야 하는가?

by 김yejin 2022. 11. 5.

 

이전 포스트에 이어서 작성한 내용입니다.

https://yejincode.tistory.com/25

 

[인프라] kubeadm 설치 1 - containerd는 무슨 역할인가?

공식 설치 안내 페이지 https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/ Installing kubeadm This page shows how to install the kubeadm toolbox. For information on how to create a cluster with kubeadm once you ha

yejincode.tistory.com

 

전체 설치 순서 중 해당 포스트에서는 kubeadm,kubelet,kubectl 설치, cgroup driver 설정에 대하여 담고 있다.

  • 설치 전 준비 (서버 사양, 네트워크, 기타 사항)
  • CNI 설치
  • kubeadm, kubelet, kubectl 설치
  • cgroup driver 설정

 

kubeadm, kubelet, kubectl 설치

 

설치를 진행하기 전에 각각의 용어를 먼저 간단히 정리하고 진행한다.

 

kubeadm 이란?

 

You can use the kubeadm tool to create and manage Kubernetes clusters. It performs the actions necessary to get a minimum viable, secure cluster up and running in a user friendly way.

쿠버네티스 공식페이지에 의하면, kubeadm은 쿠버네티스 클러스터를 생성하고 관리하기 위해 사용하는 하나의 도구로써 설명하고 있다. 

Kubeadm is a tool built to provide `kubeadm init` and `kubeadm join` as best-practice "fast paths" for creating Kubernetes clusters.
kubeadm performs the actions necessary to get a minimum viable cluster up and running. By design, it cares only about bootstrapping, not about provisioning machines. Likewise, installing various nice-to-have addons, like the Kubernetes Dashboard, monitoring solutions, and cloud-specific addons, is not in scope.
Instead, we expect higher-level and more tailored tooling to be built on top of kubeadm, and ideally, using kubeadm as the basis of all deployments will make it easier to create conformant clusters.


the command to bootstrap the cluster. 

클러스터를 bootstrap 하는 명령어로써도 설명하고 있는데, 즉 클러스터를 생성하고 관리하는 명령어이다.
예를 들어 `kubeadm init` 의 경우 쿠버네티스의 control-plan-node를 기동하기 위해 사용된다.
그외에도 여러가지 명령어가 있으며 아래는 몇가지 명령어 이다.

이중에서 `kubeadm init` 명령어를 통해 kubenetes의 중요한 control-plan node를 기동시키는 것이 설치에서의 포인트로 보인다.

  • kubeadm init to bootstrap a Kubernetes control-plane node
  • kubeadm join to bootstrap a Kubernetes worker node and join it to the cluster
  • kubeadm upgrade to upgrade a Kubernetes cluster to a newer version
  • kubeadm config if you initialized your cluster using kubeadm v1.7.x or lower, to configure your cluster for kubeadm upgrade
  • kubeadm token to manage tokens for kubeadm join
  • kubeadm reset to revert any changes made to this host by kubeadm init or kubeadm join
  • kubeadm certs to manage Kubernetes certificates
  • kubeadm kubeconfig to manage kubeconfig files
  • kubeadm version to print the kubeadm version
  • kubeadm alpha to preview a set of features made available for gathering feedback from the community

 

kubelet 이란?

 

the component that runs on all of the machines in your cluster and does things like starting pods and containers.

 pod와 컨테이너를 관리하는 kublet은 노드의 구성요소로써 클러스터 내부의 모든 머신에 반드시 존재하는 구성요소이다. 

 

공식 가이드에서 설명하고 있는 kubnetes의 구성요소이다. kubelet에 관련한 내용만 간단히 살펴보면 아래와 같다.

출처:https://kubernetes.io/docs/concepts/overview/components/

kubelet 은 kubadm 과 달리, kubenetes 의 컴퍼넌트이다. 각각의 노드에는 kublet과 kube-proxy 으로 구성되어 있다.

쿠버네티스의 컴퍼넌트는 크게 3가지로 나뉜다. Control Plan ComponentsNode Componetns , Addons.
이중에서도 kubelet은 앞서 설치한 Container runtime와 마찬가지로 Node의 컴퍼넌트에 속한다.

Kubernetes Components

  • Control Plane Components
    • kube-apiserver
    • etcd
    • kube-scheduler
    • kube-controller-manager
    • cloud-controller-manager
  • Node Components
    • kubelet
    • kube-proxy
    • Container runtime
  • Addons
    • DNS
    • Web UI (Dashboard)
    • Container Resource Monitoring
    • Cluster-level logging

 

Node, Control plane 이란?

노드란 컨테이너화 된 서비스(어플리케이션)을 실행시키기 위한 머신의 단위를 말한다. 쿠버네티스를 구성하는 클러스터는 적어도 한개이상의 worker node로 구성되어 있고, 각각의 worker 노드는 pod 라고 불리는 application workload 요소를 가진다. 즉, 노드란 컨테이너화 된 서비스가 실질적으로 돌아가는 머신이라고 볼 수 있다.

control plane 이란 woker node와 pod를 관리하는 하나의 노드이다. 

When you deploy Kubernetes, you get a cluster.
A Kubernetes cluster consists of a set of worker machines, called nodes, that run containerized applications. Every cluster has at least one worker node.The worker node(s) host the Pods that are the components of the application workload
The control plane manages the worker nodes and the Pods in the cluster. In production environments, the control plane usually runs across multiple computers and a cluster usually runs multiple nodes, providing fault-tolerance and high availability.

 

따라서 kubelet이 무엇인가?

클러스터 내에서 기동중인 각각의 노드들을 관리하는 agent 이다.

An agent that runs on each node in the cluster. It makes sure that containers are running in a Pod.
The kubelet takes a set of PodSpecs that are provided through various mechanisms and ensures that the containers described in those PodSpecs are running and healthy. The kubelet doesn't manage containers which were not created by Kubernetes.

 

kubectl 이란?

the command line util to talk to your cluster.

The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs

즉, 클러스터를 설정하기 위하여 control plane과 커뮤니케이션하는 CLI 도구라고 볼 수 있다.

실질적으로 kubenetes를 application 배포, 리소스 inspect, manage, 로그확인 과 같은 클러스터에 명령을 kubectl을 통해 수행할 수 있다.

 


이제 kubeadm, kubelet, kubctl 설치를 진행한다.

 

먼저 SELinux가 설정되어있는 경우 해제한다. 

// SELinux 해제
[root@yejin-master ~]# setenforce 0
[root@yejin-master ~]# sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

// SElinux 상태 확인
[root@yejin-master ~]# sestatus
SELinux status:                 disabled

 

yum 의 repo에서 kubenetes.repo을 아래와 같이 설정한다.

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF

- 여기서 exclude에 해당 하는 부분이 yum install에서 적용되기 때문에 동일하게 작성한다.

해당 repo로부터 yum을 통해 kubeadm, kubelet, kubectl를 설치한다.

[root@yejin-master yum.repos.d]# sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

- 의문점은 `--disableexclues=kubernetes` 는 exclude에 해당하는 부분을 disable 하는 옵션이다. 그렇다면 kubelet과 kubeadm, kubectl를 빼고 설치한다는 의미로 해석되는데.. 중첩되는 부분이 있어서 그런것인지 의문이 든다.

 

설치가 완료되면, kubeadm과 kubectl은 도구이기 때문에 명령어로 version을 확인해보면 정상적으로 설치된 것을 확인할 수 있다.

kubelet은 systemd에 service가 등록되었기 때문에 service를 enabled --now 해준 후 status를 확인하면 아래와 같다.

[root@yejin-master yum.repos.d]# systemctl enable --now kubelet

 

현재까지는 단순 kubenetes 를 설치하기 위한 도구를 설치하고 kublet 이라는 agent 서비스를 설치한 상태이다. kublet이 기동된 상태를 확인해보면 disabled 상태임을 확인 할 수 있다. 정상 기동을 위한 추가 설정이 필요하다.

 

 

Cgroup driver 설정

 

Cgroup(Control Group) 이란?

다수의 Process가 포함되어 있는 Process Group 단위Resource(CPU, Memory, Disk, Network) 사용량을 제한하고 격리시키는 Linux의 기능. 주로 Container의 Resource 제어를 위해 많이 사용.

 

Cgroup 제어 방법 : cgropufs , systemd

cgroupfs : linux에서 제공하는 cgroup 제어 방법. cgroup 제어를 위한 특수한 file system. 

systemd : demon process의 제어 역할을 수행하는 linux의 init process. systemd이 제어하는 unit의 일부로 cgroup도 포함. 

 

systemd 는 생성한 unit의 cgroup을 기본적으로 /sys/fs/cgroup/memory/system.slice 경로 하위에 생성함

앞서 설치한 Container runtime 인 containerd 서비스를 확인해보면 아래와 같다.

   CGroup: /system.slice/containerd.service

/sys/fs/cgroup/memory/system.slice/containerd.service 경로를 보면 아래와 같이 cgroup이 생성된 것을 확인 할 수 있으며 procs 를 보면 879 번 containerd process가 소속되어 있는 것을 확인 할 수 있다.

[root@yejin-master yum.repos.d]# ls -alrt /sys/fs/cgroup/memory/system.slice/ |egrep containerd
drwxr-xr-x  2 root root 0 Nov  4 14:55 containerd.service

[root@yejin-master yum.repos.d]# cat /sys/fs/cgroup/memory/system.slice/containerd.service/cgroup.procs 
879

 

Cgroup Driver 란?

Cgroup 을 관리하는 모듈.

  • cgroupfs Driver : driver가 직접 cgroupfs 통해 Cgroup을 제어
  • systemd Driver : systemd를 통해 Cgroup 제어

 

kubenetes의 클러스터에서 cgroup driver 의 동작과정을 아래 그림을 통해 확인해보면 다음과 같다.
(그림에서는 도커 데몬을 이용하는 경우)

kubelet 내부 libcontainer 에서 cgroup driver 결정

docker daemon에서 cgroup driver 결정 -> containerd 호출 -> runc 에서 해당 cgroup drvier 사용

kubelet이 가지고 있는 cgroup dirver와 container runtime에서 가지고 있는 cgroup driver는 동일해야 함.

-> 만약 두개의 cgroup driver가 다르다면? kubelet process 가 제대로 기동되지 않는다. 

https://tech.kakao.com/2020/06/29/cgroup-driver/

위 그림을 통해 cgroupfs driver와 systemd driver의 동작과정도 간단히 비교해 볼 수 있다.

  • systemd driver
    systemd driver --- (D-Bus) --> systemd -- > cgroupfs
  • cgroupfs driver
    cgroupfs driver -> cgroupfs

 

따라서,
현재 fail 상태인 kubeletcontainerdcgroup driver을 동일하게 맞추어 주어야 한다.

kubelet 의 cgroup driver 확인 -> systemd driver을 사용하고 있다.

[root@yejin-master lib]# systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
   CGroup: /system.slice/kubelet.service
           └─35050 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --

containerd의 cgroup driver 확인
-> systemd driver을 사용하고 있다.

[root@yejin-master lib]# systemctl status containerd
● containerd.service - containerd container runtime
   CGroup: /system.slice/containerd.service
           └─879 /usr/local/bin/containerd

공식 문서에 따르면 kubeadm이 kubelet을 systemd로 관리하기 때문에  Container runtime에서 systmed를 사용하는 것을 권장한다. 

참고자료 :

https://tech.kakao.com/2020/06/29/cgroup-driver/ -> cgroup과 cgroup driver, 그리고 cgroupfs driver vs systemd driver에 대한 고찰이 상세히 담겨있다.

https://waspro.tistory.com/556 -> linux의 cgroup , namespce의 역할 동작에 대한 설명과 docker cgroup 의 변경방법까지 전체적이 고찰히 상세히 담겨있다.

 

 

각각의 cgroup 드라이버를 변경하는 방법, 그리고 왜 systemd를 권장하는지는 네트워크 세팅과 남은 containerd 세팅 후, kubeadm init을 통해 control-plane을 초기화 하는 작업 이후 다시 자세히 정리할 예정이다.

다음 예정 : container-runtime 

https://kubernetes.io/docs/setup/production-environment/container-runtimes/