-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.yaml
124 lines (110 loc) · 4.16 KB
/
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
---
- name: Install microk8s {{ microk8s_version }}
hosts: localhost
connection: local
vars_files: vars.yaml
tasks:
- name: Install snap package
become: true
community.general.snap:
name: microk8s
classic: true
channel: "{{ microk8s_version }}"
- name: Ensure microk8s group
become: true
check_mode: false
ansible.builtin.group:
name: microk8s
- name: Add user to microk8s group
become: true
ansible.builtin.user:
name: "{{ ansible_env.USER }}"
append: true
groups: microk8s
- name: Create aliases and ENVs
become: true
ansible.builtin.blockinfile:
path: /etc/profile.d/microk8s.sh
create: true
owner: root
group: root
mode: "0644"
marker: "# {mark} ANSIBLE MANAGED BY https://github.com/OlGe404/microk8s"
block: |
alias mk8s='microk8s'
alias mktoken='microk8s kubectl get secret kubernetes-dashboard-admin-token -n kubernetes-dashboard -o jsonpath={'.data.token'} | base64 -d | awk "{print $1}"'
{% if microk8s_manage_kubectl %}
alias kubectl='microk8s kubectl'
{% else %}
alias mkctl='microk8s kubectl'
{% endif %}
alias mkns='_mkns(){ microk8s kubectl config set-context microk8s --namespace "$1" ;}; _mkns'
{% if microk8s_manage_kubeconfig %}
export KUBECONFIG='{{ microk8s_kubeconfig }}'
{% endif %}
- name: Get kubeconfig file output
become: true
ansible.builtin.command: microk8s kubectl config view --raw
register: kubeconfig
- name: Create kubeconfig file from output
ansible.builtin.blockinfile:
path: "{{ microk8s_kubeconfig }}"
create: true
owner: "{{ ansible_env.USER }}"
mode: "0600"
marker: "# {mark} ANSIBLE MANAGED BY https://github.com/OlGe404/microk8s"
block: "{{ kubeconfig.stdout }}"
- name: Start microk8s
become: true
ansible.builtin.command: /snap/bin/microk8s.start
- name: Wait for microk8s to be ready
become: true
ansible.builtin.command: /snap/bin/microk8s.status --wait-ready
- name: "Enable microk8s add-ons {{ microk8s_add_ons | join(', ') }}"
become: true
ansible.builtin.command: "microk8s enable {{ item }}"
with_items: "{{ microk8s_add_ons }}"
- name: Community addons
when: microk8s_community_addons | length > 0
block:
- name: Enable community addons repo
become: true
ansible.builtin.command: microk8s enable community
- name: "Install community add-ons {{ microk8s_community_addons | join(', ') }}"
become: true
ansible.builtin.command: "microk8s enable {{ item }}"
with_items: "{{ microk8s_community_addons }}"
- name: Add kubernetes-dashboard helm repo
tags: dashboard
kubernetes.core.helm_repository:
name: kubernetes-dashboard
url: https://kubernetes.github.io/dashboard/
- name: Install kubernetes-dashboard
tags: dashboard
when: not ansible_check_mode
kubernetes.core.helm:
kubeconfig: "{{ microk8s_kubeconfig }}"
release_name: kubernetes-dashboard
release_namespace: kubernetes-dashboard
create_namespace: true
chart_ref: kubernetes-dashboard/kubernetes-dashboard
chart_version: "7.4.0"
values_files: dashboard-values.yaml
- name: Wait for kubernetes-dashboard rollout to finish
tags: dashboard
become: true
ansible.builtin.command: >-
microk8s kubectl rollout status deploy/{{ item }}
--namespace kubernetes-dashboard --watch --timeout=180s
with_items:
- kubernetes-dashboard-api
- kubernetes-dashboard-auth
- kubernetes-dashboard-kong
- kubernetes-dashboard-metrics-scraper
- kubernetes-dashboard-web
- name: Print kubernetes-dashboard infos
tags: dashboard
ansible.builtin.debug:
msg: >-
You can now access the kubernetes-dashboard at: http://localhost:30001.
Run 'source /etc/profile.d/microk8s.sh' and 'mktoken' to retrieve your login token.