일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- argocd
- k8s
- cicd
- alibaba
- alibabacloud
- cloud monitor
- Cluster
- CKAD
- NCP
- 테라폼
- alibaba cloud
- Deployment
- Kubernetes
- IAC
- 자동화
- recreate
- hashicorp
- 알리바바클라우드
- slack app
- RollingUpdate
- terraform
- kubeadm
- slack
- GIT
- 쿠버네티스
- 시험
- Naver Cloud
- cloudmonitor
- helm
- 네이버클라우드
- Today
- Total
Room9
Kubernetes Cluster (2) - Kubeadm을 이용한 kubernetes 설치 본문

Overview
이전 글Kubernetes Cluster (1) - VirtualBox VM Config에서 VirtualBox를 이용하여 VM구성을 진행하였습니다. 이번 글에서는 VM을 이용하여 Kubernetes Cluster를 구성해보도록 하겠습니다. Kubernetes 1.20 릴리즈부터 Docker가 Deprecated 되어 Containerd, CRI-O와 같은 다른 Container Runtime Interface(CRI)를 이용해 보도록 하겠습니다. 컨테이너 런타임과 관련된 내용은 링크의 내용을 한번 읽어보면 도움이 될 것 같아 링크 남깁니다.
흔들리는 도커의 위상 - OCI와 CRI 중심으로 재편되는 컨테이너 생태계
Detail
- containerd(CRI) install
- Kubernetes install
- calico(CNI) install
containerd (CRI) install
Prerequisites
$ cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
$ sudo modprobe overlay
$ sudo modprobe br_netfilter
# 설치에 필요한 파라미터를 sysctl에 정의합니다. 해당 옵션은 재시작하여도 유지됩니다.
$ cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
# 재시작 없이 파라미터를 적용합니다.
$ sudo sysctl --system
install
사전작업이 마무리되면 containerd를 설치를 진행하겠습니다.
# HTTPS를 활용해 저장소에 접근하기 위해 다음의 패키지를 설치합니다.
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
# Docker의 공식 GPG 키를 시스템에 추가합니다.
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
$ echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# 새로운 저장소가 추가되었으므로, 업데이트를 합니다.
$ sudo apt-get update
# containerd install
$ sudo apt-get install containerd.io
containerd config
$ sudo mkdir -p /etc/containerd
$ containerd config default | sudo tee /etc/containerd/config.toml
$ sudo systemctl restart containerd
systemd cgroup driver의 사용
/etc/containerd/config.toml 의 systemd cgroup 드라이버를 runc에서 사용하려면 config.toml파일 수정이 필요하다.
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
...
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
각 항목은 config.toml 파일이 존재하며, SystemCgroup = true 를 해당 위치에 넣어주고 containerd 재시작하여 적용합니다.
sudo systemctl restart containerd
재시작까지 완료하면 containerd 설치는 완료되었습니다.
Kubernetes install
container도 설치를 완료했고 이제 kubernetes cluster를 설치해보도록 하겠습니다. kubernetes cluster를 설치하는 방법은 정말 많습니다. kubeadm , kubespray , kops 등으로 설치를 진행할 수 있습니다. 해당 글은 kubeadm으로 설치를 진행하겠습니다.
Requirements
- 호환되는 리눅스 머신. 쿠버네티스 프로젝트는 데비안 기반 배포판, 레드햇 기반 배포판, 그리고 패키지 매니저를 사용하지 않는 경우에 대한 일반적인 가이드를 제공한다. - ubuntu 20.04
- 2 GB 이상의 램을 장착한 머신. - 4096MB
- 2 이상의 CPU. - 2 CPU
- 클러스터의 모든 머신에 걸친 전체 네트워크 연결. - NAT Network
- 모든 노드에 대해 고유한 호스트 이름, MAC 주소 및 product_uuid. 자세한 내용은 여기를 참고한다. - m-k8s, w1-k8s, w2-k8s
- 컴퓨터의 특정 포트들 개방.
- 스왑의 비활성화. kubelet이 제대로 작동하게 하려면 반드시 스왑을 사용하지 않도록 설정한다.
이전 글에서 설정한 VM설정 내용들이 요구사항에 부합하는지 확인합니다.
Swapoff
스왑을 비활성화한다.
$ swapoff -a
Port Open
ubuntu의 방화벽인 ufw에 필요한 포트들을 추가하여줍니다.
# 단일 포트 열기
sudo ufw allow [PORT]/tcp
# 범위 포트 열기
sudo ufw allow [PORT부터]:[PORT까지]/tcp
Controlplane(master)에 필요한 포트들은 아래 표와 같습니다.
TCP | Inbound | 2379-2380 | etcd server client API | kube-apiserver, etcd |
TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
TCP | Inbound | 10259 | kube-scheduler | Self |
TCP | Inbound | 10257 | kube-controller-manager | Self |
TCP | Inbound | 6443 | Kubernetes API server | All |

