Kubernetes attach additional Slaves to master

Below are the steps to be followed to attach the additional slaves to an existing kubernetes cluster.

Execute below commands in Kubernetes (new) Slave:

  1. kubectl run -i --tty ubuntu --rm --image=ubuntu --restart=Never --overrides='
  2. apt-get update && apt-get install -y apt-transport-https
  3. curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
  4. cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
    deb http://apt.kubernetes.io/ kubernetes-xenial main
    EOF
  5. curl -fsSL 'https://sks-keyservers.net/pks/lookup?op=get&search=0xee6d536cf7dc86e2d7d56f59a178ac6c6238f52e' | sudo apt-key add -
  6. sudo add-apt-repository \
    "deb https://packages.docker.com/1.13/apt/repo/ \
    ubuntu-$(lsb_release -cs) \
    main"
  7. apt-get update
  8. apt-get -y install docker-engine
  9.        Run docker as daemon in as given below (if required):   

             Open /lib/systemd/system/docker.service and add the below line and save the file:

              ExecStart=/usr/bin/dockerd -H fd:// -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2376 $DOCKER_OPTS

              Execute the following commands to reload and restart docker

              systemctl daemon-reload
              systemctl restart docker

  10. apt-get install -y kubeadm=1.9.4-00 kubectl=1.9.4-00 kubelet=1.9.4-00 kubernetes-cni
  11. service kubelet start

To know the K8s cluster join token:

To get the join command, execute the below command in Kubernetes Master.

Command: kubeadm token create --print-join-command

Result: kubeadm join --token 8xxxxa.6axxxxda3xxx0fx4 <<master-ip>>:6443 --discovery-token-ca-cert-hash sha256:a54ab1234e247eeb36ba772eb442b507b0a1234f8b1234567df1234567890c01

Reference: https://linuxacademy.com/community/posts/show/topic/25431-tip-kubeadm-print-join-command