K8s worker nodes Join to control plane - Ansible

So far in previous tutorials, we have deployed our multi-master Kubernetes control plane using ansible and now we are going to add the worker nodes to the cluster in a simple way.

Step1: Add the worker nodes to the control plane. Below YAML file is executing from Ansible-master.

cat <<EOF> worker_nodes_join.yaml

- name: "generate the kubdeadm join command"     
  hosts: master1 #Ideal way is to run from Loadbalancer if Kubectl and kubeconfig available to run \
                 # genarate command, Here I am using master1 for demo purpose
  become: yes
  tasks:
       - name: "execute the kubeadm command"
         shell: "kubeadm token create --print-join-command"
         register: join_worker_command
       - name: " set the facts to pull from different plays"
         set_fact:
              join_worker_command: "{{join_worker_command.stdout_lines[0]}}"

- name: "join the worker nodes to control plane"                
  hosts: worker
  become: yes
  tasks:
      - name: "join all workers"
        shell: "{{hostvars['master1'].join_worker_command}}"

      - local_action: copy content={{workerjoin.stdout}} dest="./join_workers"
EOF
 
Step2: Validate from the controller machine(from where you have planned to administrate the cluster)

$ kubectl get nodes

As we expected our worker nodes had joined the cluster successfully.

Our Initial goal of Installing the High available cluster with multi-master is successful and from now on we can start working on deploying the application(microservices) via Kubernetes primitives(Deployment, replica set, replication controller, Daemonsets, Pods, etc..)



Comments

Popular Posts