From ccb2f70998072c5cd30184334e6f755c46847d78 Mon Sep 17 00:00:00 2001 From: "Miguel A. Cabrera Minagorri" Date: Thu, 25 Jul 2019 11:40:49 +0000 Subject: [PATCH] Add ingress controller to Tomcat Signed-off-by: Miguel A. Cabrera Minagorri --- bitnami/tomcat/Chart.yaml | 2 +- bitnami/tomcat/README.md | 5 ++++ bitnami/tomcat/templates/NOTES.txt | 9 ++++++- bitnami/tomcat/templates/_helpers.tpl | 7 +++++ bitnami/tomcat/templates/deployment.yaml | 2 +- bitnami/tomcat/templates/ingress.yaml | 33 ++++++++++++++++++++++++ bitnami/tomcat/templates/pvc.yaml | 2 +- bitnami/tomcat/templates/secrets.yaml | 2 +- bitnami/tomcat/templates/svc.yaml | 2 +- bitnami/tomcat/values.yaml | 33 ++++++++++++++++++++++++ 10 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 bitnami/tomcat/templates/ingress.yaml diff --git a/bitnami/tomcat/Chart.yaml b/bitnami/tomcat/Chart.yaml index 3fa120f6e4..620b8cf42d 100644 --- a/bitnami/tomcat/Chart.yaml +++ b/bitnami/tomcat/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: tomcat -version: 4.1.0 +version: 4.2.0 appVersion: 9.0.22 description: Chart for Apache Tomcat keywords: diff --git a/bitnami/tomcat/README.md b/bitnami/tomcat/README.md index 7322b1e725..001ac2ccd0 100644 --- a/bitnami/tomcat/README.md +++ b/bitnami/tomcat/README.md @@ -78,6 +78,11 @@ The following tables lists the configurable parameters of the Tomcat chart and t | `persistence.accessMode` | PVC Access Mode for Tomcat volume | `ReadWriteOnce` | | `persistence.size` | PVC Storage Request for Tomcat volume | `8Gi` | | `resources` | CPU/Memory resource requests/limits | Memory: `512Mi`, CPU: `300m` | +| `ingress.enabled` | Enable the ingress controller | `false` | +| `ingress.certManager` | Add annotations for certManager | `false` | +| `ingress.annotations` | Annotations to set in the ingress controller | - | +| `ingress.hosts` | List of hostnames to be covered with the ingress | `tomcat.local` | +| `ingress.tls` | List with TLS configuration for the ingress | `hosts: tomcat.local, secretName: tomcat.local-tls` | The above parameters map to the env variables defined in [bitnami/tomcat](http://github.com/bitnami/bitnami-docker-tomcat). For more information please refer to the [bitnami/tomcat](http://github.com/bitnami/bitnami-docker-tomcat) image documentation. diff --git a/bitnami/tomcat/templates/NOTES.txt b/bitnami/tomcat/templates/NOTES.txt index 212978cade..f73566dd6c 100644 --- a/bitnami/tomcat/templates/NOTES.txt +++ b/bitnami/tomcat/templates/NOTES.txt @@ -3,7 +3,14 @@ 1. Get the Tomcat URL by running: -{{- if contains "NodePort" .Values.service.type }} +{{- if .Values.ingress.enabled }} + +export CLUSTER_IP=$(minikube ip) # On Minikube. Use: `kubectl cluster-info` on others K8s clusters +export HOSTNAME=$(kubectl get ingress --namespace {{ .Release.Namespace }} {{ template "tomcat.fullname" . }} -o jsonpath='{.spec.rules[0].host}') +echo "Tomcat URL: http://$HOSTNAME/" +echo "$CLUSTER_IP $HOSTNAME" | sudo tee -a /etc/hosts + +{{- else if contains "NodePort" .Values.service.type }} export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "tomcat.fullname" . }}) export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") diff --git a/bitnami/tomcat/templates/_helpers.tpl b/bitnami/tomcat/templates/_helpers.tpl index 99942233fe..bd5c7a8fe4 100644 --- a/bitnami/tomcat/templates/_helpers.tpl +++ b/bitnami/tomcat/templates/_helpers.tpl @@ -6,6 +6,13 @@ Expand the name of the chart. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} {{- end -}} +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "tomcat.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + {{/* Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). diff --git a/bitnami/tomcat/templates/deployment.yaml b/bitnami/tomcat/templates/deployment.yaml index 549a23341b..8102a25a93 100644 --- a/bitnami/tomcat/templates/deployment.yaml +++ b/bitnami/tomcat/templates/deployment.yaml @@ -4,7 +4,7 @@ metadata: name: {{ template "tomcat.fullname" . }} labels: app: {{ template "tomcat.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + chart: {{ template "tomcat.chart" . }} release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" spec: diff --git a/bitnami/tomcat/templates/ingress.yaml b/bitnami/tomcat/templates/ingress.yaml new file mode 100644 index 0000000000..daaf3b0a24 --- /dev/null +++ b/bitnami/tomcat/templates/ingress.yaml @@ -0,0 +1,33 @@ +{{- if .Values.ingress.enabled }} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "tomcat.fullname" . }} + labels: + app: "{{ template "tomcat.fullname" . }}" + chart: "{{ template "tomcat.chart" . }}" + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} + annotations: + {{- if .Values.ingress.certManager }} + kubernetes.io/tls-acme: "true" + {{- end }} + {{- range $key, $value := .Values.ingress.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} +spec: + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .name }} + http: + paths: + - path: {{ default "/" .path }} + backend: + serviceName: "{{ template "tomcat.fullname" $ }}" + servicePort: http + {{- end }} + {{- if .Values.ingress.tls }} + tls: +{{ toYaml .Values.ingress.tls | indent 4 }} + {{- end }} +{{- end }} diff --git a/bitnami/tomcat/templates/pvc.yaml b/bitnami/tomcat/templates/pvc.yaml index 52396aaabf..8d93bfe28a 100644 --- a/bitnami/tomcat/templates/pvc.yaml +++ b/bitnami/tomcat/templates/pvc.yaml @@ -5,7 +5,7 @@ metadata: name: {{ template "tomcat.fullname" . }} labels: app: {{ template "tomcat.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + chart: {{ template "tomcat.chart" . }} release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" annotations: diff --git a/bitnami/tomcat/templates/secrets.yaml b/bitnami/tomcat/templates/secrets.yaml index f46fb74eb9..acc6e94a07 100644 --- a/bitnami/tomcat/templates/secrets.yaml +++ b/bitnami/tomcat/templates/secrets.yaml @@ -4,7 +4,7 @@ metadata: name: {{ template "tomcat.fullname" . }} labels: app: {{ template "tomcat.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + chart: {{ template "tomcat.chart" . }} release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" type: Opaque diff --git a/bitnami/tomcat/templates/svc.yaml b/bitnami/tomcat/templates/svc.yaml index 115c87e669..d251388496 100644 --- a/bitnami/tomcat/templates/svc.yaml +++ b/bitnami/tomcat/templates/svc.yaml @@ -4,7 +4,7 @@ metadata: name: {{ template "tomcat.fullname" . }} labels: app: {{ template "tomcat.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + chart: {{ template "tomcat.chart" . }} release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" spec: diff --git a/bitnami/tomcat/values.yaml b/bitnami/tomcat/values.yaml index bf91046d1f..34baced654 100644 --- a/bitnami/tomcat/values.yaml +++ b/bitnami/tomcat/values.yaml @@ -118,3 +118,36 @@ resources: requests: memory: 512Mi cpu: 300m + +## Configure the ingress resource that allows you to access the +## Tomcat installation. Set up the URL +## ref: http://kubernetes.io/docs/user-guide/ingress/ +## +ingress: + ## Set to true to enable ingress record generation + enabled: false + + ## Set this to true in order to add the corresponding annotations for cert-manager + certManager: false + + ## Ingress annotations done as key:value pairs + ## For a full list of possible ingress annotations, please see + ## ref: https://github.com/kubernetes/ingress-nginx/blob/master/docs/annotations.md + ## + ## If tls is set to true, annotation ingress.kubernetes.io/secure-backends: "true" will automatically be set + ## If certManager is set to true, annotation kubernetes.io/tls-acme: "true" will automatically be set + annotations: + # kubernetes.io/ingress.class: nginx + + ## The list of hostnames to be covered with this ingress record. + ## Most likely this will be just one host, but in the event more hosts are needed, this is an array + hosts: + - name: tomcat.local + path: / + + ## The tls configuration for the ingress + ## see: https://kubernetes.io/docs/concepts/services-networking/ingress/#tls + tls: + - hosts: + - tomcat.local + secretName: tomcat.local-tls