diff --git a/charts/application-ingress/Chart.yaml b/charts/application-ingress/Chart.yaml new file mode 100644 index 0000000..63b061f --- /dev/null +++ b/charts/application-ingress/Chart.yaml @@ -0,0 +1,18 @@ +apiVersion: v2 +name: ingress +version: 1.1.1 +description: A Helm chart for Ingress +type: application +home: https://github.com/technicaldomain/helm +sources: + - https://github.com/technicaldomain/helm +maintainers: + - email: alex@kharkevich.org + name: Alexander Kharkevich +icon: file://icon.png +appVersion: "1.0" + +dependencies: + - name: common + repository: https://technicaldomain.github.io/helm/ + version: 2.1.4 diff --git a/charts/application-ingress/icon.png b/charts/application-ingress/icon.png new file mode 100644 index 0000000..b15750a Binary files /dev/null and b/charts/application-ingress/icon.png differ diff --git a/charts/application-ingress/readme.md b/charts/application-ingress/readme.md new file mode 100644 index 0000000..ddf213a --- /dev/null +++ b/charts/application-ingress/readme.md @@ -0,0 +1,3 @@ +# Manage Ingress in a Simple Way + +See [values.yaml](./values.yaml) for more details diff --git a/charts/application-ingress/templates/ingress.yml b/charts/application-ingress/templates/ingress.yml new file mode 100644 index 0000000..ef33aa0 --- /dev/null +++ b/charts/application-ingress/templates/ingress.yml @@ -0,0 +1,65 @@ +{{- $fullName := include "common.fullname" . }} +{{- $appLabels := include "common.labels.standard" . -}} +{{- range .Values.services }} +{{- $contextPath := .contextPath }} +{{- $serviceName := .name }} +{{- $servicePort := .port | default 80 }} +{{- $annotations := .annotations }} +{{- $useRewrite := .useRewrite }} +{{- $ingressClass := .ingressClass | default $.Values.ingressClass | default "traefik" }} +{{- /* Define default annotations */}} +{{- $defaultAnnotations := dict }} +{{- if eq $ingressClass "nginx" }} +{{- $_ := set $defaultAnnotations "kubernetes.io/ingress.class" "nginx" }} +{{- $_ := set $defaultAnnotations "nginx.ingress.kubernetes.io/service-upstream" "true" }} +{{- $_ := set $defaultAnnotations "nginx.ingress.kubernetes.io/upstream-vhost" (printf "%s.%s.svc.cluster.local" $serviceName $.Release.Namespace) }} +{{- $_ := set $defaultAnnotations "nginx.ingress.kubernetes.io/use-regex" "true" }} +{{- if (default $useRewrite false) }} +{{- $_ := set $defaultAnnotations "nginx.ingress.kubernetes.io/rewrite-target" "/$2" }} +{{- end }} +{{- else if eq $ingressClass "traefik" }} +{{- $_ := set $defaultAnnotations "kubernetes.io/ingress.class" "traefik" }} +{{- $_ := set $defaultAnnotations "traefik.ingress.kubernetes.io/router.entrypoints" "web" }} +{{- if (default $useRewrite false) }} +{{- $_ := set $defaultAnnotations "traefik.ingress.kubernetes.io/router.middlewares" (printf "%s-rewrite" $serviceName) }} +{{- end }} +{{- end }} + +{{- /* Merge annotations from values file, overriding defaults */}} +{{- $mergedAnnotations := mergeOverwrite $defaultAnnotations $annotations }} + +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ $fullName}}-{{ $serviceName }} + labels: {{ $appLabels | nindent 4 }} + annotations: + {{- range $key, $value := $mergedAnnotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} +spec: + tls: + - hosts: + {{- range $.Values.hosts }} + - {{ . | quote }} + {{- end }} + {{- if $.Values.explicitTLS }} + secretName: {{ $.Values.explicitTLS }} + {{- end }} + rules: + {{- range $.Values.hosts }} + - host: {{ . | quote }} + http: + paths: + {{- range $contextPath }} + - path: {{ . }} + pathType: Prefix + backend: + service: + name: {{ $serviceName }} + port: + number: {{ $servicePort }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/application-ingress/values.yaml b/charts/application-ingress/values.yaml new file mode 100644 index 0000000..e4b9900 --- /dev/null +++ b/charts/application-ingress/values.yaml @@ -0,0 +1,36 @@ +--- +# ingressClass: nginx + +solution: + component: ingress + +servicePort: 80 + +hosts: [] + # - "cluster.example.com" + +explicitTLS: + +services: {} + # - name: serviceA + # port: 8081 + # useRewrite: true + # contextPath: + # - / + # - name: serviceB + # ingressClass: nginx + # annotations: + # nginx.ingress.kubernetes.io/proxy-body-size: 100m + # nginx.ingress.kubernetes.io/use-regex: "false" + # contextPath: + # - /serviceB + +# use rewrites +# useRewrite: true +# services: +# - name: frontend +# contextPath: +# - ()(/.*) +# - name: api +# contextPath: +# - (/api)(/.*)