f Ubuntu 20.04 安裝 K8s ~ 迪貝之家

Ubuntu 20.04 安裝 K8s


How to set up a Kubernetes cluster on-premise with kubeadm?

Step 1: The container runtime

curl -fsSL https://get.docker.com -o get-docker.sh

sudo sh get-docker.sh

Step 2: Installing kubeadm

To disable swap, you will need to:

Run swapoff -a

Open /etc/fstab file

Remove any swap entry for the file

Then, we can install all the components we will need to configure our cluster:

sudo apt-get update && sudo apt-get install -y apt-transport-https curl

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list

deb https://apt.kubernetes.io/ kubernetes-xenial main


sudo apt-get update

# Install components

sudo apt-get install -y kubelet kubeadm kubectl

# Hold version

sudo apt-mark hold kubelet kubeadm kubectl

Step III Initial Cluster 

kubeadm init --kubernetes-version=1.20.2 --ignore-preflight-errors=all --service-cidr  --pod-network-cidr  --apiserver-advertise-address


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

上述指令不做,根本連kubectl 指令都沒辦法運作


kubeadm join --token soktmz.d0vwvz57to497w6p \

        --discovery-token-ca-cert-hash sha256:5e1a615b4e4e474dcedd979f9d8b7cfa37691a32b15885072c765a51975d18c5

最後把 CNI 安裝上去 ,我也不是很清楚它是什麼?


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


然後再到各worker node執行那一段join cluster 的command


這沒什麼好藏私的~~ 因為難的是...怎麼使用它....哈!!