From f7c408d4e58f41ffe8b2d0d9925a3f31581fce2e Mon Sep 17 00:00:00 2001 From: ReSearchITEng Date: Tue, 25 Jul 2017 08:34:11 +0300 Subject: [PATCH] [stable/moodle] ingress,existingClaims,affinity,ImageVerUpdate,singleMountPoint (#1534) - adds `Ingress` controller support - defines single mountpoint for persistence at `/bitnami` - adds support for `existingClaim`, `affinity`, etc. --- stable/moodle/Chart.yaml | 2 +- stable/moodle/README.md | 109 +++++++++++++----- stable/moodle/templates/NOTES.txt | 18 ++- stable/moodle/templates/_helpers.tpl | 10 ++ stable/moodle/templates/deployment.yaml | 17 +-- stable/moodle/templates/ingress.yaml | 38 ++++++ stable/moodle/templates/moodle-pvc.yaml | 23 ---- .../templates/{apache-pvc.yaml => pvc.yaml} | 12 +- stable/moodle/values.yaml | 99 +++++++++++++--- 9 files changed, 242 insertions(+), 86 deletions(-) create mode 100644 stable/moodle/templates/ingress.yaml delete mode 100644 stable/moodle/templates/moodle-pvc.yaml rename stable/moodle/templates/{apache-pvc.yaml => pvc.yaml} (60%) diff --git a/stable/moodle/Chart.yaml b/stable/moodle/Chart.yaml index 1527181fb4..6a8d4ce11f 100644 --- a/stable/moodle/Chart.yaml +++ b/stable/moodle/Chart.yaml @@ -1,5 +1,5 @@ name: moodle -version: 0.1.11 +version: 0.2.0 appVersion: 3.3.1 description: Moodle is a learning platform designed to provide educators, administrators and learners with a single robust, secure and integrated system to create personalised learning environments keywords: diff --git a/stable/moodle/README.md b/stable/moodle/README.md index bd5ffbe68a..7fffe019e3 100644 --- a/stable/moodle/README.md +++ b/stable/moodle/README.md @@ -45,32 +45,38 @@ The command removes all the Kubernetes components associated with the chart and The following tables lists the configurable parameters of the Moodle chart and their default values. -| Parameter | Description | Default | -|------------------------------------|----------------------------------------|---------------------------------------------| -| `image` | Moodle image | `bitnami/moodle:{VERSION}` | -| `imagePullPolicy` | Image pull policy | `IfNotPresent` | -| `moodleUsername` | User of the application | `user` | -| `moodlePassword` | Application password | _random 10 character alphanumeric string_ | -| `moodleEmail` | Admin email | `user@example.com` | -| `smtpHost` | SMTP host | `nil` | -| `smtpPort` | SMTP port | `nil` | -| `smtpProtocol` | SMTP Protocol | `nil` | -| `smtpUser` | SMTP user | `nil` | -| `smtpPassword` | SMTP password | `nil` | -| `serviceType` | Kubernetes Service type | `LoadBalancer` | -| `resources` | CPU/Memory resource requests/limits | Memory: `512Mi`, CPU: `300m` | -| `persistence.enabled` | Enable persistence using PVC | `true` | -| `persistence.apache.storageClass` | PVC Storage Class for Apache volume | `nil` (uses alpha storage class annotation) | -| `persistence.apache.accessMode` | PVC Access Mode for Apache volume | `ReadWriteOnce` | -| `persistence.apache.size` | PVC Storage Request for Apache volume | `1Gi` | -| `persistence.moodle.storageClass` | PVC Storage Class for Moodle volume | `nil` (uses alpha storage class annotation) | -| `persistence.moodle.accessMode` | PVC Access Mode for Moodle volume | `ReadWriteOnce` | -| `persistence.moodle.size` | PVC Storage Request for Moodle volume | `8Gi` | -| `mariadb.mariadbRootPassword` | MariaDB admin password | `nil` (uses alpha storage class annotation) | -| `mariadb.persistence.enabled` | Enable MariaDB persistence using PVC | `true` | -| `mariadb.persistence.storageClass` | PVC Storage Class for MariaDB volume | `generic` | -| `mariadb.persistence.accessMode` | PVC Access Mode for MariaDB volume | `ReadWriteOnce` | -| `mariadb.persistence.size` | PVC Storage Request for MariaDB volume | `8Gi` | +| Parameter | Description | Default | +|-------------------------------------|-----------------------------------------|---------------------------------------------| +| `image` | Moodle image | `bitnami/moodle:{VERSION}` | +| `imagePullPolicy` | Image pull policy | `IfNotPresent` | +| `moodleUsername` | User of the application | `user` | +| `moodlePassword` | Application password | _random 10 character alphanumeric string_ | +| `moodleEmail` | Admin email | `user@example.com` | +| `smtpHost` | SMTP host | `nil` | +| `smtpPort` | SMTP port | `nil` (but moodle internal default is 25) | +| `smtpProtocol` | SMTP Protocol (options: ssl,tls, nil) | `nil` | +| `smtpUser` | SMTP user | `nil` | +| `smtpPassword` | SMTP password | `nil` | +| `serviceType` | Kubernetes Service type | `LoadBalancer` | +| `ingress.enabled` | If ingress should be created | `false` | +| `ingress.annotations` | Any ingress annotations | `nil` | +| `ingress.hosts` | List of Ingress hosts | `nil` | +| `ingress.tls` | List of certs. If defined, https is set | `nil` | +| `affinity` | Set affinity for the moodle pods | `nil` | +| `resources` | CPU/Memory resource requests/limits | Memory: `512Mi`, CPU: `300m` | +| `persistence.enabled` | Enable persistence using PVC | `true` | +| `persistence.storageClass` | PVC Storage Class for Moodle volume | `nil` (uses alpha storage class annotation) | +| `persistence.accessMode` | PVC Access Mode for Moodle volume | `ReadWriteOnce` | +| `persistence.size` | PVC Storage Request for Moodle volume | `8Gi` | +| `persistence.existingClaim` | If PVC exists&bounded for Moodle | `nil` (when nil, new one is requested) | +| `mariadb.mariadbRootPassword` | MariaDB admin password | `nil` (uses alpha storage class annotation) | +| `mariadb.persistence.enabled` | Enable MariaDB persistence using PVC | `true` | +| `mariadb.persistence.storageClass` | PVC Storage Class for MariaDB volume | `generic` | +| `mariadb.persistence.accessMode` | PVC Access Mode for MariaDB volume | `ReadWriteOnce` | +| `mariadb.persistence.size` | PVC Storage Request for MariaDB volume | `8Gi` | +| `mariadb.persistence.existingClaim` | If PVC exists&bounded for MariaDB | `nil` (when nil, new one is requested) | +| `mariadb.affinity` | Set affinity for the MariaDB pods | `nil` | +| `mariadb.resources` | CPU/Memory resource requests/limits | Memory: `256Mi`, CPU: `250m` | The above parameters map to the env variables defined in [bitnami/moodle](http://github.com/bitnami/bitnami-docker-moodle). For more information please refer to the [bitnami/moodle](http://github.com/bitnami/bitnami-docker-moodle) image documentation. @@ -92,9 +98,58 @@ $ helm install --name my-release -f values.yaml stable/moodle > **Tip**: You can use the default [values.yaml](values.yaml) +### Ingress without TLS +For using ingress (example without tls): +```console +$ helm install --name my-release \ + --set ingress.enabled=True,ingress.hosts[0]=moodle.domain.com,serviceType=ClusterIP,moodleUsername=admin,moodlePassword=password,mariadb.mariadbRootPassword=secretpassword stable/moodle +``` + +These are the *3 mandatory parameters* when *Ingress* is desired: +`ingress.enabled=True,ingress.hosts[0]=moodle.domain.com,serviceType=ClusterIP` + +### Ingress TLS +If your cluster allows automatic creation/retrieval of TLS certificates (e.g. [kube-lego](https://github.com/jetstack/kube-lego)), please refer to the documentation for that mechanism. + +To manually configure TLS, first create/retrieve a key & certificate pair for the address(es) you wish to protect. Then create a TLS secret in the namespace: + +```console +$ kubectl create secret tls moodle-server-tls --cert=path/to/tls.cert --key=path/to/tls.key +``` + +Include the secret's name, along with the desired hostnames, in the Ingress TLS section of your custom `values.yaml` file: + +```console +ingress: + ## If true, Moodle server Ingress will be created + ## + enabled: true + + ## Moodle server Ingress annotations + ## + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: 'true' + + ## Moodle server Ingress hostnames + ## Must be provided if Ingress is enabled + ## + hosts: + - moodle.domain.com + + ## Moodle server Ingress TLS configuration + ## Secrets must be manually created in the namespace + ## + tls: + - secretName: moodle-server-tls + hosts: + - moodle.domain.com +``` + ## Persistence The [Bitnami Moodle](https://github.com/bitnami/bitnami-docker-moodle) image stores the Moodle data and configurations at the `/bitnami/moodle` and `/bitnami/apache` paths of the container. -Persistent Volume Claims are used to keep the data across deployments. This is known to work in GCE, AWS, and minikube. +Persistent Volume Claims are used to keep the data across deployments. This is known to work in GCE, AWS, vpshere, and minikube. See the [Configuration](#configuration) section to configure the PVC or to disable persistence. +You may want to review the [PV reclaim policy](https://kubernetes.io/docs/tasks/administer-cluster/change-pv-reclaim-policy/), and update as required. By default it's set to delete, and when moodle is uninstalled, data is also removed. diff --git a/stable/moodle/templates/NOTES.txt b/stable/moodle/templates/NOTES.txt index 220c67d7c5..4592225d25 100644 --- a/stable/moodle/templates/NOTES.txt +++ b/stable/moodle/templates/NOTES.txt @@ -1,10 +1,22 @@ ** Please be patient while the chart is being deployed ** +{{- if and .Values.ingress.enabled (ne .Values.serviceType "ClusterIP") }} +** Notice : Usually with ingress the serviceType should be set to ClusterIP, which is not the case to this deployment! ** +{{- end }} -1. Get the Moodle URL by running: - -{{- if contains "NodePort" .Values.serviceType }} +1. Access you Moodle instance with: +{{- if .Values.ingress.enabled }} + {{ if .Values.ingress.tls }} + {{- range .Values.ingress.hosts }} + - https://{{ . }} + {{- end }} + {{- else }} + {{- range .Values.ingress.hosts }} + - http://{{ . }} + {{- end }} + {{- end }} +{{- else if contains "NodePort" .Values.serviceType }} export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }}) 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/stable/moodle/templates/_helpers.tpl b/stable/moodle/templates/_helpers.tpl index 3d76d82dd6..40dc8a9c3d 100644 --- a/stable/moodle/templates/_helpers.tpl +++ b/stable/moodle/templates/_helpers.tpl @@ -22,3 +22,13 @@ We truncate at 24 chars because some Kubernetes name fields are limited to this {{- define "mariadb.fullname" -}} {{- printf "%s-%s" .Release.Name "mariadb" | trunc 63 | trimSuffix "-" -}} {{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 24 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "moodle.fullname" -}} +{{- printf "%s-%s" .Release.Name "moodle" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + + diff --git a/stable/moodle/templates/deployment.yaml b/stable/moodle/templates/deployment.yaml index 68490383d0..12a13a784e 100644 --- a/stable/moodle/templates/deployment.yaml +++ b/stable/moodle/templates/deployment.yaml @@ -13,6 +13,10 @@ spec: labels: app: {{ template "fullname" . }} spec: + {{- if .Values.affinity }} + affinity: +{{ toYaml .Values.affinity | indent 8 }} + {{- end }} containers: - name: {{ template "fullname" . }} image: "{{ .Values.image }}" @@ -72,21 +76,12 @@ spec: {{ toYaml .Values.resources | indent 10 }} volumeMounts: - name: moodle-data - mountPath: /bitnami/moodle - - name: apache-data - mountPath: /bitnami/apache + mountPath: /bitnami volumes: - name: moodle-data {{- if .Values.persistence.enabled }} persistentVolumeClaim: - claimName: {{ template "fullname" . }}-moodle - {{- else }} - emptyDir: {} - {{- end }} - - name: apache-data - {{- if .Values.persistence.enabled }} - persistentVolumeClaim: - claimName: {{ template "fullname" . }}-apache + claimName: {{ .Values.persistence.existingClaim | default (include "moodle.fullname" . ) }} {{- else }} emptyDir: {} {{- end }} diff --git a/stable/moodle/templates/ingress.yaml b/stable/moodle/templates/ingress.yaml new file mode 100644 index 0000000000..2102237ca0 --- /dev/null +++ b/stable/moodle/templates/ingress.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ingress.enabled -}} +{{- $releaseName := .Release.Name -}} +{{- $serviceName := include "fullname" . }} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: +{{- if .Values.ingress.annotations }} + annotations: +{{ toYaml .Values.ingress.annotations | indent 4}} +{{- end }} + labels: + app: {{ template "fullname" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version }} + component: "{{ .Values.name }}" + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} + name: {{ template "fullname" . }} +spec: + rules: + {{- range .Values.ingress.hosts }} + - host: {{ . }} + http: + paths: + - backend: + serviceName: {{ $serviceName }} + servicePort: 80 + {{- end -}} +{{- if .Values.ingress.tls }} + tls: +{{ toYaml .Values.ingress.tls | indent 4 }} + backend: + serviceName: {{ $serviceName }} + servicePort: 80 + {{- end -}} +{{- end -}} + + + diff --git a/stable/moodle/templates/moodle-pvc.yaml b/stable/moodle/templates/moodle-pvc.yaml deleted file mode 100644 index 493dafaf72..0000000000 --- a/stable/moodle/templates/moodle-pvc.yaml +++ /dev/null @@ -1,23 +0,0 @@ -{{- if .Values.persistence.enabled -}} -kind: PersistentVolumeClaim -apiVersion: v1 -metadata: - name: {{ template "fullname" . }}-moodle - labels: - app: {{ template "fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" - annotations: - {{- if .Values.persistence.moodle.storageClass }} - volume.beta.kubernetes.io/storage-class: {{ .Values.persistence.moodle.storageClass | quote }} - {{- else }} - volume.alpha.kubernetes.io/storage-class: default - {{- end }} -spec: - accessModes: - - {{ .Values.persistence.moodle.accessMode | quote }} - resources: - requests: - storage: {{ .Values.persistence.moodle.size | quote }} -{{- end -}} diff --git a/stable/moodle/templates/apache-pvc.yaml b/stable/moodle/templates/pvc.yaml similarity index 60% rename from stable/moodle/templates/apache-pvc.yaml rename to stable/moodle/templates/pvc.yaml index 166feb8b9f..2424b389ce 100644 --- a/stable/moodle/templates/apache-pvc.yaml +++ b/stable/moodle/templates/pvc.yaml @@ -1,23 +1,23 @@ -{{- if .Values.persistence.enabled -}} +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) -}} kind: PersistentVolumeClaim apiVersion: v1 metadata: - name: {{ template "fullname" . }}-apache + name: {{ template "fullname" . }} labels: app: {{ template "fullname" . }} chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" annotations: - {{- if .Values.persistence.apache.storageClass }} - volume.beta.kubernetes.io/storage-class: {{ .Values.persistence.apache.storageClass | quote }} + {{- if .Values.persistence.storageClass }} + volume.beta.kubernetes.io/storage-class: {{ .Values.persistence.storageClass | quote }} {{- else }} volume.alpha.kubernetes.io/storage-class: default {{- end }} spec: accessModes: - - {{ .Values.persistence.apache.accessMode | quote }} + - {{ .Values.persistence.accessMode | quote }} resources: requests: - storage: {{ .Values.persistence.apache.size | quote }} + storage: {{ .Values.persistence.size | quote }} {{- end -}} diff --git a/stable/moodle/values.yaml b/stable/moodle/values.yaml index 628b1e960e..25878d472b 100644 --- a/stable/moodle/values.yaml +++ b/stable/moodle/values.yaml @@ -52,31 +52,100 @@ mariadb: # storageClass: accessMode: ReadWriteOnce size: 8Gi +# existingClaim: "" + + ## Define affinity for the pod + ## Sometimes required when persistent volumes are defined externally + ## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector +# affinity: +# nodeAffinity: +# requiredDuringSchedulingIgnoredDuringExecution: +# nodeSelectorTerms: +# - matchExpressions: +# - key: node-role.kubernetes.io/master +# operator: Exists +# values: +# - machine01 +# preferredDuringSchedulingIgnoredDuringExecution: +# - weight: 1 +# preference: +# matchExpressions: +# - key: another-node-label-key +# operator: In +# values: +# - another-node-label-value +# +# resources: +# requests: +# memory: 768Mi +# cpu: 750m + ## Kubernetes configuration -## For minikube, set this to NodePort, elsewhere use LoadBalancer +## For minikube, set this to NodePort, for ingress ClusterIP, elsewhere use LoadBalancer ## serviceType: LoadBalancer +## Optionally, create ingress controller +ingress: + ## If true, Moodle server Ingress will be created + ## + enabled: false + + ## Moodle server Ingress annotations + ## + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: 'true' + + ## Moodle server Ingress hostnames + ## Must be provided if Ingress is enabled + ## + hosts: [] + # - moodle.domain.com + + ## Moodle server Ingress TLS configuration + ## Secrets must be manually created in the namespace + ## kubectl create secret tls moodle-server-tls --cert=tls.crt --key=tls.key + ## + tls: [] + # - secretName: moodle-server-tls + # hosts: + # - moodle.domain.com + ## Enable persistence using Persistent Volume Claims ## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/ ## persistence: enabled: true - apache: - ## If defined, volume.beta.kubernetes.io/storage-class: - ## Default: volume.alpha.kubernetes.io/storage-class: default - ## - # storageClass: - accessMode: ReadWriteOnce - size: 1Gi - moodle: - ## If defined, volume.beta.kubernetes.io/storage-class: - ## Default: volume.alpha.kubernetes.io/storage-class: default - ## - # storageClass: - accessMode: ReadWriteOnce - size: 8Gi + ## If defined, volume.beta.kubernetes.io/storage-class: + ## Default: volume.alpha.kubernetes.io/storage-class: default + ## + # storageClass: + accessMode: ReadWriteOnce + size: 8Gi + #existingClaim: "" + +## Define affinity for the moodle pod +## Sometimes required when persistent volumes are defined externally +## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector +# affinity: +# nodeAffinity: +# requiredDuringSchedulingIgnoredDuringExecution: +# nodeSelectorTerms: +# - matchExpressions: +# - key: node-role.kubernetes.io/master +# operator: In +# values: +# - machine01 +# preferredDuringSchedulingIgnoredDuringExecution: +# - weight: 1 +# preference: +# matchExpressions: +# - key: another-node-label-key +# operator: In +# values: +# - another-node-label-value ## Configure resource requests and limits ## ref: http://kubernetes.io/docs/user-guide/compute-resources/