diff --git a/charts/portainer/README.md b/charts/portainer/README.md index 0d871bb..080c144 100644 --- a/charts/portainer/README.md +++ b/charts/portainer/README.md @@ -72,6 +72,7 @@ The following table lists the configurable parameters of the Portainer chart and | `service.annotations` | Annotations to add to the service | `{}` | | `feature.flags` | Enable one or more features separated by spaces. For instance, `--feat=open-amt` | `nil` | | `ingress.enabled` | Create an ingress for Portainer | `false` | +| `ingress.ingressClassName` | For Kubernetes >= 1.18 you should specify the ingress-controller via the field `ingressClassName`. For instance, `nginx` | `nil` | | `ingress.annotations` | Annotations to add to the ingress. For instane, `kubernetes.io/ingress.class: nginx` | `{}` | | `ingress.hosts.host` | URL for Portainer Web. For instance, `portainer.example.io` | `nil` | | `ingress.hosts.paths.path` | Path for the Portainer Web. | `/` | diff --git a/charts/portainer/templates/_helpers.tpl b/charts/portainer/templates/_helpers.tpl index 893e401..b428447 100644 --- a/charts/portainer/templates/_helpers.tpl +++ b/charts/portainer/templates/_helpers.tpl @@ -71,4 +71,17 @@ Provide a pre-defined claim or a claim based on the Release {{- else -}} {{- template "portainer.fullname" . }} {{- end -}} +{{- end -}} + +{{/* +Generate a right Ingress apiVersion +*/}} +{{- define "ingress.apiVersion" -}} +{{- if semverCompare ">=1.20-0" .Capabilities.KubeVersion.GitVersion -}} +networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +networking.k8s.io/v1beta1 +{{- else -}} +extensions/v1 +{{- end }} {{- end -}} \ No newline at end of file diff --git a/charts/portainer/templates/ingress.yaml b/charts/portainer/templates/ingress.yaml index 265d075..50d51d4 100644 --- a/charts/portainer/templates/ingress.yaml +++ b/charts/portainer/templates/ingress.yaml @@ -1,14 +1,8 @@ {{- if .Values.ingress.enabled -}} {{- $fullName := include "portainer.fullname" . -}} -{{- $tlsforced := .Values.tls.force }} -{{- $kubeVersion := .Capabilities.KubeVersion.GitVersion -}} -{{- if semverCompare ">=1.19-0" $kubeVersion -}} -apiVersion: networking.k8s.io/v1 -{{- else if semverCompare ">=1.14-0" $kubeVersion -}} -apiVersion: networking.k8s.io/v1beta -{{- else }} -apiVersion: extensions/v1beta1 -{{- end }} +{{- $tlsforced := .Values.tls.force -}} +{{- $apiVersion := include "ingress.apiVersion" . -}} +apiVersion: {{ $apiVersion }} kind: Ingress metadata: name: {{ $fullName }} @@ -20,6 +14,9 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} spec: +{{- with .Values.ingress.ingressClassName }} + ingressClassName: {{ . }} +{{- end }} {{- if .Values.ingress.tls }} tls: {{- range .Values.ingress.tls }} @@ -37,26 +34,27 @@ spec: paths: {{- range .paths }} - path: {{ .path | default "/" }} - {{- if semverCompare ">=1.19-0" $kubeVersion -}} + {{- if eq $apiVersion "networking.k8s.io/v1" }} pathType: Prefix + {{- end }} backend: + {{- if eq $apiVersion "networking.k8s.io/v1" }} service: name: {{ $fullName }} - port: + port: {{- if $tlsforced }} number: {{ .port | default 9443 }} {{- else }} number: {{ .port | default 9000 }} {{- end }} - {{- else -}} - backend: + {{- else }} serviceName: {{ $fullName }} {{- if $tlsforced }} servicePort: {{ .port | default 9443 }} {{- else }} servicePort: {{ .port | default 9000 }} {{- end }} - {{- end }} + {{- end }} {{- end }} {{- end }} {{- end }} \ No newline at end of file diff --git a/charts/portainer/values.yaml b/charts/portainer/values.yaml index 46c2c83..403ad60 100644 --- a/charts/portainer/values.yaml +++ b/charts/portainer/values.yaml @@ -49,8 +49,11 @@ feature: ingress: enabled: false + ingressClassName: "" annotations: {} -# nginx.ingress.kubernetes.io/backend-protocol: "HTTPS" + # kubernetes.io/ingress.class: nginx + # Only use below if tls.force=true + # nginx.ingress.kubernetes.io/backend-protocol: HTTPS hosts: - host: paths: []