k8s
use following commands to simulate kubernate clusters
0. configure static ip address
ip route | grep default
Open the Netplan configuration file:
sudo nano /etc/netplan/01-netcfg.yaml
Configure static IP: Add the following to the file:
network:
version: 2
ethernets:
ens33: #Replace with your network card name
addresses:
- 192.168.1.10/24 # Set a fixed IP address
routes:
- to: default
via: 192.168.1.1 #Set the gateway address
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
sudo netplan apply
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
- Disable Swap (if not disabled)
sudo swapoff -a
sudo sed -i '/swap/d' /etc/fstab
- 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
- Initialize the Kubernetes cluster. Run the following command to initialize the Kubernetes master node:
sudo kubeadm init --pod-network-cidr=192.186.0.0/16 --ignore-preflight-errors=Port-6443,Port-10259,Port-10257,Port-10250
- 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)