Home |

Trigat

3_join.yml

09-29-2019

Ansible playbooks for building Kubernetes cluster.
Make sure Docker is install and configured.

Add your Master and Worker nodes to the hosts file:
###################################
[master]
master ansible_host=10.1.140.11

[workers]
worker1 ansible_host=10.1.140.12
worker2 ansible_host=10.1.140.13
###################################

Run each playbook in order:
1_depend.yml
2_prepare.yml
3_join.yml

Specify the username for your servers.
Example command:

sudo ansible-playbook /etc/ansible/kube_cluster/1_depend.yml --user MyUser --ask-pass --ask-become-pass

Language or Platform: Python

Code:

- hosts: master
  become: true
  gather_facts: false
  tasks:
    - name: get join command
      shell: kubeadm token create --print-join-command
      register: join_command_raw

    - name: set join command
      set_fact:
        join_command: "{{ join_command_raw.stdout_lines[0] }}"


- hosts: workers
  become: true
  tasks:
    - name: join cluster
      shell: "{{ hostvars['master'].join_command }} >> node_status.txt"
      args:
        chdir: $HOME
        creates: node_status.txt

    - debug:
        msg: "Wait a couple minutes for node to join."

Back