-
Notifications
You must be signed in to change notification settings - Fork 6
/
kmaster.yml
99 lines (86 loc) · 2.65 KB
/
kmaster.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
---
- hosts: masters
vars:
- master_ip_nw: '192.168.1.0/24'
tasks:
- name: Ensure Kubernetes APT key is present
apt_key:
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
state: present
become: true
- name: Ensure Kubernetes APT Repo is present
apt_repository:
repo: deb http://apt.kubernetes.io/ kubernetes-xenial main
state: present
become: true
- name: Ensure Docker APT key is present
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
become: true
- name: Ensure Docker APT Repo is present
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
state: present
become: true
- name: Update cache
apt:
update_cache: true
upgrade: true
become: true
- name: Install container runtime
apt:
name: docker-ce
become: true
- name: Install kubelet kubeadm kubectl
apt:
name:
- kubelet
- kubeadm
- kubectl
state: present
become: true
- name: Pick IP from the same network as master
set_fact: hostip="{{ ansible_all_ipv4_addresses|ipaddr(master_ip_nw) }}"
- name: Send bridge packets to iptables for processing
block:
- lineinfile:
path: /etc/sysctl.conf
line: net.bridge.bridge-nf-call-iptables=1
create: yes
- lineinfile:
path: /etc/sysctl.conf
line: net.bridge.bridge-nf-call-ip6tables=1
create: yes
- command: sysctl net.bridge.bridge-nf-call-iptables=1
- command: sysctl net.bridge.bridge-nf-call-ip6tables=1
become: true
- name: Check cluster state
command: kubeadm token list
register: inited
ignore_errors: true
become: true
- name : Ensure no stale data is present
block:
- file: path=/var/lib/etcd state=absent
- file: path=/var/lib/etcd state=directory
when: inited.rc > 0
become: true
- name: Create /etc/default/kubelet with extra args
template:
src: kubelet.j2
dest: /etc/default/kubelet
become: true
- name: Initialize cluster
command: kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address "{{ hostip[0] }}"
when: inited.rc > 0
become: true
- name: Copy admin conf
block:
- copy:
src: /etc/kubernetes/admin.conf
remote_src: true
dest: "{{ ansible_env.HOME }}"
owner: "{{ ansible_env.USER }}"
group: "{{ ansible_env.USER }}"
become: true