[bitnami/apache] Allow custom htdocs

Signed-off-by: Javier Salmeron Garcia <jsalmeron@vmware.com>
This commit is contained in:
Javier Salmeron Garcia
2019-06-04 11:33:36 +02:00
parent 5e32fdc467
commit 4ddd3ca795
8 changed files with 293 additions and 84 deletions

View File

@@ -1,6 +1,6 @@
apiVersion: v1
name: apache
version: 4.3.0
version: 5.0.0
appVersion: 2.4.39
description: Chart for Apache HTTP Server
keywords:

View File

@@ -44,41 +44,53 @@ The command removes all the Kubernetes components associated with the chart and
The following tables lists the configurable parameters of the Apache chart and their default values.
| Parameter | Description | Default |
|----------------------------------|--------------------------------------------------|--------------------------------------------------------------|
| `global.imageRegistry` | Global Docker image registry | `nil` |
| `global.imagePullSecrets` | Global Docker registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) |
| `image.registry` | Apache Docker image registry | `docker.io` |
| `image.repository` | Apache Docker image name | `bitnami/apache` |
| `image.tag` | Apache Docker image tag | `{TAG_NAME}` |
| `image.pullPolicy` | Apache Docker image pull policy | `Always` |
| `image.pullSecrets` | Specify Docker registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) |
| `podAnnotations` | Pod annotations | `{}` |
| `ingress.enabled` | Enable ingress controller resource | `false` |
| `ingress.certManager` | Add annotations for cert-manager | `false` |
| `ingress.annotations` | Ingress annotations | `[]` |
| `ingress.hosts[0].name` | Hostname to your Apache installation | `example.local` |
| `ingress.hosts[0].path` | Path within the url structure | `/` |
| `ingress.tls[0].hosts[0]` | TLS hosts | `example.local` |
| `ingress.tls[0].secretName` | TLS Secret (certificates) | `example.local-tls` |
| `ingress.secrets[0].name` | TLS Secret Name | `nil` |
| `ingress.secrets[0].certificate` | TLS Secret Certificate | `nil` |
| `ingress.secrets[0].key` | TLS Secret Key | `nil` |
| `metrics.enabled` | Start a side-car prometheus exporter | `false` |
| `metrics.image.registry` | Apache exporter image registry | `docker.io` |
| `metrics.image.repository` | Apache exporter image name | `lusotycoon/apache-exporter` |
| `metrics.image.tag` | Apache exporter image tag | `v0.5.0` |
| `metrics.image.pullPolicy` | Apache exporter image pull policy | `IfNotPresent` |
| `metrics.image.pullSecrets` | Specify Docker registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) |
| `metrics.podAnnotations` | Additional annotations for Metrics exporter pod | `{prometheus.io/scrape: "true", prometheus.io/port: "9117"}` |
| `metrics.resources` | Exporter resource requests/limit | {} |
| `service.type` | Kubernetes Service type | `LoadBalancer` |
| `service.port` | Service HTTP port | `80` |
| `service.httpsPort` | Service HTTPS port | `443` |
| `service.nodePorts.http` | Kubernetes http node port | `""` |
| `service.nodePorts.https` | Kubernetes https node port | `""` |
| `service.externalTrafficPolicy` | Enable client source IP preservation | `Cluster` |
| `service.loadBalancerIP` | LoadBalancer service IP address | `""` |
| Parameter | Description | Default |
|----------------------------------|---------------------------------------------------------|--------------------------------------------------------------|
| `global.imageRegistry` | Global Docker image registry | `nil` |
| `global.imagePullSecrets` | Global Docker registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) |
| `image.registry` | Apache Docker image registry | `docker.io` |
| `image.repository` | Apache Docker image name | `bitnami/apache` |
| `image.tag` | Apache Docker image tag | `{TAG_NAME}` |
| `image.pullPolicy` | Apache Docker image pull policy | `Always` |
| `image.pullSecrets` | Specify Docker registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) |
| `git.registry` | Git image registry | `docker.io` |
| `git.repository` | Git image name | `bitnami/git` |
| `git.tag` | Git image tag | `{TAG_NAME}` |
| `git.pullPolicy` | Git image pull policy | `Always` |
| `git.pullSecrets` | Specify docker-registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) |
| `replicaCount` | Number of replicas of the Apache deployment | `docker.io` |
| `htdocsConfigMap` | ConfigMap with the server static content | `nil` |
| `htdocsPVC` | PVC with the server static content | `nil` |
| `cloneHtdocsFromGit.enabled` | Get the server static content from a git repository | `false` |
| `cloneHtdocsFromGit.repository` | Repository to clone static content from | `nil` |
| `cloneHtdocsFromGit.branch` | Branch inside the git repository | `nil` |
| `cloneHtdocsFromGit.interval` | Interval for sidecar container pull from the repository | `60` |
| `podAnnotations` | Pod annotations | `{}` |
| `ingress.enabled` | Enable ingress controller resource | `false` |
| `ingress.certManager` | Add annotations for cert-manager | `false` |
| `ingress.annotations` | Ingress annotations | `[]` |
| `ingress.hosts[0].name` | Hostname to your Apache installation | `example.local` |
| `ingress.hosts[0].path` | Path within the url structure | `/` |
| `ingress.tls[0].hosts[0]` | TLS hosts | `example.local` |
| `ingress.tls[0].secretName` | TLS Secret (certificates) | `example.local-tls` |
| `ingress.secrets[0].name` | TLS Secret Name | `nil` |
| `ingress.secrets[0].certificate` | TLS Secret Certificate | `nil` |
| `ingress.secrets[0].key` | TLS Secret Key | `nil` |
| `metrics.enabled` | Start a side-car prometheus exporter | `false` |
| `metrics.image.registry` | Apache exporter image registry | `docker.io` |
| `metrics.image.repository` | Apache exporter image name | `lusotycoon/apache-exporter` |
| `metrics.image.tag` | Apache exporter image tag | `v0.5.0` |
| `metrics.image.pullPolicy` | Apache exporter image pull policy | `IfNotPresent` |
| `metrics.image.pullSecrets` | Specify Docker registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) |
| `metrics.podAnnotations` | Additional annotations for Metrics exporter pod | `{prometheus.io/scrape: "true", prometheus.io/port: "9117"}` |
| `metrics.resources` | Exporter resource requests/limit | {} |
| `service.type` | Kubernetes Service type | `LoadBalancer` |
| `service.port` | Service HTTP port | `80` |
| `service.httpsPort` | Service HTTPS port | `443` |
| `service.nodePorts.http` | Kubernetes http node port | `""` |
| `service.nodePorts.https` | Kubernetes https node port | `""` |
| `service.externalTrafficPolicy` | Enable client source IP preservation | `Cluster` |
| `service.loadBalancerIP` | LoadBalancer service IP address | `""` |
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
@@ -98,6 +110,21 @@ $ helm install --name my-release -f values.yaml bitnami/apache
> **Tip**: You can use the default [values.yaml](values.yaml)
## Deploying your custom web application
The Apache chart allows you to deploy a custom web application using one of the following methods:
- Cloning from a git repository: Set `cloneHtdocsFromGit.enabled` to `true` and set the repository and branch using the `cloneHtdocsFromGit.repository` and `cloneHtdocsFromGit.branch` parameters. A sidecar will also pull the latest changes in an interval set by `cloneHtdocsFromGit.interval`.
- Providing a ConfigMap: Set the `htdocsConfigMap` value to mount a ConfigMap in the Apache htdocs folder.
- Using an existing PVC: Set the `htdocsPVC` value to mount an PersistentVolumeClaim with the web application content.
In the following example you can deploy a example web application using git:
```
helm install bitnami/apache --set cloneHtdocsFromGit.enabled=true --set cloneHtdocsFromGit.repository=https://github.com/mdn/beginner-html-site-styled.git --set cloneHtdocsFromGit.branch=master
```
You may also want to mount different virtual host configurations. This can be done using the `vhostsConfigMap` value. This a pointer to a ConfigMap with the desired Apache virtual host configurations.
### [Rolling VS Immutable tags](https://docs.bitnami.com/containers/how-to/understand-rolling-tags-containers/)
It is strongly recommended to use immutable tags in a production environment. This ensures your deployment does not change automatically if the same tag is updated with a different image.

