-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yml
126 lines (108 loc) · 3.3 KB
/
playbook.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
- name: Install Container Runtime on All Nodes
hosts: all_server
become: true
tasks:
- name: Install required system packages
apt:
pkg:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- gnupg-agent
state: latest
# update_cache: yes
force_apt_get: yes
- name: Set modprobe
command:
argv:
- modprobe
- br_netfilter
- overlay
- name: add sysctl config
shell: |
cat <<EOF | sudo tee /etc/sysctl.d/k8s-cri.conf
net.bridge.bridge-nf-call-iptables=1
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-ip6tables=1
EOF
- name: save sysctl config
command: sysctl --system
- name: Disable swap
command: swapoff -a
- name: Install containerd
apt:
pkg:
- containerd
state: latest
# update_cache: yes
- name: Configure Containerd
shell: |
mkdir -p /etc/containerd
containerd config default | tee /etc/containerd/config.toml
sed -i s/'SystemdCgroup = false'/'SystemdCgroup = true'/g /etc/containerd/config.toml
- name: Restart containerd & daemon-reload
systemd:
daemon_reload: yes
name: containerd
state: restarted
enabled: yes
- name: Add repo & install kubernetes all Nodes
hosts: all_server
become: true
vars:
kube_version: 1.27.1-00
tasks:
- name: Add Kubernetes repo gpg key
apt_key:
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
state: present
- name: Add kubernetes repo
apt_repository:
repo: deb https://apt.kubernetes.io/ kubernetes-xenial main
state: present
- name: Install kubectl on master node
when: inventory_hostname in groups['master']
apt:
pkg:
- kubectl={{ kube_version }}
- name: Install kubernetes component all nodes
apt:
pkg:
- kubeadm={{ kube_version }}
- kubelet={{ kube_version }}
- name: Setup cluster on master node
hosts: master
gather_facts: false
become: true
vars:
pod_cidr: 10.244.0.0/16
cri_sock: /run/containerd/containerd.sock
tasks:
- name: Initialize cluster
command: kubeadm init --pod-network-cidr={{pod_cidr}} --cri-socket {{cri_sock}} --control-plane-endpoint {{hostvars[inventory_hostname].groups.master[0]}}:6443
register: init_output
- debug:
var: init_output.stdout_lines
- name: create join command on master node
command: kubeadm token create --print-join-command
register: command
- name: Store join command to variable
add_host:
name: "join_command"
hostname: "{{hostvars[inventory_hostname].groups.master[0]}}"
commandnya: "{{command.stdout}}"
- debug:
msg: "Join command: {{command.stdout}}"
- name: Worker join master
hosts: worker
gather_facts: false
become: true
vars:
joinnya: "{{ hostvars['join_command']['commandnya'] }}"
tasks:
- name: Kubeam join master
command: "{{joinnya}}"
register: result_join
- debug:
msg: "{{result_join}}"