안녕하세요 보나에요 :)

 

오늘은 kubeadm을 사용하여 k8s를 구축해볼거에요!!

 

azure, gcp, aws 등에서는 자체적으로 k8s를 간편하게 설치할 수 있지만, 우리는 한번 직접!

 

리눅스 인스턴스를 사용하여 k8s cluster를 구축해볼거에요.

 

참고로 azure, gcp, azure에서 제공해주는 k8s-cluster는 아주 간편하고 쉽게 구축할 수 있지만,

 

가격이.. 어마무시하게 측정된다는 단점이 있습니다.

 

하지만, 서버만 사용하여 자체 구축하면 비용이 감축되는 장점도 있구요,,

 

우리는 또한!! 서버를 살 돈이 어딨어요 ㅠㅠ 비싸비싸

 

그래서 아직 한번도 사용을 안해보았다면!! 각 플랫폼은 무료 평가판을 쓸 수 있도록 해줍니다.

 

그래서 저도!! gcp 300불 무료평가판을 통해 구축해볼거에요~

 

서버를 구축하는 것은 이 링크를 참고하세요~

 

1. k8s 구축용 서버 체크.

준비서버 : master 서버1, worker용 서버 2 (ubuntu 18.04)

  • Master 서버 - 4 CPU and 16GB RAM
  • Worker1 서버 - 2 CPU and 4GB RAM
  • Worker2 서버 - 2 CPU and 4GB RAM

ip 정보  # 전에는 잘 되었던것 같은데, 외부IP로도,, 현재 다시 해보니 내부 IP로 설정해야함..

  • master 서버용 ip - 104.197.89.71
  • worker 서버용 ip - 35.239.5.160
  • worker 서버용 ip - 35.188.32.107 

 

 

2. ubuntu apt 패키지 업데이트, 업그레이드 하기.

# root로 변환시키기
sudo -i 

apt update -y && apt upgrade -y

 

3. Disable Swap 메모리

kubelet이 제대로 작동하기 위해서는 SWAP메모리를 비활성시키는게 필수적이라고 할 수 있다. master, worker노드 모두 disable 시킨다.

sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
swapoff -a

4. kubelet, kubeadm, kubectl 설치

레파지토리 추가

 

apt-get update && apt-get install -y 
apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list

 

 

설치

 

apt update
apt -y install vim git curl wget kubelet kubeadm kubectl

 

standby 모드로 대기시키기

apt-mark hold kubelet kubeadm kubectl

5. Configure Firewall

modprobe overlay
modprobe br_netfilter

 

traffic check

vi /etc/sysctl.d/kubernetes.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
sysctl --system

6. Docker 설치

apt update
apt install -y curl gnupg2
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt update
apt install -y containerd.io docker-ce

Create Directories and Configurations

mkdir -p /etc/systemd/system/docker.service.d

vi /etc/docker/daemon.json

{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
				"max-size": "100m" },
"storage-driver": "overlay2"
}

Docker 재시작

 

systemctl daemon-reload
systemctl restart docker
systemctl enable docker

7. 마스터노드 생성

lsmod | grep br_netfilter

 

Kubelet 시작

systemctl enable kubelet
kubeadm config images pull

8. Create Cluster

kubeadm init \
--pod-network-cidr=10.0.0.0/16 \
--control-plane-endpoint=master
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

Calico 설치

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml


Worker노드 추가

kubeadm join master:6443 --token bf6w4x.t6l461giuzqazuy2 --discovery-token-ca-cert-hash sha256:8d0b3721ad93a24bb0bb518a15ea657d8b9b0876a76c353c445371692b7d064e

 

+ Recent posts