Create a single master cluster with kubeadm - YuntechNet/Kubernetes-Deployment GitHub Wiki

Establish Master Node

  1. Initialize the master

    sudo kubeadm init --pod-network-cidr=10.244.0.0/16
    

    Since we will build a pod network later, we need to set up our pod network CIDR first. Here we take 10.244.0.0/16 as an example, you can modify the pod network.

  2. Make kubectl work on your non-root user

    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
    

    The above commands are also displayed in the output of kubeadm init

    Alternatively, if you are the root user

    export KUBECONFIG=/etc/kubernetes/admin.conf
    
  3. Install a pod network add-on(Here, we use Fannel to establish our pod network.)

    You must install a pod network add-on so that your pods can communicate with each other.

    kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
    

Join Node

  • Run the command which was displayed in the output of kubeadm init. It looks like the following command.
    sudo kubeadm join --token \{token\} \{master-ip\}:\{master-port\} --discovery-token-ca-cert-hash sha256:\{hash\}
    
  • If you forget the command displayed in the output of kubeadm init on the master node or the old one isn't work, then you can use the following command on the master node to generate a new one.
    sudo kubeadm token create --print-join-command
    

Delete Node

  • If we decide to delete Node2, then please follow the following instruction.
  1. Delete node2 on the master node
    kubectl drain node2 --delete-local-data --force --ignore-daemonsets
    kubectl delete node node2
    
  2. Reset node2 on the node2 node
    sudo kubeadm reset
    sudo ifconfig cni0 down
    sudo ip link delete cni0
    sudo ifconfig flannel.1 down
    sudo ip link delete flannel.1
    sudo rm -rf /var/lib/cni/
    
    After all done, Flush iptables.
    sudo iptables -F && sudo iptables -t nat -F && sudo iptables -t mangle -F && sudo iptables -X