AWS EC2(ubuntu) 환경에서 kubeadm을 이용한 K8S Cluster 구축

taeni·2022년 3월 8일
0

IP는 172.0.0.0으로 표기함.
실제 사용되는 IP와 SUBNET을 적용바람.

🛠 K8S 설치 (각 노드에 모두 동일하게 설치)

k8s 저장소 추가

$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
$ sudo chmod -R 777 /etc/apt
$ cat <<EOF> /etc/apt/sources.list.d/kubernetes.list
> deb http://apt.kubernetes.io/ kubernetes-xenial main
> EOF

docker 설치

$ wget -qO- get.docker.com | sh

k8s package 설치

$ sudo apt-get update
$ sudo apt-get install -y kubelet kubeadm kubectl kubernetes-cni

docker 환경설정 변경

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock구문 뒤에 --exec-opt native.cgroupdriver=systemd를 추가

$ sudo vi /lib/systemd/system/docker.service
[Service]
Type=notify                                                                    
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker                                                
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemd
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

🗒 MASTER NODE 설정

cluster 초기화

$ sudo kubeadm init --apiserver-advertise-address 0.0.0.0 --pod-network-cidr=172.0.0.0/16 --ignore-preflight-errors=ALL

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

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 172.0.0.0:6443 --token gs5zbb.lwpwcaghege7a6cs \
        --discovery-token-ca-cert-hash sha256:0885f23cdbf64b621c53c0c230bd938adf0da057e8039331ae4b6490343bb0ca
  • mkdir 시작되는 구문부터 3줄 복사하여 터미널에 입력
  • kubeadm join 172.0.0.0:6443 --token gs5zbb.lwpwcaghege7a6cs \ --discovery-token-ca-cert-hash sha256:0885f23cdbf64b621c53c0c230bd938adf0da057e8039331ae4b6490343bb0ca은 worker node에서 master node에 연결하기 위한 명령어

설치확인

$ kubectl get nodes

NAME               STATUS     ROLES                  AGE     VERSION
ip-172-0-0-0       NotReady   control-plane,master   7m13s   v1.23.4

🗒 WORKER NODE 설정

초기화

$ sudo kubeadm reset

master node join (master node cluster 초기화시에 생성된 토큰으로)

$ sudo kubeadm join 172.0.0.0:6443 --token p46o53.yf40pnp8mbsd4efe \
        --discovery-token-ca-cert-hash sha256:8464611730f9c9ad87d814993643085146acfbbddddd6bdf28a2ed63a59897eb --ignore-preflight-errors=ALL

master node에서 cluster 구성 확인 (STATUS NotReady)

$ kubectl get nodes
NAME               STATUS     ROLES                  AGE     VERSION
ip-172-0-0-1       NotReady   <none>                 6m34s   v1.23.4
ip-172-0-0-0       NotReady   control-plane,master   28m     v1.23.4
ip-172-0-0-2       NotReady   <none>                 12m     v1.23.4

🗒 MASTER NODE 컨테이너 네트워크 애드온 설정

IP 대역 변경

$ wget https://docs.projectcalico.org/v3.22/manifests/calico.yaml
$ sed -i -e 's?192.168.0.0/16?172.0.0.0/16?g' calico.yaml
$ kubectl apply -f calico.yaml

node 확인 (STATUS Ready 확인)

$ kubectl get nodes
NAME               STATUS     ROLES                  AGE    VERSION
ip-172-0-0-1       Ready      <none>                 33m    v1.23.4
ip-172-0-0-0       Ready      control-plane,master   115m   v1.23.4
ip-172-0-0-2       Ready      <none>                 99m    v1.23.4
profile
정태인의 블로그

0개의 댓글