Bootstrapping clusters with kubeadm

OneDayDev·2023년 1월 17일
0

K8s

목록 보기
1/12
post-thumbnail

시작하기 전에

  1. 2 이상 CPUs, 2GB 이상 RAM
  2. 클러스 내의 모든 머신의 네트워크 연결
  3. 호환되는 리눅스 머신(Debian, RedHat 기반)이여야 되고 모든 노드에 대해 고유한 호스트 이름, MAC 주소 및 product_uuid를 가져야한다.
  • hostnamectl set-hostname <설정할 이름> : 호스트 이름 변경
  • ifconfig -a 명령과 sudo cat /sys/class/dmi/id/product_uuid로 MAC 주소와 product_uuid 확인할 수 있다
  1. 포트 개방 공식 문서
  • Control plane : 6443, 2379, 2380, 10250, 10257, 10259
  • Worker Node : 10250, 30000-32767
  1. 스왑의 비활성화
sudo swapoff -a && sudo sed -i '/swap/s/^/#/' /etc/fstab

컨테이너 런타임 설치

공식 문서를 참고하자

CRI-O 설치

1. Forwarding IPv4 and letting iptables see bridged traffic

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

# sysctl params required by setup, params persist across reboots
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF

# Apply sysctl params without reboot
sudo sysctl --system

위의 명령어 실행 후 확인하기 위해 아래 명령어를 실행한다.

lsmod | grep br_netfilter
lsmod | grep overlay
sysctl net.bridge.bridge-nf-call-iptables net.bridge.bridge-nf-call-ip6tables net.ipv4.ip_forward

위의 설정 값이 1이어야한다.

2. CRI-O 설치

참고

sudo -i
export OS=xUbuntu_22.04 # OS 버전
export VERSION=1.26 
echo "deb [signed-by=/usr/share/keyrings/libcontainers-archive-keyring.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /" > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
echo "deb [signed-by=/usr/share/keyrings/libcontainers-crio-archive-keyring.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ /" > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list

mkdir -p /usr/share/keyrings
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | gpg --dearmor -o /usr/share/keyrings/libcontainers-archive-keyring.gpg
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/Release.key | gpg --dearmor -o /usr/share/keyrings/libcontainers-crio-archive-keyring.gpg

apt-get update
apt-get install cri-o cri-o-runc
sudo systemctl daemon-reload
sudo systemctl enable crio --now

kubeadm, kubelet, kubectl 설치

kubeadm: 클러스터를 부트스트랩하는 명령이다.
kubelet: 클러스터의 모든 머신에서 실행되는 파드와 컨테이너 시작과 같은 작업을 수행하는 컴포넌트이다.
kubectl: 클러스터와 통신하기 위한 커맨드 라인 유틸리티이다.

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

공식 문서에 작성된 것처럼 따라하면 된다.

위 과정을 컨트롤 노드랑와 워커 노드 둘 다 진행하고 아래 init은 컨트롤 노드만 진행

kubeadm init

# Controller - CRI-O 사용시
kubeadm init 
--cri-socket=/var/run/crio/crio.sock
--pod-network-cidr=192.168.0.0/16 
--control-plane-endpoint <ip:port>

init 후 출력되는 결과물은 저장해놓자.

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

실행 후 init 후 출력된 결과물에 kubeadm join ~~을 복사해서 work node에서 실행

그리고 kubectl get node를 하게 되면 not ready 상태일 것이다.

아래 CNI 설치를 마무리 지으면 상태가 ready로 전환될 것이다.

CNI 설치

CNI는 여러 종류가 있다. flannel, cni-plugins, kube-ovn, ovn4nfv, calico, canal, cilium, weavenet, kube-router, multus..

필자는 퍼블릭 클라우드에서 기본 네트워크 플러그인으로 삼는 calico를 사용할 것입니다.

Calico 설치

참고

kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/tigera-operator.yaml
curl https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/custom-resources.yaml -O
kubectl create -f custom-resources.yaml

node가 Ready된 후 roles이 none으로 설정되어있다. 다음 명령어로 변경하자

kubectl label node <worker node name> node-role.kubernetes.io/worker=worker
profile
안녕하세요.

0개의 댓글