-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinstall-and-configure-minikube.yaml
123 lines (107 loc) · 4.35 KB
/
install-and-configure-minikube.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
---
- name: Install and configure Minikube
hosts: all
gather_facts: false
vars:
service_file_location: /etc/systemd/system/minikube.service
service_name_minikube: minikube.service
port_expose_file_location: /etc/minikube-apiserver-port-forward.conf
tasks:
- name: Generate minikube file name
command: "echo -n minikube_latest_{{ architecture }}.deb"
register: minikube_file_name
- name: Install Minikube
# https://minikube.sigs.k8s.io/docs/start/
block:
- name: Download minikube package
shell: "curl -LO https://storage.googleapis.com/minikube/releases/latest/{{ minikube_file_name.stdout }}"
- name: Install minikube
become: true
shell: "dpkg -i {{ minikube_file_name.stdout }}"
- name: Delete minikube package
file:
path: "{{ minikube_file_name.stdout }}"
state: absent
- name: Setup and enable systemd service
block:
- name: Copy over the service file for systemd
become: true
copy:
src: minikube_config/{{ service_name_minikube }}
dest: "{{ service_file_location }}"
- name: "Service file edit: Add command to start minikube"
become: true
lineinfile:
path: "{{ service_file_location }}"
regexp: '^ExecStartPre=(.*)$'
line: 'ExecStartPre=/usr/bin/minikube start --embed-certs=true --mount --mount-string "{{ dir_home }}:{{ dir_minikube_mount }}" --cpus="{{ minikube.cpus }}" --memory="{{ minikube.memory }}" --disk-size="{{ minikube.disk_size }}" --nodes="{{ minikube.nodes }}" --cert-expiration="{{ minikube.cert_expiration }}"'
backrefs: yes
- name: "Service file edit: Add reverse proxy script"
become: true
lineinfile:
path: "{{ service_file_location }}"
regexp: '^ExecStart=(.*)$'
line: "ExecStart=kubectl proxy --address='0.0.0.0' --port={{ api_server_forwarded_port }} --accept-hosts='.*'"
backrefs: yes
- name: "Service file edit: Change User to be {{ ansible_user }}"
become: True
# https://gist.github.com/drmalex07/c0f9304deea566842490
lineinfile:
path: "{{ service_file_location }}"
regexp: '^User=(.*)$'
line: "User={{ ansible_user }}"
backrefs: yes
- name: Reload systemd service
include_tasks: tasks-reload-systemd-service.yaml
vars:
service_name: "{{ service_name_minikube }}"
become: True
- name: Minikube notes
debug:
msg: >
Directory '{{ dir_home }}' mounted on the minikube container at
'{{ dir_minikube_mount }}' with UID '{{ uid }}''.
More info https://github.com/kubernetes/minikube/pull/8159"
- name: Setup nginx ingress controller
block:
- name: Enable nginx ingress controller in minikube
shell: minikube addons enable ingress
retries: 100000
delay: 10
register: result
until: result.rc == 0
- name: Expose nginx ingress controller
include_tasks: tasks-kubernetes-port-forward-service.yaml
vars:
service_name: SKIP
service_file_name: nginx-ingress-controller.service
service_file_location_base: /etc/systemd/system/
host_port: 8080
service_port: 80
- name: Expose nginx ingress controller for SSL
include_tasks: tasks-kubernetes-port-forward-service.yaml
vars:
service_name: SKIP
service_file_name: nginx-ingress-controller-ssl.service
service_file_location_base: /etc/systemd/system/
host_port: 8081
service_port: 443
- name: Allow ports '8080' and '8081' for nginx
include_tasks: tasks-allow-ports.yaml
vars:
ports:
- "8080"
- "8081"
- debug:
msg: You can access the ingress controller at port '8080' and '8081' for HTTP and HTTPS.
- name: "Allow port '{{ api_server_forwarded_port }}' for api server"
include_tasks: tasks-allow-ports.yaml
vars:
ports:
- "{{ api_server_forwarded_port }}"
- name: Wait till minikube is running
shell: minikube status
retries: 100000
delay: 10
register: result
until: result.rc == 0