You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by wa...@apache.org on 2022/06/07 05:51:26 UTC
[incubator-devlake] branch main updated: feat: helm deployment support ingress
This is an automated email from the ASF dual-hosted git repository.
warren pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 45f8106f feat: helm deployment support ingress
45f8106f is described below
commit 45f8106f76d2ff7be2f607c41f17c0fa83b09a74
Author: Ji Bin <ma...@live.com>
AuthorDate: Sun Jun 5 02:47:33 2022 +0800
feat: helm deployment support ingress
Signed-off-by: Ji Bin <ma...@live.com>
---
deployment/helm/README.md | 67 ++++++++++++++++++++++++++++--
deployment/helm/templates/NOTES.txt | 9 ++--
deployment/helm/templates/_helpers.tpl | 56 +++++++++++++++++++++++++
deployment/helm/templates/configmaps.yaml | 15 +++++++
deployment/helm/templates/deployments.yaml | 13 +++++-
deployment/helm/templates/ingresses.yaml | 67 ++++++++++++++++++++++++++++++
deployment/helm/values.yaml | 21 +++++-----
7 files changed, 227 insertions(+), 21 deletions(-)
diff --git a/deployment/helm/README.md b/deployment/helm/README.md
index d6e62142..f7fc8866 100644
--- a/deployment/helm/README.md
+++ b/deployment/helm/README.md
@@ -5,18 +5,71 @@
- Helm >= 3.6.0
- Kubernetes >= 1.19.0
+
## Quick Install
clone the code, and enter the deployment/helm folder.
```
-helm install devlake .
+helm install devlake . --set service.grafanaEndpoint=http://YOUR-NODE-IP:32000
```
And visit your devlake from the node port (32001 by default).
+http://YOUR-NODE-IP:32001
+
+
+## Some example deployments
+
+### Deploy with NodePort
+
+Conditions:
+ - IP Address of Kubernetes node: 192.168.0.6
+ - Want to visit devlake with port 30000, and grafana at port 30001
+
+```
+helm install devlake . --set "service.uiPort=30000,service.grafanaPort=30001,service.grafanaEndpoint=http://192.168.0.6:30001"
+```
+
+After deployed, visit devlake: http://192.168.0.6:30000
+
+### Deploy with Ingress
+
+Conditions:
+ - I have already configured default ingress for the Kubernetes cluster
+ - I want to use http://devlake.example.com for visiting devlake
+
+```
+helm install devlake . --set "ingress.enabled=true,ingress.hostname=devlake.example.com"
+```
+
+After deployed, visit devlake: http://devlake.example.com, and grafana at http://devlake.example.com/grafana
+
+### Deploy with Ingress (Https)
+
+Conditions:
+ - I have already configured ingress(class: nginx) for the Kubernetes cluster, and the https using 8443 port.
+ - I want to use https://devlake-0.example.com:8443 for visiting devlake.
+ - The https certificates are generated by letsencrypt.org, and the certificate and key files: `cert.pem` and `key.pem`
+
+First, create the secret:
+```
+kubectl create secret tls ssl-certificate --cert cert.pem --key secret.pem
+```
+
+Then, deploy the devlake:
+```
+helm install devlake . \
+ --set "ingress.enabled=true,ingress.enableHttps=true,ingress.hostname=devlake-0.example.com" \
+ --set "ingress.className=nginx,ingress.httpsPort=8443" \
+ --set "ingress.tlsSecretName=ssl-certificate"
+```
+
+After deployed, visit devlake: https://devlake-0.example.com:8443, and grafana at https://devlake-0.example.com:8443/grafana
+
+
## Parameters
-Some useful parameter for the chart, you could also check them in values.yaml
+Some useful parameters for the chart, you could also check them in values.yaml
| Parameter | Description | Default |
|-----------|-------------|---------|
@@ -47,4 +100,12 @@ Some useful parameter for the chart, you could also check them in values.yaml
| service.type | Service type for exposed service | NodePort |
| service.grafanaPort | Service port for grafana | 32000 |
| service.uiPort | Service port for config ui | 32001 |
-| service.grafanaEndpoint | The external grafana endpoint, used when ingress not configured | http://127.0.0.1:32000 |
\ No newline at end of file
+| service.grafanaEndpoint | The external grafana endpoint, used when ingress not configured | http://127.0.0.1:32000 |
+| service.ingress.enabled | If enable ingress | false |
+| service.ingress.enableHttps | If enable https | false |
+| service.ingress.className | The class name for ingressClass. If leave empty, the default IngressClass will be used | "" |
+| service.ingress.hostname | The hostname/domainname for ingress | localhost |
+| service.ingress.prefix | The prefix for endpoints, currently not supported due to devlake's implementation | / |
+| service.ingress.tlsSecretName | The secret name for tls's certificate, required when https enabled | "" |
+| service.ingress.httpPort | The http port for ingress | 80 |
+| service.ingress.httpsPort | The https port for ingress | 443 |
diff --git a/deployment/helm/templates/NOTES.txt b/deployment/helm/templates/NOTES.txt
index 5745506f..a000ebb6 100644
--- a/deployment/helm/templates/NOTES.txt
+++ b/deployment/helm/templates/NOTES.txt
@@ -1,14 +1,11 @@
Welcome to use devlake.
-Now please get the URL by running these commands:
{{- if .Values.ingress.enabled }}
-{{- range $host := .Values.ingress.hosts }}
- {{- range .paths }}
- http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
- {{- end }}
-{{- end }}
+Now please visit:
+ {{ include "devlake.uiEndpoint" . }}
{{- else if contains "NodePort" .Values.service.type }}
+Now please get the URL by running these commands:
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "devlake.fullname" . }}-ui)
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
diff --git a/deployment/helm/templates/_helpers.tpl b/deployment/helm/templates/_helpers.tpl
index 40d1c0b1..087b3178 100644
--- a/deployment/helm/templates/_helpers.tpl
+++ b/deployment/helm/templates/_helpers.tpl
@@ -61,3 +61,59 @@ Create the name of the service account to use
{{- end }}
{{- end }}
+
+{{/*
+The ui endpoint prefix
+*/}}
+{{- define "devlake.grafanaEndpointPrefix" -}}
+{{- print .Values.ingress.prefix "/grafana" | replace "//" "/" | trimAll "/" -}}
+{{- end }}
+
+{{/*
+The ui endpoint prefix
+*/}}
+{{- define "devlake.uiEndpointPrefix" -}}
+{{- print .Values.ingress.prefix "/" | replace "//" "/" | trimAll "/" -}}
+{{- end }}
+
+{{/*
+The grafana endpoint
+*/}}
+{{- define "devlake.grafanaEndpoint" -}}
+{{- if .Values.ingress.enabled }}
+{{- $grafanaPortString := "" }}
+{{- if .Values.ingress.enableHttps }}
+{{- if ne 443 ( .Values.ingress.httpsPort | int) }}
+{{- $grafanaPortString = printf ":%d" ( .Values.ingress.httpsPort | int) }}
+{{- end }}
+{{- printf "https://%s%s/%s" .Values.ingress.hostname $grafanaPortString (include "devlake.grafanaEndpointPrefix" .) }}
+{{- else }}
+{{- if ne 80 ( .Values.ingress.httpPort | int) }}
+{{- $grafanaPortString = printf ":%d" ( .Values.ingress.httpPort | int) }}
+{{- end }}
+{{- printf "http://%s%s/%s" .Values.ingress.hostname $grafanaPortString (include "devlake.grafanaEndpointPrefix" .) }}
+{{- end }}
+{{- else }}
+{{ .Values.service.grafanaEndpoint }}
+{{- end }}
+{{- end }}
+
+{{/*
+The ui endpoint
+*/}}
+{{- define "devlake.uiEndpoint" -}}
+{{- if .Values.ingress.enabled }}
+{{- $uiPortString := "" }}
+{{- if .Values.ingress.enableHttps }}
+{{- if ne 443 ( .Values.ingress.httpsPort | int) }}
+{{- $uiPortString = printf ":%d" ( .Values.ingress.httpsPort | int) }}
+{{- end }}
+{{- printf "https://%s%s/%s" .Values.ingress.hostname $uiPortString (include "devlake.uiEndpointPrefix" .) }}
+{{- else }}
+{{- if ne 80 ( .Values.ingress.httpPort | int) }}
+{{- $uiPortString = printf ":%d" ( .Values.ingress.httpPort | int) }}
+{{- end }}
+{{- printf "http://%s%s/%s" .Values.ingress.hostname $uiPortString (include "devlake.uiEndpointPrefix" .) }}
+{{- end }}
+{{- end }}
+{{- end }}
diff --git a/deployment/helm/templates/configmaps.yaml b/deployment/helm/templates/configmaps.yaml
index 0a7f1613..f5a80991 100644
--- a/deployment/helm/templates/configmaps.yaml
+++ b/deployment/helm/templates/configmaps.yaml
@@ -1,3 +1,4 @@
+---
apiVersion: v1
kind: ConfigMap
metadata:
@@ -7,3 +8,17 @@ data:
MYSQL_PASSWORD: "{{ .Values.mysql.password }}"
MYSQL_DATABASE: "{{ .Values.mysql.database }}"
MYSQL_ROOT_PASSWORD: "{{ .Values.mysql.rootPassword }}"
+
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: {{ include "devlake.fullname" . }}-grafana-config
+data:
+ grafana.ini: |
+ [server]
+ {{- if .Values.ingress.enabled }}
+ domain = {{ .Values.ingress.hostname }}
+ root_url = {{ include "devlake.grafanaEndpoint" . }}
+ serve_from_sub_path = true
+ {{- end }}
diff --git a/deployment/helm/templates/deployments.yaml b/deployment/helm/templates/deployments.yaml
index 8f6d3013..03837b13 100644
--- a/deployment/helm/templates/deployments.yaml
+++ b/deployment/helm/templates/deployments.yaml
@@ -29,6 +29,10 @@ spec:
port: 3000
initialDelaySeconds: 30
timeoutSeconds: 30
+ volumeMounts:
+ - mountPath: /etc/grafana/grafana.ini
+ name: {{ include "devlake.fullname" . }}-grafana-config
+ subPath: grafana.ini
envFrom:
- configMapRef:
name: {{ include "devlake.fullname" . }}-config
@@ -41,6 +45,11 @@ spec:
value: '*'
- name: MYSQL_URL
value: {{ include "devlake.fullname" . }}-mysql:3306
+ volumes:
+ - configMap:
+ defaultMode: 420
+ name: {{ include "devlake.fullname" . }}-grafana-config
+ name: {{ include "devlake.fullname" . }}-grafana-config
---
# devlake-ui
@@ -75,8 +84,8 @@ spec:
# TODO: remove hardcoded `cluster.local`
value: {{ include "devlake.fullname" . }}-lake.{{ .Release.Namespace }}.svc.cluster.local:8080
- name: GRAFANA_ENDPOINT
- value: "{{ .Values.service.grafanaEndpoint }}"
+ value: "{{ include "devlake.grafanaEndpoint" . }}"
# - name: ADMIN_USER
# value: "admin"
# - name: ADMIN_PASS
- # value: "admin"
\ No newline at end of file
+ # value: "admin"
diff --git a/deployment/helm/templates/ingresses.yaml b/deployment/helm/templates/ingresses.yaml
new file mode 100644
index 00000000..4b622723
--- /dev/null
+++ b/deployment/helm/templates/ingresses.yaml
@@ -0,0 +1,67 @@
+{{- if .Values.ingress.enabled -}}
+{{- $fullName := include "devlake.fullname" . -}}
+{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
+ {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
+ {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
+ {{- end }}
+{{- end }}
+{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
+apiVersion: networking.k8s.io/v1
+{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
+apiVersion: networking.k8s.io/v1beta1
+{{- else -}}
+apiVersion: extensions/v1beta1
+{{- end }}
+kind: Ingress
+metadata:
+ name: {{ $fullName }}
+ labels:
+ {{- include "devlake.labels" . | nindent 4 }}
+ annotations:
+ nginx.ingress.kubernetes.io/rewrite-target: /$2
+ {{- with .Values.ingress.annotations }}
+ {{- toYaml . | nindent 4 }}
+ {{- end }}
+spec:
+ {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
+ ingressClassName: {{ .Values.ingress.className }}
+ {{- end }}
+ {{- if .Values.ingress.enableHttps }}
+ tls:
+ - hosts:
+ - {{ .Values.ingress.hostname }}
+ secretName: {{ .Values.ingress.tlsSecretName }}
+ {{- end }}
+ rules:
+ - host: {{ .Values.ingress.hostname | quote }}
+ http:
+ paths:
+ - path: /{{ include "devlake.grafanaEndpointPrefix" . }}(/|$)(.*)
+ {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }}
+ pathType: Prefix
+ {{- end }}
+ backend:
+ {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
+ service:
+ name: {{ include "devlake.fullname" . }}-grafana
+ port:
+ number: {{ .Values.service.grafanaPort }}
+ {{- else }}
+ serviceName: {{ include "devlake.fullname" . }}-grafana
+ servicePort: {{ .Values.service.grafanaPort }}
+ {{- end }}
+ - path: /{{ include "devlake.uiEndpointPrefix" . }}(/?|$)(.*)
+ {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }}
+ pathType: Prefix
+ {{- end }}
+ backend:
+ {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
+ service:
+ name: {{ include "devlake.fullname" . }}-ui
+ port:
+ number: {{ .Values.service.uiPort }}
+ {{- else }}
+ serviceName: {{ include "devlake.fullname" . }}-ui
+ servicePort: {{ .Values.service.uiPort }}
+ {{- end }}
+{{- end }}
\ No newline at end of file
diff --git a/deployment/helm/values.yaml b/deployment/helm/values.yaml
index 276d5989..6a8f715f 100644
--- a/deployment/helm/values.yaml
+++ b/deployment/helm/values.yaml
@@ -108,19 +108,20 @@ service:
# the external endpoint for grafana, only used when ingress not enabled
grafanaEndpoint: http://127.0.0.1:32000
-# TODO(matrixji) support ingress.
ingress:
enabled: false
+ enableHttps: false
className: ""
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
- hosts:
- - host: chart-example.local
- paths:
- - path: /
- pathType: ImplementationSpecific
- tls: []
- # - secretName: chart-example-tls
- # hosts:
- # - chart-example.local
\ No newline at end of file
+ # domain name for hosting devlake
+ hostname: localhost
+ # url prefix, not works right now, keep "/"
+ prefix: /
+ # if using https provides the certificates secret name
+ tlsSecretName: ""
+ # ingress http port
+ httpPort: 80
+ # ingress https port
+ httpsPort: 443