1. ssh
sudo apt update
sudo apt install openssh-server -y
sudo systemctl enable ssh
sudo systemctl start ssh
sudo systemctl status ssh
sudo vim /etc/fstab
#/swapfile none swap sw 0 0
sudo reboot
free -h
2. Master
- 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, copy the generated command to worker node by using the following command in the master node to join the worker node to the cluster:
sudo kubeadm token create --print-join-command
If need to deploy an application, can use kubectl apply or Helm deployment.
3. worker
sudo apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/kubernetes-archive-keyring.gpg
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
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-get install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl enable kubelet
on worker:
mkdir -p $HOME/.kube
go to the master:
sudo scp /etc/kubernetes/admin.conf <worker-username>@<worker-node-ip-address>:/home/<worker-username>/.kube/config
back to the worker:
sudo chown $(id -u):$(id -g) $HOME/.kube/config
check the status:
kubectl get nodes
Top comments (0)