-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.yml
199 lines (184 loc) · 5.02 KB
/
site.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
---
- hosts: all
gather_facts: no
become: true
become_method: sudo
tags:
- upgrade
roles:
- docker
tasks:
- name: Upgrade all deps
apt:
update_cache: yes
upgrade: dist
autoremove: yes
- name: Make sure installed/latest ca-certificates
apt:
name: ca-certificates
state: latest
- name: Prerestart the box
command: /sbin/shutdown -r +1
async: 0
poll: 0
- name: Wait for PI to come back after upgrade
local_action: wait_for
args:
host: "{{ ansible_ssh_host }}"
port: 22
state: started
delay: 70
timeout: 300
post_tasks:
- name: Remove dependencies that are no longer required
apt:
autoremove: yes
- name: Remove useless packages from the cache
apt:
autoclean: yes
- hosts: all
gather_facts: no
become: true
become_method: sudo
tags:
- setup
roles:
- common
- docker
- { role: k8s, tags: ['k8s'] }
tasks:
- name: Pass bridged IPv4 traffic to iptables chains
sysctl:
name: net.bridge.bridge-nf-call-iptables
value: 1
sysctl_set: yes
- name: run docker
command: docker ps
register: install_docker_ps
tags:
- test
- name: run docker
debug:
msg: '{{ install_docker_ps }}'
tags:
- test
post_tasks:
- name: Remove dependencies that are no longer required
apt:
autoremove: yes
- name: Remove useless packages from the cache
apt:
autoclean: yes
- hosts: master
gather_facts: yes
become: true
become_method: sudo
tags:
- k8s
- install
tasks:
- name: Generate kubeadm token
command: kubeadm token generate
register: kubeadm_token_generate
- name: Set kubeadm token
set_fact:
kubeadm_token: '{{ kubeadm_token_generate.stdout }}'
- name: Debug 'kubeadm init' info
debug:
msg: 'command to run: kubeadm init --token={{ kubeadm_token }} --apiserver-advertise-address={{ ansible_default_ipv4.address }} --pod-network-cidr 172.30.0.0/16'
- name: Kube init
command: 'kubeadm init --token={{ kubeadm_token }} --apiserver-advertise-address={{ ansible_default_ipv4.address }} --pod-network-cidr 172.30.0.0/16'
register: kubeadm_init_command
- name: kubeadm output
debug:
msg: '{{ kubeadm_init_command.stdout_lines }}'
- name: Reload systemd files on Master
systemd:
daemon_reload: yes
- name: Get k8s version
command: bash -c "kubectl version | base64 | tr -d '\n'"
register: kubectl_version_command
- name: Download flannel
get_url:
url: https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
dest: /tmp/kube-flannel.yml
force: yes
- name: Fix flannel yml
replace:
path: /tmp/kube-flannel.yml
regexp: 'amd64'
replace: 'arm'
- name: Install flannel
command: kubectl create -f /tmp/kube-flannel.yml
environment:
KUBECONFIG: /etc/kubernetes/admin.conf
# - name: Install weave
# command: "kubectl apply -f 'https://cloud.weave.works/k8s/net?k8s-version={{ kubectl_version_command.stdout }}&env.IPALLOC_RANGE=172.30.0.0/16'"
# environment:
# KUBECONFIG: /etc/kubernetes/admin.conf
- name: Try kubectl
command: kubectl get pods -o wide
environment:
KUBECONFIG: /etc/kubernetes/admin.conf
register: kubectl_get_pods
- name: Debug 'kubectl get pods'
debug:
msg: '{{ kubectl_get_pods.stdout_lines }}'
- hosts: master
gather_facts: no
become: true
become_method: sudo
tags:
- k8s
- install
- join
tasks:
- name: Get join command
command: kubeadm token create --print-join-command
environment:
KUBECONFIG: /etc/kubernetes/admin.conf
register: kubeadm_join_command_generate
- hosts: nodes
gather_facts: no
become: true
become_method: sudo
serial: 1
tags:
- k8s
- install
- join
tasks:
- name: Join Cluster command
debug:
msg: "Command to run: {{ hostvars[groups['master'][0]].kubeadm_join_command_generate.stdout }}"
- name: Join cluster
command: "{{ hostvars[groups['master'][0]].kubeadm_join_command_generate.stdout }}"
- name: Reload systemd files on Nodes
systemd:
daemon_reload: yes
- hosts: master
gather_facts: no
become: true
become_method: sudo
tags:
- k8s
- status
- test
- join
tasks:
- name: Check nodes
command: kubectl get nodes
register: kubectl_check
environment:
KUBECONFIG: /etc/kubernetes/admin.conf
- name: Print kubectl check
debug:
msg: '{{ kubectl_check.stdout_lines }}'
- name: Check pods
command: kubectl get pods -o wide --namespace=kube-system
register: kubectl_check
environment:
KUBECONFIG: /etc/kubernetes/admin.conf
- name: Print kubectl check
debug:
msg: '{{ kubectl_check.stdout_lines }}'