Workernode에서 필요한 포트들은 아래표와 같습니다.
TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
TCP | Inbound | 30000-32767 | NodePort Services† | All |


kubeadm, kubelet, kubectl 설치
kubectl경우에는 worker node에는 따로 설치를 진행해주시지 않아도 됩니다.
1. apt 패키지를 업데이트하고, 쿠버네티스 apt 리포지터리를 사용하는 데 필요한 패키지를 설치합니다.
$ sudo apt-get update
$ sudo apt-get install -y apt-transport-https ca-certificates curl
2. 구글클라우드 샤이닝 키를 다운로드합니다.
$ sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
3. 쿠버네티스 apt repo를 추가합니다.
$ echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
4. apt 패키지 색인을 업데이트하고, kubelet, kubeadm, kubectl을 설치하고 해당 버전을 고정합니다.
$ sudo apt-get update
$ sudo apt-get install -y kubelet kubeadm kubectl
$ sudo apt-mark hold kubelet kubeadm kubectl
Controlplane 초기화
$ kubeadm init --apiserver-advertise-address=10.0.1.4
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a Pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
초기화를 진행하면 kubeadm join이라는 명령어를 하나 출력하는데, 해당 명령어는 추후에 Worker node를 클러스터에 합류시킬 때 사용하는 명령어입니다. 복사해서 메모장 같은데 복사해둡시다.
명령어 옵션 중에 --control-plane-endpoint 옵션도 존재합니다. 해당 옵션은 다중 Master Node 구성시에 사용하여 endpoint를 구성할 수 있습니다.
kubectl
kubectl을 root사용자가 아닌 사용자가 사용할 수 있도록 아래 명령어를 실행해줍니다.
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
Woker node 추가
위에서 kubeadm join 명령어를 이용하여 각 워커 노드에서 실행하여줍니다.
$ kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Calico install
kubernetes cluster 설치는 완료되었습니다. 이제 CNI구성을 완료하여 노드 간 통신이 원활하게 진행되는지 확인을 진행하겠습니다.
여러 가지 CNI들이 있겠지만, 저에게 조금 익숙한 calico를 설치하여 보겠습니다.
$ curl https://docs.projectcalico.org/manifests/calico.yaml -O
$ kubectl apply -f calico.yaml
구성 확인

나만의 작은 클러스터가 완성되었습니다.
마치며
Kubernetes Cluster 구축이 완료되었습니다. 처음 설치할 때 버전이 1.18 버전이었던 것 같은데 최신 버전으로 설치를 진행했더니 1.22.4 버전까지 빠르게 버전이 변하고 있네요. 앞으로 kubernetes나 Cloud Native 관련 글이 많을 것 같기도 하고 리마인드 차원에서 포스팅을 하였습니다. 부족한 부분이나 빠진 부분은 댓글로 피드백 부탁드리겠습니다. 읽어주셔서 감사합니다.
References
https://kubernetes.io/ko/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/