Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add geoserver helm chart #17

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/geoserver/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove all these extensions and leave only the ones that apply to our project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was generated by helm, i removed some of the unused stuff..

# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
5 changes: 5 additions & 0 deletions src/geoserver/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "2.13.0"
description: A Helm chart for Kubernetes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the description, this will be visible for users who want to install the chart.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

name: geoserver
version: 0.1.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we don't start at 0.0.1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched to 0.0.1 for consistency with the other modules

19 changes: 19 additions & 0 deletions src/geoserver/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range .Values.ingress.hosts }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "geoserver.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "geoserver.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "geoserver.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "geoserver.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these instructions accurate? Can I access the app if I follow these steps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the target port for port-forward

{{- end }}
16 changes: 16 additions & 0 deletions src/geoserver/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "geoserver.name" -}}
{{- default .Chart.Name .Values.nameOverride | 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).
*/}}
{{- define "geoserver.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
153 changes: 153 additions & 0 deletions src/geoserver/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ .Chart.Name }}
labels:
app: {{ .Chart.Name }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Chart.Version }}
heritage: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
release: {{ .Chart.Version }}
spec:
initContainers:
- name: init
image: postgres:9.3-alpine
command: ['bash', '-c', './scripts/init.sh']
env:
- name: PGHOST
valueFrom :
secretKeyRef:
name: {{ .Values.database.secret }}
key: host
- name: PGUSER
valueFrom:
secretKeyRef:
name: {{ .Values.database.secret }}
key: user
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.database.secret }}
key: password
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: {{ .Values.application.secret }}
key: geoserver-database-user
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.application.secret }}
key: geoserver-database-password
- name: DB_NAME
valueFrom:
secretKeyRef:
name: {{ .Values.application.secret }}
key: geoserver-database-name
volumeMounts:
- mountPath: /scripts
name: geoserver-init
- name: {{ .Chart.Name }}
mountPath: {{ .Values.application.data_mount }}
{{ if .Values.provider.gcp }}
- name: cloudsql-instance-credentials
mountPath: /secrets/cloudsql
readOnly: true
{{ end }}
containers:
{{ if .Values.provider.gcp }}
- name: cloudsql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's useful to have a pullPolicy for every image, in case we need to force a re-download.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unlikely to happen for a 3rd party image, the default of IfNotPresent should be ok

command: ["/cloud_sql_proxy",
"-instances={{ .Values.database.instance }}=tcp:5432",
"-credential_file=/secrets/cloudsql/credentials.json"]
volumeMounts:
- name: cloudsql-instance-credentials
mountPath: /secrets/cloudsql
readOnly: true
{{ end }}
- name: {{ .Chart.Name }}
image: "{{ .Values.geoserver.repository }}:{{ .Values.geoserver.tag | default .Chart.AppVersion }}"
ports:
- containerPort: 8080
livenessProbe:
initialDelaySeconds: 120
periodSeconds: 10
httpGet:
path: /
port: 8080
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these port numbers should use the values defined in the values file.

httpHeaders:
- name: X-Kubernetes-Health-Check
value: livenessProbe
- name: Host
value: {{ .Values.url }}
readinessProbe:
initialDelaySeconds: 120
periodSeconds: 10
httpGet:
path: /
port: 8080
httpHeaders:
- name: X-Kubernetes-Health-Check
value: check
- name: Host
value: {{ .Values.url }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: DEBUG
value: {{ quote .Values.debug }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inconsistent with how the other charts handle the DEBUG value. Is this because of an app constraint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adapted to other charts

{{- if .Values.extra_env_vars -}}
{{- range $key, $value := .Values.extra_env_vars }}
- name: {{ $key }}
value: {{ . | quote }}
{{- end -}}
{{ end }}
- name: GEOSERVER_DATA_DIR
value: {{ .Values.application.data_mount }}
- name: PGUSER
valueFrom:
secretKeyRef:
name: {{ .Values.application.secret }}
key: geoserver-database-user
- name: PGPORT
value: "5432"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should come from the values file.

- name: PGHOST
valueFrom :
secretKeyRef:
name: {{ .Values.database.secret }}
key: host
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.application.secret }}
key: geoserver-database-password
- name: DB_NAME
valueFrom:
secretKeyRef:
name: {{ .Values.application.secret }}
key: geoserver-database-name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a secret?

