-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk8s_install.yaml
153 lines (126 loc) · 3.79 KB
/
k8s_install.yaml
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
---
- hosts: kubernetes
remote_user: centos
become: yes
become_method: sudo
become_user: root
gather_facts: yes
connection: ssh
tasks:
- name: "Update system with Latest Packages"
ansible.builtin.yum:
name: "*"
state: latest
- name: "restart system to reboot to newest kernel"
shell: "sleep 10 && reboot"
async: 1
poll: 0
- name: "wait for 10 seconds"
pause:
seconds: 20
- name: "wait for the system to reboot"
wait_for_connection:
connect_timeout: 20
sleep: 10
delay: 10
timeout: 60
- name: Create containerd config file
file:
path: "/etc/modules-load.d/containerd.conf"
state: "touch"
- name: Add conf for containerd
blockinfile:
path: "/etc/modules-load.d/containerd.conf"
block: |
overlay
br_netfilter
- name: modprobe
shell: |
sudo modprobe overlay
sudo modprobe br_netfilter
- name: Set system configurations for Kubernetes networking
file:
path: "/etc/sysctl.d/99-kubernetes-cri.conf"
state: "touch"
- name: Add conf for containerd
blockinfile:
path: "/etc/sysctl.d/99-kubernetes-cri.conf"
block: |
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
- name: Apply new settings
command: sudo sysctl --system
- name: "Install Docker as a Container Runtime"
ansible.builtin.get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: /etc/yum.repos.d/docker-ce.repo
- name: "Install Docker Packages with containerd Container Runtime"
ansible.builtin.yum:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
- epel-release
state: present
- name: "Enable and Start the Docker"
ansible.builtin.systemd:
name: docker
state: started
enabled: true
- name: "Enable and Start the Containerd"
ansible.builtin.systemd:
name: containerd
state: started
enabled: true
- name: "Remove config.tom File"
ansible.builtin.file:
path: /etc/containerd/config.tom
state: absent
- name: "Restart Containerd Service to take effect"
ansible.builtin.systemd:
name: containerd
state: restarted
enabled: true
# - name: disable swap
# shell: |
# sudo swapoff -a
# sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
# - name: install and configure dependencies
# shell: |
# sudo yum update && sudo yum install -y apt-transport-https curl
# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
- name: Create kubernetes repo file
file:
path: "/etc/yum.repos.d/kubernetes.repo"
state: "touch"
- name: Add K8s Source
ansible.builtin.blockinfile:
path: "/etc/yum.repos.d/kubernetes.repo"
block: |
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
- name: "Verification if Repository File is properly created or not"
ansible.builtin.command:
cmd: "cat /etc/yum.repos.d/kubernetes.repo"
register: file_content
- name: "Content Redirection to Output"
debug:
var: file_content
- name: install kubernetes
ansible.builtin.yum:
name:
- kubeadm
- kubelet
- kubectl
disable_excludes: kubernetes
- name: "Start and Enable Kubernetes"
ansible.builtin.systemd:
name: kubelet
enabled: true