SuSu DaDDy

Kubernetes Cluster via kubeadm on Ubuntu 22.04 (Unbuntu 20.04, containerd)

by SuSu Daddy
반응형

0. 쿠버네티스 설치 결과

쿠버네티스 실습을 위해 설치한  내용을 기록하였습니다.

 

GitHub - inganyoyo/Kubernetes_install_helper

Contribute to inganyoyo/Kubernetes_install_helper development by creating an account on GitHub.

github.com

 

1. 설치환경

 - OS: ubuntu 20.04 (Virtual Box) 

 - Kubernetes: 1.24.3

 - Container Runtime: containerd

 - CNI: Flannel

 

2. 설치방법

# Download Scripts
git clone https://github.com/inganyoyo/kubernetes-yaml.git
cd ./kubernetes-yaml/kubernetes-yaml/Kubernetes_install_helper

#Change Mode 
sudo chmod +x ./scripts/*.sh

#Install (cotrol_plane and worker_node)
./scripts/step1_install_control_plane.sh
./scripts/step2_install_worker_node.sh #1~N
./scripts/step3_install_control_plane.sh

 

3. 명령어 설명

 - Install general dependencies

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl

 - Install containerd

curl -fsSLo containerd-config.toml \
  https://gist.githubusercontent.com/oradwell/31ef858de3ca43addef68ff971f459c2/raw/5099df007eb717a11825c3890a0517892fa12dbf/containerd-config.toml
sudo mkdir /etc/containerd
sudo mv containerd-config.toml /etc/containerd/config.toml


curl -fsSLo containerd-1.5.13-linux-amd64.tar.gz \
  https://github.com/containerd/containerd/releases/download/v1.5.13/containerd-1.5.13-linux-amd64.tar.gz
  
# Extract the binaries
sudo tar Cxzvf /usr/local containerd-1.5.13-linux-amd64.tar.gz

# Install containerd as a service
sudo curl -fsSLo /etc/systemd/system/containerd.service \
  https://raw.githubusercontent.com/containerd/containerd/main/containerd.service

sudo systemctl daemon-reload
sudo systemctl enable --now containerd

 

 - Install runc

curl -fsSLo runc.amd64 \
  https://github.com/opencontainers/runc/releases/download/v1.1.3/runc.amd64
sudo install -m 755 runc.amd64 /usr/local/sbin/runc

 

 - Install CNI network plugins

curl -fsSLo cni-plugins-linux-amd64-v1.1.1.tgz \
  https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz
sudo mkdir -p /opt/cni/bin
sudo tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.1.1.tgz

echo "##Forward IPv4 and let iptables see bridged network traffic##"
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe -a overlay br_netfilter

# sysctl params required by setup, params persist across reboots
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

# Apply sysctl params without reboot
sudo sysctl --system

 - Install kubeadm, kubelet, kubectl

# Add Kubernetes GPG key
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg \
  https://packages.cloud.google.com/apt/doc/apt-key.gpg

# Add 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

# Fetch package list
sudo apt-get update

sudo apt-get install -y kubelet kubeadm kubectl

# Prevent them from being updated automatically
sudo apt-mark hold kubelet kubeadm kubectl

 -  Ensure swap is disable

# See if swap is enabled
swapon --show

# Turn off swap
sudo swapoff -a

# Disable swap completely
sudo sed -i -e '/swap/d' /etc/fstab

(master only)

 - Create the cluster using kubeadm

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

 

 - configure kubectl

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc

echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -o default -F __start_kubectl k' >>~/.bashrc

 - Install a CNI plugin

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

(worker node only)

 - Join worker node

 # Step: 1 ~ 10
 
 kubeadm join 10.100.0.100:6443 --token npv6tj.u9intgo53hxtmyga \
	--discovery-token-ca-cert-hash sha256:c8e014d5889276accab3d73f98521280b9eede5e63716a46619bc6829ab4d83a

(control plane only)

 - install helm

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

echo "##Install helm##"
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash

echo "##Install a CSI driver##"
# Add openebs repo to helm
helm repo add openebs https://openebs.github.io/charts

 - Install a test 

# Add bitnami repo to helm
helm repo add bitnami https://charts.bitnami.com/bitnami

# install wordpress
helm install wordpress bitnami/wordpress \
  --set=global.storageClass=openebs-hostpath
  
echo "##print result##"
kubectl get pods --all-namespaces

 

4.  kubeadm reset

#kubeadm reset (cotrol_plane and worker_node)
cd ./kubernetes-yaml/kubernetes-yaml/Kubernetes_install_helper
./scripts/step9_kubeadm_reset.sh

 

반응형

블로그의 정보

SuSu Daddy

SuSu Daddy

활동하기