-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster.yaml
More file actions
81 lines (70 loc) · 2.55 KB
/
master.yaml
File metadata and controls
81 lines (70 loc) · 2.55 KB
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
---
- hosts: kube_master
become: yes
tasks:
- name: Remove /etc/containerd/config.toml file
ansible.builtin.file:
path: /etc/containerd/config.toml
state: absent
- name: Ensure containerd service is running and enabled
ansible.builtin.service:
name: containerd
state: started
enabled: yes
- name: Open required ports in firewall
ansible.builtin.firewalld:
port: "{{ item }}"
state: enabled
permanent: yes
with_items:
- 6443/tcp
- 10250/tcp
notify: reload firewalld
- name: Reset kubeadm
ansible.builtin.command: kubeadm reset -f
ignore_errors: yes # Ignore errors if kubeadm has not been initialized yet
- name: Remove Kubernetes configuration files
ansible.builtin.file:
path: "{{ item }}"
state: absent
with_items:
- /etc/kubernetes/admin.conf
- /etc/kubernetes/kubelet.conf
- /etc/kubernetes/bootstrap-kubelet.conf
- /etc/kubernetes/kubelet.conf.old
- /etc/kubernetes/bootstrap-kubelet.conf.old
- /etc/kubernetes/kubelet.env
- /etc/kubernetes/pki
- name: Initialize Kubernetes control-plane node
command: >
sudo kubeadm init --apiserver-advertise-address=192.168.0.106 --pod-network-cidr=10.244.0.0/16
environment:
KUBECONFIG: /etc/kubernetes/admin.conf
register: kubeadm_init_output
ignore_errors: yes
- name: Set up kubectl configuration for local user
ansible.builtin.copy:
src: /etc/kubernetes/admin.conf
dest: "/root/.kube/config"
remote_src: yes
when: kubeadm_init_output.rc == 0
- name: Restart Kubelet and containerd
ansible.builtin.command: sudo kubectl get nodes
- name: Restart Kubelet and containerd
ansible.builtin.command: sudo kubectl get pods --all-namespaces
- name: Deploy Flannel CNI
ansible.builtin.command: sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
environment:
KUBECONFIG: /etc/kubernetes/admin.conf
when: kubeadm_init_output.rc == 0
- name: Restart Kubelet and containerd
ansible.builtin.command: sudo systemctl restart containerd.service && sudo systemctl restart kubelet
- name: Ensure kubelet service is started and enabled
ansible.builtin.service:
name: kubelet
state: started
enabled: yes
handlers:
- name: reload firewalld
ansible.builtin.firewalld:
state: reload