View File

@@ -1,6 +1,12 @@
{{ include "apache.validateValues" . }}
{{- if not (include "apache.useHtdocs" .)}}
WARNING: You did not provide a custom web application. Apache will be deployed with a default page. Check the README section "Deploying your custom web application" in https://github.com/bitnami/charts/blob/master/bitnami/apache/README.md#deploying-your-custom-web-application.
{{- end }}
{{- if and (contains "bitnami/" .Values.image.repository) (not (.Values.image.tag | toString | regexFind "-r\\d+$|sha256:")) }}
WARNING: Rolling tag detected ({{ .Values.image.repository }}:{{ .Values.image.tag }}), please note that it is strongly recommended to avoid using rolling tags in a production environment.
+info https://docs.bitnami.com/containers/how-to/understand-rolling-tags-containers/
{{- end }}
{{- end }}

View File

@@ -95,3 +95,95 @@ Also, we can't use a single if because lazy evaluation is not an option
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
{{- end -}}
{{- end -}}
{{/*
Return true if mouting a static web page
*/}}
{{- define "apache.useHtdocs" -}}
{{ or .Values.cloneHtdocsFromGit.enabled .Values.htdocsConfigMap .Values.htdocsPVC }}
{{- end -}}
{{/*
Return associated volume
*/}}
{{- define "apache.htdocsVolume" -}}
{{- if .Values.cloneHtdocsFromGit.enabled }}
emptyDir: {}
{{- else if .Values.htdocsConfigMap }}
configMap:
name: {{ .Values.htdocsConfigMap }}
{{- else if .Values.htdocsPVC }}
persistentVolumeClaim:
claimName: {{ .Values.htdocsPVC }}
{{- end }}
{{- end -}}
{{/*
Validate data
*/}}
{{- define "apache.validateValues" -}}
{{- $messages := list -}}
{{- $messages := append $messages (include "apache.validateValues.htdocs" .) -}}
{{- $messages := append $messages (include "apache.validateValues.htdocsGit" .) -}}
{{- $messages := without $messages "" -}}
{{- $message := join "\n" $messages -}}
{{- if $message -}}
{{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
{{- end -}}
{{- end -}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "apache.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Validate data (htdocs)
*/}}
{{- define "apache.validateValues.htdocs" -}}
{{- if or (and .Values.cloneHtdocsFromGit.enabled (or .Values.htdocsPVC .htdocsConfigMap )) (and .Values.htdocsPVC (or .Values.htdocsConfigMap .Values.cloneHtdocsFromGit.enabled )) (and .Values.htdocsConfigMap (or .Values.htdocsPVC .Values.cloneHtdocsFromGit.enabled )) }}
apache: htdocs
You have selected more than one way of deploying htdocs. Please select only one of htdocsConfigMap cloneHtdocsFromGit or htdocsVolume
{{- end }}
{{- end -}}
{{/*
Validate data (htdocs git)
*/}}
{{- define "apache.validateValues.htdocsGit" -}}
{{- if .Values.cloneHtdocsFromGit.enabled }}
{{- if not .Values.cloneHtdocsFromGit.repository }}
apache: htdocs-git-repository
You did not specify a git repository to clone. Please set cloneHtdocsFromGit.repository
{{- end }}
{{- if not .Values.cloneHtdocsFromGit.branch }}
apache: htdocs-git-branch
You did not specify a branch to checkout in the git repository. Please set cloneHtdocsFromGit.branch
{{- end }}
{{- end -}}
{{- end -}}
{{/*
Return the proper git image name
*/}}
{{- define "git.image" -}}
{{- $registryName := .Values.git.registry -}}
{{- $repositoryName := .Values.git.repository -}}
{{- $tag := .Values.git.tag | toString -}}
{{/*
Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
Also, we can't use a single if because lazy evaluation is not an option
*/}}
{{- if .Values.global }}
{{- if .Values.global.imageRegistry }}
{{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
{{- else -}}
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
{{- end -}}
{{- else -}}
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
{{- end -}}
{{- end -}}

View File

@@ -3,34 +3,34 @@ kind: Deployment
metadata:
name: {{ template "apache.fullname" . }}
labels:
app: {{ template "apache.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
app.kubernetes.io/name: {{ template "apache.fullname" . }}
helm.sh/chart: {{ include "apache.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
selector:
matchLabels:
app: {{ template "apache.fullname" . }}
release: "{{ .Release.Name }}"
replicas: 1
app.kubernetes.io/name: {{ template "apache.fullname" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
replicas: {{ .Values.replicaCount }}
template:
metadata:
labels:
app: {{ template "apache.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- if or .Values.podAnnotations .Values.metrics.enabled }}
app.kubernetes.io/name: {{ template "apache.fullname" . }}
helm.sh/chart: {{ include "apache.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if or .Values.podAnnotations .Values.metrics.enabled }}
annotations:
{{- if .Values.podAnnotations }}
{{ toYaml .Values.podAnnotations | indent 8 }}
{{- end }}
{{- if .Values.metrics.podAnnotations }}
{{ toYaml .Values.metrics.podAnnotations | indent 8 }}
{{- end }}
{{- end }}
{{- if .Values.podAnnotations }}
{{- toYaml .Values.podAnnotations | nindent 8 }}
{{- end }}
{{- if .Values.metrics.podAnnotations }}
{{- toYaml .Values.metrics.podAnnotations | nindent 8 }}
{{- end }}
{{- end }}
spec:
{{- include "apache.imagePullSecrets" . | indent 6 }}
{{- include "apache.imagePullSecrets" . | nindent 6 }}
hostAliases:
- ip: "127.0.0.1"
hostnames:
@@ -44,10 +44,10 @@ spec:
- /bin/bash
- -ec
- |
git clone {{ .Values.airflow.cloneDagFilesFromGit.repository }} --branch {{ .Values.airflow.cloneDagFilesFromGit.branch }} /app
git clone {{ .Values.cloneHtdocsFromGit.repository }} --branch {{ .Values.cloneHtdocsFromGit.branch }} /app
volumeMounts:
- name: git-cloned-dag-files
mountPath: /dags
- name: htdocs
mountPath: /app
containers:
- name: git-repo-syncer
image: "{{ template "git.image" . }}"
@@ -57,17 +57,16 @@ spec:
- -ec
- |
while true; do
cd /app && git pull origin {{ .Values.airflow.cloneDagFilesFromGit.branch }}
sleep {{ default "60" .Values.airflow.cloneDagFilesFromGit.interval }}
cd /app && git pull origin {{ .Values.cloneHtdocsFromGit.branch }}
sleep {{ .Values.cloneHtdocsFromGit.interval }}
done
volumeMounts:
- name: htdocs
mountPath: /app
{{- else -}}
{{- else }}
containers:
{{- end }}
- name: {{ template "apache.fullname" . }}
- name: "{{ template "apache.fullname" . }}"
image: "{{ template "apache.image" . }}"
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
ports:
@@ -75,21 +74,39 @@ spec:
containerPort: 8080
- name: https
containerPort: 8443
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 30
timeoutSeconds: 5
failureThreshold: 6
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
successThreshold: {{ .Values.livenessProbe.successThreshold }}
failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
{{- end }}
{{- if .Values.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 5
timeoutSeconds: 3
periodSeconds: 5
{{- if .Values.metrics.enabled }}
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
successThreshold: {{ .Values.readinessProbe.successThreshold }}
failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
{{- end }}
resources: {{ toYaml .Values.resources | nindent 10 }}
volumeMounts:
{{- if (include "apache.useHtdocs" .) }}
- name: htdocs
mountPath: /app
{{- end }}
{{- if .Values.vhostsConfigMap }}
- name: vhosts
mountPath: /vhosts
{{- end }}
{{- if .Values.metrics.enabled }}
- name: metrics
image: {{ template "apache.metrics.image" . }}
imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
@@ -109,6 +126,15 @@ spec:
port: metrics
initialDelaySeconds: 5
timeoutSeconds: 1
resources:
{{ toYaml .Values.metrics.resources | indent 10 }}
{{- end }}
resources: {{ toYaml .Values.metrics.resources | nindent 10 }}
{{- end }}
volumes:
{{- if (include "apache.useHtdocs" .) }}
- name: htdocs
{{- include "apache.htdocsVolume" . | nindent 8 }}
{{- end }}
{{- if .Values.vhostsConfigMap }}
- name: vhosts
configMap:
name: {{ .Values.vhostsConfigMap }}
{{- end }}

View File

@@ -4,10 +4,10 @@ kind: Ingress
metadata:
name: {{ template "apache.fullname" . }}
labels:
app: "{{ template "apache.fullname" . }}"
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
app.kubernetes.io/name: {{ template "apache.fullname" . }}
helm.sh/chart: {{ include "apache.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
annotations:
{{- if .Values.ingress.certManager }}
kubernetes.io/tls-acme: "true"

View File

@@ -3,10 +3,10 @@ kind: Service
metadata:
name: {{ template "apache.fullname" . }}
labels:
app: {{ template "apache.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
app.kubernetes.io/name: {{ template "apache.fullname" . }}
helm.sh/chart: {{ include "apache.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
{{- if (or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort")) }}
@@ -29,4 +29,4 @@ spec:
nodePort: {{ .Values.service.nodePorts.https }}
{{- end }}
selector:
app: {{ template "apache.fullname" . }}
app.kubernetes.io/name: {{ template "apache.fullname" . }}

View File

@@ -25,11 +25,69 @@ image:
# pullSecrets:
# - myRegistryKeySecretName
## Bitnami git image version
## ref: https://hub.docker.com/r/bitnami/git/tags/
##
git:
registry: docker.io
repository: bitnami/git
tag: 2.21.0-debian-9-r72
pullPolicy: IfNotPresent
## Optionally specify an array of imagePullSecrets.
## Secrets must be manually created in the namespace.
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
##
# pullSecrets:
# - myRegistryKeySecretName
replicaCount: 1
cloneHtdocsFromGit:
enabled: false
# repository:
# branch:
interval: 60
# htdocsConfigMap:
# htdocsPVC:
# vhostsConfigMap:
## Pod annotations
## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
##
podAnnotations: {}
## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
resources:
# limits:
# cpu: 200m
# memory: 1Gi
# requests:
# memory: 256Mi
# cpu: 250m
## Configure extra options for liveness and readiness probes
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#configure-probes)
livenessProbe:
enabled: true
initialDelaySeconds: 180
periodSeconds: 20
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
readinessProbe:
enabled: true
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
## Configure the ingress resource that allows you to access the
## Apache installation. Set up the URL
## ref: http://kubernetes.io/docs/user-guide/ingress/