-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook-k8s.yml
93 lines (79 loc) · 2.89 KB
/
playbook-k8s.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
---
- hosts: all
any_errors_fatal: true
tasks:
- name: update hosts file
lineinfile:
dest: /etc/hosts
line: "{{ hostvars[item].ansible_eth1.ipv4.address }} {{ item }}"
regexp: '.*{{ item }}$'
loop: "{{ groups.all }}"
- name: update host name
hostname:
name: "{{ inventory_hostname }}"
- name: disable swap fstab
mount:
name: "{{ item }}"
fstype: swap
state: absent
loop:
- /swap.img
- hosts: control[0]
any_errors_fatal: true
tasks:
- name: initialize the cluster
command: 'kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address={{ ansible_eth1.ipv4.address }}'
args:
creates: /root/cluster_initialized.txt
register: kubeadm_init_raw
- name: save kubeadm init output to a file
copy:
content: "stdout:\n{{ kubeadm_init_raw.stdout }}\n\nstderr:\n{{ kubeadm_init_raw.stderr }}"
dest: /root/cluster_initialized.txt
when: kubeadm_init_raw.changed
- name: copy auth, install cni, ingress
ansible.builtin.shell: |
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
#kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.29.1/manifests/tigera-operator.yaml
#kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.29.1/manifests/custom-resources.yaml
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.12.0-beta.0/deploy/static/provider/cloud/deploy.yaml
args:
creates: /root/k8s_cni_initialized.txt
register: k8s_cni_init_raw
- name: save cni init output to a file
copy:
content: "stdout:\n{{ k8s_cni_init_raw.stdout }}\n\nstderr:\n{{ k8s_cni_init_raw.stderr }}"
dest: /root/k8s_cni_initialized.txt
when: k8s_cni_init_raw.changed
- name: get join command
command: kubeadm token create --print-join-command
register: join_command_raw
changed_when: no
- name: set join command
set_fact:
join_command: "{{ join_command_raw.stdout_lines[0] }}"
- hosts: worker
any_errors_fatal: true
vars:
join_command: "{{ hostvars['vagrant-control-01'].join_command }}"
tasks:
- name: join cluster
command: "{{ join_command }}"
args:
creates: /root/node_joined.txt
register: kubeadm_join_raw
- name: save kubeadm join output to a file
copy:
content: "stdout:\n{{ kubeadm_join_raw.stdout }}\n\nstderr:\n{{ kubeadm_join_raw.stderr }}"
dest: /root/node_joined.txt
when: kubeadm_join_raw.changed
- hosts: all
any_errors_fatal: true
tasks:
- name: kubelet service
service:
name: kubelet
enabled: yes
state: started