Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
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
Tags
more
Archives
Today
Total
관리 메뉴

클라우드 엔지니어 꿈나무

k8s 설치 - RHEL9 본문

kubernetes

k8s 설치 - RHEL9

새싹싹이 2024. 7. 18. 00:30

Master Node

쿠버네티스 사용을 위하여 SElinux  Permissive 모드 설정 및 swap 끄기

# SElinux permissive로 설정 
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

#swap 미사용 주석처리
swapoff -a && sed -i '/swap/s/^/#/' /etc/fstab
#sed -e '/swap/s/^/#/g' -i /etc/fstab

 

Chrony로 시간 대역을 다 맞추고 진행

dnf install -y chrony

vi /etc/chrony.conf
server time.bora.net iburst

systemctl enable --now chrony

 

쿠버네티스 클러스터로 묶을 가상머신 기입

vi /etc/hosts
10.0.0.1        rhel-ma
10.0.0.2        rhel-worker1
10.0.0.3        rhel-worker2

 

Kernel-devel 패키지 다운로드 및 모듈 설정

dnf install kernel-devel-$(uname -r)

#네트워크 관리와 로드밸런싱 구성을 위하여 설정
#PVS(Internet Protocol Virtual Server) 모듈을 로드 - 트래픽 네트워크 분산
modprobe ip_vs
#라운드 로빈 스케줄링은 각 서버에 순차적으로 트래픽을 분배
modprobe ip_vs_rr
#서버에 가중치를 부여하여 더 높은 가중치를 가진 서버로 더 많은 트래픽을 분배
modprobe ip_vs_wrr
#소스 IP 주소를 해싱하여 동일한 클라이언트의 요청을 동일한 서버로 분배 - 세션 유지시 필요
modprobe ip_vs_sh
# 파일 시스템을 다른 파일 시스템 위에 덮어쓰는 방식
modprobe overlay

 

위 내용을 쿠버네티스 설정에 입력

cat > /etc/modules-load.d/kubernetes.conf << EOF
br_netfilter
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
overlay
EOF

 

IP 관련한 정보도 추가 기입

cat > /etc/sysctl.d/kubernetes.conf << EOF
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

#커널 변경 사항 적용
sysctl --system

 

방화벽을 개별로 열어줘도 되나 방화벽 미사용으로 설정

systemctl stop firewalld
systemctl disable firewalld

 

 

Conatinerd 설치 - RHEL9를 CRIO가 지원하지 않기 때문에 Centos8 방식으로 설치

컨테이너 레포지토리 추가

dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

 

캐시 패키지 다운로드

dnf makecache

 

컨테이너 이미지 다운로드

dnf -y install containerd.io

sh -c "containerd config default > /etc/containerd/config.toml"

vi /etc/containerd/config.toml
# 하기 부분 true로 변경 -> Systemd 에서 관리하는 컨테이너와 호환
SystemdCgroup = true

systemctl enable --now containerd
systemctl reboot

systemctl status containerd
#작동이 된 것을 확인

 

쿠버네티스 repo를 패키지 관리자로 추가

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF

 

 

쿠버네티스 패키지 설치

--disableexcludes=kubernetes플래그는 설치 중에 Kubernetes repo의 패키지가 제외되지 않도록 설정
dnf install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

 

필수 컨테이너 이미지를 가져와 저장

kubeadm config images pull

 

쿠버네티스 마스터 노드에 컨트롤 플레인 초기화 

kubeadm init --pod-network-cidr=10.244.0.0/16

 

init을 진행하면 하기와 같이 토큰이 표시된다.

노드 조인 시, 필요

 

<<참고>>

하기 명령어로도 토인을 다시 제공받을 수 있다.

kubeadm token create --print-join-command

 

 

쿠버네티스 클러스터 통신을 위하여 하기와 같이 설정

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

 

파드 네트워크 설정 - Calico

kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/tigera-operator.yaml

 

 

설치 확인

crictl ps -a

 

kubectl get nodes

 


Worker Node

setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux	

swapoff -a && sed -i '/swap/s/^/#/' /etc/fstab
#sed -e '/swap/s/^/#/g' -i /etc/fstab
dnf install -y chrony

vi /etc/chrony.conf
server time.bora.net iburst

systemctl enable --now chronyd
vi /etc/hosts
10.0.0.1        rhel-ma
10.0.0.2        rhel-worker1
10.0.0.3        rhel-worker2
systemctl stop firewalld
systemctl disable firewalld
dnf install kernel-devel-$(uname -r) -y

modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh
modprobe overlay
cat > /etc/modules-load.d/kubernetes.conf << EOF
br_netfilter
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
overlay
EOF
cat > /etc/sysctl.d/kubernetes.conf << EOF
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sysctl --system
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf makecache
dnf -y install containerd.io

sh -c "containerd config default > /etc/containerd/config.toml"

vi /etc/containerd/config.toml
SystemdCgroup = true

systemctl enable --now containerd
reboot

systemctl status containerd
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF
dnf install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubelet

 

노드 조인

토큰을 워커 노드에 입력

 


Master Node

마스터 노드에서 노드 조인 확인

 

 

 

 

 

<<참고>>

https://infotechys.com/install-a-kubernetes-cluster-on-rhel-9/

 

Install a Kubernetes Cluster on RHEL 9 | CentOS 9 - Infotechys.com

Learn how to install a Kubernetes cluster on RHEL 9 | CentOS 9. Explore step-by-step instructions, best practices, and considerations for ...

infotechys.com