-
Notifications
You must be signed in to change notification settings - Fork 77
/
30_install_ingress_controller.yml
166 lines (155 loc) · 6.49 KB
/
30_install_ingress_controller.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
---
- name: Prepare cluster to install ingress controller
hosts: vm_host
vars_files:
- vars/k8s_cluster.yml
run_once: true
tasks:
- name: Configure Ingress controller
when: ingress_controller.install_ingress_controller
block:
- name: Take all required steps to install contour as ingress controller
when:
- ingress_controller.type == 'contour'
block:
- name: Ensure the needed Namespaces exist.
kubernetes.core.k8s:
api_version: v1
kind: Namespace
name: projectcontour
kubeconfig: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
state: present
- name: Add helm chart repository for Contour
kubernetes.core.helm_repository:
name: "{{ item.name }}"
repo_url: "{{ item.repo_url }}"
loop:
- name: "{{ ingress.contour.chart.name }}"
repo_url: "{{ ingress.contour.chart.url }}"
- name: Ensure Contour helm chart is installed
kubernetes.core.helm:
name: contour
chart_ref: "{{ ingress.contour.chart.ref }}"
kubeconfig: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
release_namespace: projectcontour
update_repo_cache: true
values:
contour:
ingressClass: ""
replicaCount: 1
defaultBackend:
enabled: true
envoy:
kind: deployment
useHostPort: false
service:
externalTrafficPolicy: Cluster
type: NodePort
nodePorts:
http: "{{ ingress_controller.node_port.http }}"
https: "{{ ingress_controller.node_port.https }}"
wait: true
- name: Take all required steps to install haproxy as ingress controller
when:
- ingress_controller.type == 'haproxy'
block:
- name: Ensure the needed Namespaces exist.
kubernetes.core.k8s:
api_version: v1
kind: Namespace
name: haproxy-controller
kubeconfig: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
state: present
- name: Add helm chart repository for haproxy
kubernetes.core.helm_repository:
name: "{{ item.name }}"
repo_url: "{{ item.repo_url }}"
loop:
- name: "{{ ingress.haproxy.chart.name }}"
repo_url: "{{ ingress.haproxy.chart.url }}"
- name: Ensure haproxy helm chart is installed
kubernetes.core.helm:
name: haproxy
chart_ref: "{{ ingress.haproxy.chart.ref }}"
kubeconfig: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
release_namespace: haproxy-controller
values:
controller:
ingressClass: null
service:
type: NodePort
nodePorts:
http: "{{ ingress_controller.node_port.http }}"
https: "{{ ingress_controller.node_port.https }}"
stat: 31024
kind: Deployment
replicaCount: 1
update_repo_cache: true
wait: true
- name: Take all required steps to install Nginx as ingress controller
when:
- ingress_controller.type == 'nginx'
block:
- name: Ensure the needed Namespaces exist.
kubernetes.core.k8s:
definition:
api_version: v1
kind: Namespace
metadata:
name: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
kubeconfig: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
state: present
- name: Add helm chart repository for Nginx
kubernetes.core.helm_repository:
name: "{{ item.name }}"
repo_url: "{{ item.repo_url }}"
loop:
- name: "{{ ingress.nginx.chart.name }}"
repo_url: "{{ ingress.nginx.chart.url }}"
- name: Ensure Nginx helm chart is installed
kubernetes.core.helm:
name: nginx
chart_ref: "{{ ingress.nginx.chart.ref }}"
kubeconfig: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
release_namespace: ingress-nginx
values:
controller:
service:
type: NodePort
nodePorts:
http: "{{ ingress_controller.node_port.http }}"
https: "{{ ingress_controller.node_port.https }}"
update_repo_cache: true
wait: true
- name: Trigger new haproxy configuration
hosts: loadbalancer
become: true
vars_files:
- vars/k8s_cluster.yml
tasks:
- name: Configure HAProxy
when: ingress_controller.install_ingress_controller
block:
- name: Fire up new haproxy template
ansible.builtin.template:
src: templates/haproxy.j2
dest: /etc/haproxy/haproxy.cfg
mode: "0755"
- name: Restart haproxy
ansible.builtin.systemd:
name: haproxy
state: restarted
- name: Save new haproxy configuration
hosts: vm_host
become: true
vars_files:
- vars/k8s_cluster.yml
tasks:
- name: Save HAProxy configuration
ansible.builtin.template:
src: templates/haproxy.j2
dest: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/haproxy.cfg"
mode: "0755"