RedPlug's Tory

[k8s] k8s 설치

Linux2021. 5. 9. 18:35

 

1. 노드구성 : k8s-master, k8s-node1, k8s-node2

2. Hyper-v 에 Ubuntu 20.04 설치하여 진행

3. 3대 모두 Docker 설치 진행

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
## apt 레파지토리 업데이트
sudo apt-get update
 
## 사전 설치 진행
sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
 
## GPG 키 추가
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
    sudo gpg --dearmor -/usr/share/keyrings/docker-archive-keyring.gpg
 
## 레파지토리 추가
echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
 
## 도커 설치
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
 
## 도커 등록 및 실행
sudo systemctl enable docker
sudo systemctl start docker
 
##  도커 버젼 확인
sudo docker version
 

4. 쿠버네티스 설치

4.1 설치 사양

Installing kubeadm
kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

 

Installing kubeadm

This page shows how to install the kubeadm toolbox. For information how to create a cluster with kubeadm once you have performed this installation process, see the Using kubeadm to Create a Cluster page. Before you begin A compatible Linux host. The Kubern

kubernetes.io

Before you begin

  • A compatible Linux host. The Kubernetes project provides generic instructions for Linux distributions based on Debian and Red Hat, and those distributions without a package manager.
  • 2 GB or more of RAM per machine (any less will leave little room for your apps).
  • 2 CPUs or more.
  • Full network connectivity between all machines in the cluster (public or private network is fine).
  • Unique hostname, MAC address, and product_uuid for every node. See here for more details.
  • Certain ports are open on your machines. See here for more details.
  • Swap disabled. You MUST disable swap in order for the kubelet to work properly.

4.2 설치 진행

- 스왑 끄기

sudo swapoff -a

/etc/fstab에서 # swap was on~~ 하단 UUID 에 # 주석처리 진행

또는 swapoff -a && sed -i '/swap/s/^/#/' /etc/fstab

- 설치 전 환경 설정(네트워크 설정, master,node1~2 브릿지 네트워크 리슨할 수 있도록 설정 )

1
2
3
4
5
6
7
8
9
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
 
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
 

- 방화벽 오픈(테스트 여서 오프함)

1
2
sudo systemctl stop firewalld
sudo systemctl disable firewalld
 

 

- kubeadm(전체관리), kubelet(데몬), kubectl(명렁어) 설치

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
## Download the Google Cloud public signing key
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
 
## Add the Kubernetes apt repository:
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
 
## Update apt package index, install kubelet, kubeadm and kubectl, and pin their version:
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
 
 
## kubelet 실행
sudo systemctl enable kubelet
sudo systemctl start kubelet
 
 

4.3 kubeadm으로 클러스터 구성

- 마스터에서만 실행

1
kubeadm init
 

- init 완료 후 Join 토큰 저장

- kubectl 명령어 허가

1
2
3
4
5
6
To start using your cluster, you need to run the following as a regular user:
 
  mkdir -p $HOME/.kube
  sudo cp -/etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
 
 
 

- Pod Network 설치

1
2
kubectl apply -"https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
kubectl get nodes
 

설치 후 STATUS가 Ready 가 되어야 함

- Join 토큰을 node에서 실행

 

- bash 명령어 관련 : kubernetes.io/docs/reference/kubectl/cheatsheet/

명령어 좀 편하게...

1
2
3
4
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
source <(kubeadm completion bash)
echo "source <(kubeadm completion bash)" >> ~/.bashrc
 

 

설치완료

 

 

 

참고 : 

www.youtube.com/watch?v=lheclzO-G7k&list=PLApuRlvrZKohaBHvXAOhUD-RxD0uQ3z0c&index=4

github.com/237summit/k8s_core_labs