/
k8s_comasters.yml
110 lines (93 loc) · 3.25 KB
/
k8s_comasters.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# k8s_workers.yml
---
# add masters into hosts as ip address of k8scp should be changed for main master as well in /etc/hosts
- hosts: comasters
remote_user: "{{ ansible_user }}"
become: yes
become_method: sudo
become_user: root
gather_facts: yes
connection: ssh
roles:
- atomika_base
- hosts: proxies
vars:
comaster_names: "{{ query('inventory_hostnames', 'comasters') }}"
tasks:
- name: Deploy and configure HAProxy
ansible.builtin.import_tasks: ha_proxy.yml
- hosts: masters
tasks:
- name: Get the token for joining the nodes with Kubernetes master.
become_user: "{{ ansible_user }}"
shell: kubeadm token create --print-join-command
register: kubernetes_join_command
# - debug:
# msg: "{{ kubernetes_join_command.stdout }}"
- name: Generate the secret for joining the nodes with Kubernetes master.
become: yes
shell: kubeadm init phase upload-certs --upload-certs
register: kubernetes_join_secret
- name: Copy join command to local file.
become: false
local_action: copy content="{{ kubernetes_join_command.stdout_lines[0] }} --control-plane --certificate-key {{ kubernetes_join_secret.stdout_lines[2] }}" dest="/tmp/kubernetes_join_command" mode=0700
#local_action: copy content="{{ kubernetes_join_command.stdout_lines[0] }} --apiserver-advertise-address 192.168.68.122 --certificate-key {{ kubernetes_join_secret.stdout_lines[2] }}" dest="/tmp/kubernetes_join_command" mode=0700
- hosts: comasters
#remote_user: k8s5gc
become: yes
become_method: sudo
become_user: root
gather_facts: yes
connection: ssh
# TODO use set_facts instead - see kubectl_user for example
# first set it to main master so comasters can be joined to master and then later set k8scp to ip of haproxy TODO - is this required?
vars:
control_plane_endpoint: "{{ hostvars['host1']['ansible_host'] }}"
tasks:
- ansible.builtin.import_tasks: internal/i_set_cplb_endpoint.yml
- name: Copy join command to worker nodes.
become: yes
become_method: sudo
become_user: root
copy:
src: /tmp/kubernetes_join_command
dest: /tmp/kubernetes_join_command
mode: 0700
- name: Join the comasters with the master.
become: yes
become_method: sudo
become_user: root
command: sh /tmp/kubernetes_join_command
register: joined_or_not
- debug:
msg: "{{ joined_or_not.stdout }}"
- name: Copy kube config for designated users
ansible.builtin.import_tasks: internal/i_copy_kube_config.yml
- hosts: "masters,comasters,workers"
become: yes
become_method: sudo
become_user: root
gather_facts: yes
connection: ssh
# TODO use set_facts instead - see kubectl_user for example
vars:
control_plane_endpoint: "{{ hostvars['haproxy']['ansible_host'] }}"
tasks:
- name: Add endpoint of haproxy to hosts
ansible.builtin.import_tasks: internal/i_set_cplb_endpoint.yml
#- hosts: "masters,comasters"
# #remote_user: k8s5gc
# #become: yes
# #become_method: sudo
# become_user: root
# gather_facts: yes
# connection: ssh
#
# tasks:
#
# - name: Configure kubectl command auto-completion.
# lineinfile:
# dest: /home/{{ ansible_user }}/.bashrc
# line: 'source <(kubectl completion bash)'
# insertafter: EOF
...