2024-10-03 23:38:51
728x90
728x90

구성 환경

Master 2core Memory 2GB HDD 50GB 

Worker1 2core Memory 2GB  HDD 50GB

Worker2 2core memory 2GB HDD 50GB

 

0. 패키지 설치 및 방화벽 설정

# 전체 노드 진행
apt install -y ntp docker.io socat
systemctl enable --now docker

#IP Forwarding 기능 활성화
echo '1' > /proc/sys/net/ipv4/ip_forward

# 마스터 노드 진행
ufw enable
ufw allow 6443/tcp
ufw allow 2379/tcp
ufw allow 2380/tcp
ufw allow 10248/tcp
ufw allow 10250/tcp
ufw allow 10251/tcp
ufw allow 10252/tcp
ufw allow 10255/tcp
ufw reload

1.  containerd 설치

# 모든 노드 swapoff 진행
swapoff -a
sed -i '/ swap / s/^/#/' /etc/fstab

# 커널 모듈 및 네트워크 설정(마스터 노드 진행)
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

modprobe overlay
modprobe br_netfilter

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

sysctl --system

# containerd 설치
apt install -y containerd

mkdir -p /etc/containerd

containerd config default | sudo tee /etc/containerd/config.toml

vi /etc/containerd/config.toml
# SystemdCgroup을 false에서 true로 변경
# sandbox_image를 registry.k8s.io/pause:3.8에서 registry.k8s.io/pause:3.9로 변경 

systemctl restart containerd

 

 

2.  kubeadm 설치

#전체 노드 진행
apt-get update
apt-get install -y apt-transport-https ca-certificates curl gpg

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl

systemctl enable --now kubelet

# 마스터 노드에서만 진행 (마스터노드와 워커 노드의 ip에 따라 ip 변경)
kubeadm init --apiserver-advertise-address 192.168.141.133 --pod-network-cidr=10.0.0.0/16
#에러 시 kubeadm reset 명령어 입력 후 해결하여 재진행

# 마스터 노드에서만 진행
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

# 워커 노드에서만 진행 (워커 노드에서 init 성공시 나오는 명령어 사용)
kubeadm join 192.168.141.133:6443 --token 0tzbpj.6zl2w5fjo8gmrsa5 \
    --discovery-token-ca-cert-hash sha256:e4f0e40dc3149acfd019702f3b369f086e5e160e3876e481b862f04a4f2f1199

 

3. cni(calico) 설치

# 마스터 노드만 진행
mkdir cni
cd cni

wget https://raw.githubusercontent.com/projectcalico/calico/v3.28.1/manifests/tigera-operator.yaml
wget https://raw.githubusercontent.com/projectcalico/calico/v3.28.1/manifests/custom-resources.yaml

# cidr 대역을 워커 노드 cidr 대역으로 변경
vi custom-resources.yaml

kubectl create -f tigera-operator.yaml
kubectl create -f custom-resources.yaml

 

4. 확인

kubectl get nodes
NAME      STATUS   ROLES           AGE   VERSION
master    Ready    control-plane   74m   v1.30.5
worker1   Ready    <none>          63m   v1.30.5
worker2   Ready    <none>          63m   v1.30.5

 

※ 노드 상태가 NotReady일 때 해결 방법

쿠버네티스 설치후 kubectl get nodes로 확인하니 NotReady 상태인걸 확인

kubectl get pods -n kube-system -o wide로 확인해보니 coredns가 pending 상태인걸 확인

kubectl edit cm coredns -n kube-system를 입력하여 24라인의 loop 부분을 주석 처리

1 # Please edit the object below. Lines beginning with a '#' will be ignored,
  2 # and an empty file will abort the edit. If an error occurs while saving this file will be
  3 # reopened with the relevant failures.
  4 #
  5 apiVersion: v1
  6 data:
  7   Corefile: |
  8     .:53 {
  9         errors
 10         health {
 11            lameduck 5s
 12         }
 13         ready
 14         kubernetes cluster.local in-addr.arpa ip6.arpa {
 15            pods insecure
 16            fallthrough in-addr.arpa ip6.arpa
 17            ttl 30
 18         }
 19         prometheus :9153
 20         forward . /etc/resolv.conf {
 21            max_concurrent 1000
 22         }
 23         cache 30
 24         #loop <- 이 부분
 25         reload
 26         loadbalance
 27     }
 28 kind: ConfigMap
 29 metadata:
 30   creationTimestamp: "2024-10-03T03:56:07Z"
 31   name: coredns
 32   namespace: kube-system
 33   resourceVersion: "4813"
 34   uid: fe69f246-226a-4f6b-b421-b7361e217bdd
 
 kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

 

※ 가상 머신 재부팅 시 The connection to the server 192.168.141.138:6443 was refused - did you specify the right host or port? 해결

스냅샷은 항시 저장할 것. 해결이 안되면 스냅샷으로 복구

journalctl -xe로 로그 확인하니 swap on 상태라고 함.

swapoff -a

systemctl restart kubelet

 

 

이래도 안된다면 가상 머신의 용량을 추가하거나 글 대로만 진행하면 됩니다. 다른 글들 참고하고 안되는거 제외하고 무조건 되는 방법으로 진행했어요..

728x90