DEV Community

Reene
Reene

Posted on

[Kube][Commands]

1. ssh

sudo apt update
sudo apt install openssh-server -y

sudo systemctl enable ssh
sudo systemctl start ssh

sudo systemctl status ssh

Enter fullscreen mode Exit fullscreen mode
sudo vim /etc/fstab

#/swapfile none swap sw 0 0

sudo reboot
free -h
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode
  • Update and install Kubernetes
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl

Enter fullscreen mode Exit fullscreen mode
  • Confirm whether the installation is successful
kubelet --version
kubeadm version
kubectl version --client

Enter fullscreen mode Exit fullscreen mode
  • Disable Swap (if not disabled)
sudo swapoff -a
sudo sed -i '/swap/d' /etc/fstab
Enter fullscreen mode Exit fullscreen mode
  • 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

Enter fullscreen mode Exit fullscreen mode
  • 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

Enter fullscreen mode Exit fullscreen mode

Test whether the connection is successful:

kubectl get nodes

Enter fullscreen mode Exit fullscreen mode


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

Enter fullscreen mode Exit fullscreen mode
  • 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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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)