- Import the GPG public key of the Alibaba Cloud image
curl -fsSL https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/kubernetes-archive-keyring.gpg
sudo apt-get update
- Check /etc/apt/sources.list.d/kubernetes.list configuration
sudo rm -f /etc/apt/sources.list.d/kubernetes.list
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
- Update and install Kubernetes
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
- Confirm whether the installation is successful
kubelet --version
kubeadm version
kubectl version --client
- Disable Swap (if not disabled)
sudo swapoff -a
sudo sed -i '/swap/d' /etc/fstab
- Initialize the Kubernetes cluster. Run the following command to initialize the Kubernetes master node:
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
- Set up kubectl to access the cluster
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Test whether the connection is successful:
kubectl get nodes
bash
If the master node status is displayed as Ready, it means that the initialization is successful.
- Install network plugin (using Flannel)
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
- Add a working node
After the master node is initialized, you can use the following command to join the worker node to the cluster:
kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
If need to deploy an application, can use kubectl apply or Helm deployment.
Source link
lol