The environment that

  • Cloud host: 2 (cloud host needs to be able to climb the wall)
  • Operating system: Ubuntu 18
  • Configuration: 2C 2G

Create two aliyun cloud hosts, as shown in the following figure

I use pay-as-you-go and delete when I’m done

  • Use foreign territories and available areas
  • Use foreign territories and available areas
  • Use foreign territories and available areas

Set the hostname

  • Example Set the cloud host hostname of the master node to K8S-master
hostnamectl set-hostname k8s-master
Copy the code

  • Set the cloud host hostname of worker node to K8S-worker1
hostnamectl set-hostname k8s-worker1
Copy the code

Deploy the master node (SSH to the CLOUD host of K8S-Master first)

  • Run the following command to deploy the master node
curl https://gitee.com/huang_juan/k8s-deploy-shell/raw/master/master.sh | sh
Copy the code

  • The following figure shows the successful deployment of the master node

  • Master node Check the status of nodes and Pods. At this point, only k8S-master is available

Deploy the worker node (SSH to k8S-worker1 cloud host first)

  • Execute the following command to deploy the worker node in one click
curl https://gitee.com/huang_juan/k8s-deploy-shell/raw/master/worker.sh | sh
Copy the code

  • The following figure shows the successful deployment of worker nodes

Add the Workder node to the cluster

  • Run the following command on the master node to obtain the token and ca_hash
kubeadm token create
master_ip=$(ifconfig | grep eth0 -A 1 | grep inet | awk '{print $2}')
token=$(kubeadm token list | grep -v TOKEN | awk '{print $1}' | head -n 1)
ca_hash=$(openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //')

echo kubeadm join $master_ip:6443 --token $token --discovery-token-ca-cert-hash sha256:$ca_hash
Copy the code

  • To add the worker node to the K8S cluster, first copy the generation command on the master node to the worker node for execution
kubeadm join $master_ip:6443 --token $token --discovery-token-ca-cert-hash sha256:$ca_hash
Copy the code

  • Configure kubectl on the worker node

Run this command on the K8S-Worker1 cloud host

mkdir -p $HOME/.kube
# $master_ipIt needs to be replaced with the IP of your K8S-Master cloud host (if your two cloud hosts are ali Cloud, either internal IP or external IP can be used).
scp root@$master_ip:/etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
Copy the code

Verify the config file on the K8S-worker1 node

cat /root/.kube/config
Copy the code

After the configuration is complete, you can view nodes information on the K8S-Worker1 node and view that the K8S-Worker1 node has been added to the cluster

View nodes information on the K8S-master node