volumeMounts:
- name: {{ .Chart.Name }}
mountPath: {{ .Values.application.data_mount }}
imagePullSecrets:
- name: regsecret
volumes:
- name: {{ .Chart.Name }}
MrPink marked this conversation as resolved.
Show resolved Hide resolved
persistentVolumeClaim:
claimName: {{ .Chart.Name }}
- name: geoserver-init
configMap:
name: geoserver-init
defaultMode: 0744
{{ if .Values.provider.gcp }}
- name: cloudsql-instance-credentials
secret:
secretName: cloudsql-instance-credentials
{{ end }}
restartPolicy: Always
34 changes: 34 additions & 0 deletions src/geoserver/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{- $serviceName := include "geoserver.name" . -}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between include and template? Why do we have a variable for one but not for the other?

{{- $servicePort := .Values.service.externalPort -}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add the indirection of a variable for a simple value? If servicePort is a better name than externalPort then we should change the value name instead. And why is it only renamed here and not in service.yaml?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is used directly the templating fails, because {{ .Values.service.externalPort }}can not be resolved inside the loop

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ template "geoserver.name" . }}
labels:
app: {{ template "geoserver.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
annotations:
{{- range $key, $value := .Values.ingress.annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
tls:
- hosts:
{{- range .Values.ingress.hosts }}
- {{ . }}
{{- end }}
{{ if not .Values.ingress.certsecret|empty -}}
secretName: {{ .Values.ingress.certsecret -}}
{{ end }}
rules:
{{- range $host := .Values.ingress.hosts }}
- host: {{ $host }}
http:
paths:
- path: /
backend:
serviceName: {{ $serviceName }}
servicePort: {{ $servicePort }}
{{- end -}}
46 changes: 46 additions & 0 deletions src/geoserver/templates/init-config-map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: geoserver-init
data:
{{- if .Values.provider.gcp }}
init.sh: |
#!/bin/bash
apk add --no-cache ca-certificates && update-ca-certificates
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O /cloud_sql_proxy
chmod +x /cloud_sql_proxy
echo 8.8.8.8 >>/etc/resolv.conf
echo "starting proxy in background"
/cloud_sql_proxy -instances={{ .Values.database.instance }}=tcp:5432 -credential_file=/secrets/cloudsql/credentials.json &
PROXY_PID=$!
sleep 5

psql -c "CREATE DATABASE $DB_NAME;"
psql -c "CREATE USER $DB_USERNAME WITH PASSWORD '$DB_PASSWORD';"
psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USERNAME;"
psql -d $DB_NAME -c "CREATE EXTENSION postgis;"
psql -d $DB_NAME -c "CREATE EXTENSION postgis_topology;"
psql -d $DB_NAME -c "CREATE EXTENSION fuzzystrmatch;"
psql -d $DB_NAME -c "CREATE EXTENSION postgis_tiger_geocoder;"

echo "sql executed.."
sleep 5

echo "stopping proxy"
kill $PROXY_PID
# Fix EFS mount permissions
# chmod -R 775 /media
# chown -R 1000:101 /media

{{ else }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{{- else }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing whitespace here does not make things better but instead can give problems

init.sh: |
#!/bin/bash
psql -c "CREATE DATABASE $DB_NAME;"
psql -c "CREATE USER $DB_USERNAME WITH PASSWORD '$DB_PASSWORD';"
psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USERNAME;"

# Fix EFS mount permissions
# chmod -R 775 /media
# chown -R 1000:101 /media

{{- end -}}
17 changes: 17 additions & 0 deletions src/geoserver/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Chart.Name }}
labels:
app: {{ .Chart.Name }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.externalPort }}
targetPort: {{ .Values.service.internalPort }}
protocol: TCP
selector:
app: {{ .Chart.Name }}
39 changes: 39 additions & 0 deletions src/geoserver/templates/volume_claim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{- if .Values.provider.aws -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ .Chart.Name }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other charts we added the suffix -pvc to the claims, so that when in the logs we see the {{ .Chart.Name }} we know immediately what we are talking about.

annotations:
volume.beta.kubernetes.io/storage-class: "aws-efs"
spec:
accessModes:
- ReadWriteMany
resources:
requests:
# This is not used by the provisioner, but is required by the PVC.
storage: 1Mi
{{- else if .Values.provider.gcp }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ .Chart.Name }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
{{- else -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ .Chart.Name }}
spec:
accessModes:
- ReadWriteMany
hostPath:
path: /data/pv0001
resources:
requests:
storage: 1Mi
{{- end -}}
Loading