From a0d2bda742be603454ba28e3858ab066a79ea561 Mon Sep 17 00:00:00 2001 From: ABW <49398549+chrxmvtik@users.noreply.github.com> Date: Mon, 19 Feb 2024 11:47:36 +0100 Subject: [PATCH] feat/add default ingress-nginx service (#10925) feat/add default ingress-nginx service feat/add default ingress-nginx service feat/add default ingress-nginx service --- .../sample/group_vars/k8s_cluster/addons.yml | 1 + .../ingress_nginx/defaults/main.yml | 1 + .../ingress_nginx/tasks/main.yml | 7 ++++++ .../templates/svc-ingress-nginx.yml.j2 | 24 +++++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 roles/kubernetes-apps/ingress_controller/ingress_nginx/templates/svc-ingress-nginx.yml.j2 diff --git a/inventory/sample/group_vars/k8s_cluster/addons.yml b/inventory/sample/group_vars/k8s_cluster/addons.yml index e57f8a725..5fc115fc6 100644 --- a/inventory/sample/group_vars/k8s_cluster/addons.yml +++ b/inventory/sample/group_vars/k8s_cluster/addons.yml @@ -99,6 +99,7 @@ rbd_provisioner_enabled: false # Nginx ingress controller deployment ingress_nginx_enabled: false # ingress_nginx_host_network: false +# ingress_nginx_service_type: LoadBalancer ingress_publish_status_address: "" # ingress_nginx_nodeselector: # kubernetes.io/os: "linux" diff --git a/roles/kubernetes-apps/ingress_controller/ingress_nginx/defaults/main.yml b/roles/kubernetes-apps/ingress_controller/ingress_nginx/defaults/main.yml index 7a5c13488..c83c8c3ed 100644 --- a/roles/kubernetes-apps/ingress_controller/ingress_nginx/defaults/main.yml +++ b/roles/kubernetes-apps/ingress_controller/ingress_nginx/defaults/main.yml @@ -1,6 +1,7 @@ --- ingress_nginx_namespace: "ingress-nginx" ingress_nginx_host_network: false +ingress_nginx_service_type: LoadBalancer ingress_publish_status_address: "" ingress_nginx_nodeselector: kubernetes.io/os: "linux" diff --git a/roles/kubernetes-apps/ingress_controller/ingress_nginx/tasks/main.yml b/roles/kubernetes-apps/ingress_controller/ingress_nginx/tasks/main.yml index b67a17f39..ac64c8242 100644 --- a/roles/kubernetes-apps/ingress_controller/ingress_nginx/tasks/main.yml +++ b/roles/kubernetes-apps/ingress_controller/ingress_nginx/tasks/main.yml @@ -24,6 +24,8 @@ - { name: rolebinding-ingress-nginx, file: rolebinding-ingress-nginx.yml, type: rolebinding } - { name: ingressclass-nginx, file: ingressclass-nginx.yml, type: ingressclass } - { name: ds-ingress-nginx-controller, file: ds-ingress-nginx-controller.yml, type: ds } + ingress_nginx_template_for_service: + - { name: svc-ingress-nginx, file: svc-ingress-nginx.yml, type: svc } ingress_nginx_templates_for_webhook: - { name: admission-webhook-configuration, file: admission-webhook-configuration.yml, type: sa } - { name: sa-admission-webhook, file: sa-admission-webhook.yml, type: sa } @@ -33,6 +35,11 @@ - { name: rolebinding-admission-webhook, file: rolebinding-admission-webhook.yml, type: rolebinding } - { name: admission-webhook-job, file: admission-webhook-job.yml, type: job } +- name: NGINX Ingress Controller | Append extra templates to NGINX Ingress Template list for service + set_fact: + ingress_nginx_templates: "{{ ingress_nginx_templates + ingress_nginx_template_for_service }}" + when: not ingress_nginx_host_network + - name: NGINX Ingress Controller | Append extra templates to NGINX Ingress Templates list for webhook set_fact: ingress_nginx_templates: "{{ ingress_nginx_templates + ingress_nginx_templates_for_webhook }}" diff --git a/roles/kubernetes-apps/ingress_controller/ingress_nginx/templates/svc-ingress-nginx.yml.j2 b/roles/kubernetes-apps/ingress_controller/ingress_nginx/templates/svc-ingress-nginx.yml.j2 new file mode 100644 index 000000000..115232f01 --- /dev/null +++ b/roles/kubernetes-apps/ingress_controller/ingress_nginx/templates/svc-ingress-nginx.yml.j2 @@ -0,0 +1,24 @@ +{% if not ingress_nginx_host_network %} +apiVersion: v1 +kind: Service +metadata: + name: ingress-nginx + namespace: {{ ingress_nginx_namespace }} + labels: + app.kubernetes.io/name: ingress-nginx + app.kubernetes.io/part-of: ingress-nginx +spec: + type: {{ ingress_nginx_service_type }} + ports: + - name: http + port: 80 + targetPort: 80 + protocol: TCP + - name: https + port: 443 + targetPort: 443 + protocol: TCP + selector: + app.kubernetes.io/name: ingress-nginx + app.kubernetes.io/port-of: ingress-nginx +{% endif %}