[kubenetes] 1-2-2. 여러 서버로 구성된 클러스터 설치

kubenetes
Author
chan2slo chan2slo
Date
2022-07-25 21:17
Views
994

쿠버네티스의 각종 기능을 제대로 사용하려면 최소한 3대 이상의 서버를 준비하는것이 좋다.

실습에는 1개의 마스터와 3개의 워커노드를 이용한다.

아래 항목들이 준비되었는지 확인 해야한다.
- 모든 서버의 시간이 동기화되었는지
- 모든 서버의 맥주소가 다른지 확인
- 모든 서버가 2GB메모리 2cpu 이상의 충분한 지원을 가지고있는지
- 스왑 비활성화(swapoff -a)

클러스터 구성

kube-master1 192.168.122.140
kube-worker1 192.168.122.141
kube-worker2 192.168.122.142
kube-worker3 192.168.122.143

// 이제까지는 CentOS7로 진행했지만 교재가 ubuntu18.04로 진행하고있어
새로 ubuntu18.04 설치 후에 진행한다. 여태까지의 진행사항은 CentOS7과 동일하다.

쿠버네티스 저장소 추가

root@Minikube_practice_1:~# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 
OK
root@Minikube_practice_1:~# cat  /etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF

도커를 설치하는 스크립트 실행.. 아 도커 설치 이미했는데...

root@Minikube_practice_1:~# wget -qO- get.docker.com | sh 
# Executing docker install script, commit: 7cae5f8b0decc17d6571f9f52eb840fbc13b2737
Warning: the "docker" command appears to already exist on this system.

If you already have Docker installed, this script can cause trouble, which is
why we're displaying this warning and provide the opportunity to cancel the
installation.

If you installed the current Docker package using this script and are using it
again to update Docker, you can safely ignore this message.

You may press Ctrl+C now to abort this script.
+ sleep 20

책 기준 1.18.6 버전이므로 해당 버전 설치하려고 했으나
클러스터 초기화시 kubeadm이 지원하지않는다고해서 최신버전 설치해줌

root@Minikube_practice_1:~# apt-get install kubelet=1.18.6-00 kubeadm kubectl kubernetes-cni

쿠버네티스 클러스터 초기화

root@Kube-master1:~# kubeadm init --apiserver-advertise-address 192.168.122.140 --pod-network-cidr=192.168.140.0/24
[init] Using Kubernetes version: v1.21.0
[preflight] Running pre-flight checks
        [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
….
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 192.168.122.140:6443 --token jw1ez3.rc7czwtq0mcew1im \
        --discovery-token-ca-cert-hash sha256:177be1ba15bbe9714eab4c102febff38efb37b866690b84e7e7e83b13946e711 

위에서 나온 명령어 실행

root@Kube-master1:~#   mkdir -p $HOME/.kube
root@Kube-master1:~#   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
root@Kube-master1:~#   sudo chown $(id -u):$(id -g) $HOME/.kube/config

워커 노드들에서 맨아래 명령어들 실행

root@Kube-worker1:~# kubeadm join 192.168.122.140:6443 --token pay8d7.gbrmhpyaydmk1z0u \
>         --discovery-token-ca-cert-hash sha256:23e4c7ccdc85fece41568e8ac87a5dcc3da02840160db7ed8c3cdd046206d951 
…..
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

root@Kube-master1:~# kubectl get nodes
NAME           STATUS     ROLES                  AGE     VERSION
kube-master1   NotReady   control-plane,master   6m17s   v1.21.0
kube-worker1   NotReady                    59s     v1.21.0
kube-worker2   NotReady                    51s     v1.21.0
kube-worker3   NotReady                    46s     v1.21.0
Total Reply 0