#/bin/bash # This script is to install Kubernetes on Ubuntu 22.04 LTS, with Calico as CNI # This script used 10.244.0.0/16 as pod network CIDR. This network should not be used in your physical network. # This script used Calico v3.27.0. You can change it to the latest version. DEBIAN_FRONTEND=noninteractive sudo apt update DEBIAN_FRONTEND=noninteractive sudo apt install curl gnupg2 software-properties-common apt-transport-https ca-certificates -y echo "Uninstall Docker.ce..." aiur() { arg="$( cut -d ' ' -f 2- <<< "$@" )" && curl -sL https://gitlab.aiursoft.cn/aiursoft/aiurscript/-/raw/master/$1.sh | sudo bash -s $arg; } aiur uninstall/docker sudo apt autoremove -y echo "Install Docker.io..." DEBIAN_FRONTEND=noninteractive sudo apt install docker.io -y echo "Prepare network..." cat < /etc/containerd/config.toml" sudo sed -i 's/ SystemdCgroup = false/ SystemdCgroup = true/' /etc/containerd/config.toml sudo systemctl restart containerd.service sudo systemctl restart kubelet.service echo "Install K8S..." curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes.gpg --yes echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/kubernetes.gpg] http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list sudo apt update DEBIAN_FRONTEND=noninteractive sudo apt install kubeadm kubelet kubectl kubernetes-cni -y # Init (Only on Master) echo "Init K8S..." sudo kubeadm config images pull sudo kubeadm init --pod-network-cidr=10.244.0.0/16 read -p "Please copy the kubeadm join command above and run it on worker nodes. Press any key to continue..." # Config (Only on Master) echo "Config K8S..." mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config # Calico (Only on Master) echo "Install Calico..." kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/tigera-operator.yaml curl https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/custom-resources.yaml -O sed -i 's/cidr: 192\.168\.0\.0\/16/cidr: 10\.244\.0\.0\/16/' custom-resources.yaml kubectl create -f custom-resources.yaml sudo systemctl restart kubelet.service # Test (Only on Master) echo "Test K8S..." kubectl get nodes -o wide kubectl get pods --all-namespaces