From 9797037660c8c4fe8edab4317427c3081ff77f58 Mon Sep 17 00:00:00 2001 From: Edson Raigosa Date: Wed, 10 Mar 2021 11:34:13 -0500 Subject: [PATCH] adding k8s support with helm --- .gitignore | 3 ++ README.md | 8 +++ charts/tileserver-gl/.helmignore | 25 +++++++++ charts/tileserver-gl/Chart.yaml | 23 ++++++++ charts/tileserver-gl/templates/_helpers.tpl | 32 ++++++++++++ .../tileserver-gl/templates/deployment.yaml | 52 +++++++++++++++++++ charts/tileserver-gl/templates/ingress.yaml | 18 +++++++ charts/tileserver-gl/templates/pv.yaml | 14 +++++ charts/tileserver-gl/templates/pvc.yaml | 11 ++++ charts/tileserver-gl/templates/service.yaml | 19 +++++++ charts/tileserver-gl/values.yaml | 44 ++++++++++++++++ 11 files changed, 249 insertions(+) create mode 100644 charts/tileserver-gl/.helmignore create mode 100644 charts/tileserver-gl/Chart.yaml create mode 100644 charts/tileserver-gl/templates/_helpers.tpl create mode 100644 charts/tileserver-gl/templates/deployment.yaml create mode 100644 charts/tileserver-gl/templates/ingress.yaml create mode 100644 charts/tileserver-gl/templates/pv.yaml create mode 100644 charts/tileserver-gl/templates/pvc.yaml create mode 100644 charts/tileserver-gl/templates/service.yaml create mode 100644 charts/tileserver-gl/values.yaml diff --git a/.gitignore b/.gitignore index 2009454de..806a563b0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ light plugins config.json *.mbtiles + +#visual studio IDE +**/.vs/ \ No newline at end of file diff --git a/README.md b/README.md index 7e2f9a933..6db6ac47f 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,14 @@ This will download and start a ready to use container on your computer and the m On laptop you can use [Docker Kitematic](https://kitematic.com/) and search "tileserver-gl" and run it, then drop in the 'data' folder the MBTiles. +## Using Kubernetes/helm + +```bash +helm install tileserver-gl .\tileserver-gl\ -n default +``` + +you can now access the service (kubectl get svc) via port-forward or you can change the service type configuration to LoadBalancer or even activate the ingres/traefik routing. + ## Documentation You can read full documentation of this project at https://tileserver.readthedocs.io/. diff --git a/charts/tileserver-gl/.helmignore b/charts/tileserver-gl/.helmignore new file mode 100644 index 000000000..4e9204848 --- /dev/null +++ b/charts/tileserver-gl/.helmignore @@ -0,0 +1,25 @@ +# 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 +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ +*/bin/ +*/obj/ \ No newline at end of file diff --git a/charts/tileserver-gl/Chart.yaml b/charts/tileserver-gl/Chart.yaml new file mode 100644 index 000000000..3cd118337 --- /dev/null +++ b/charts/tileserver-gl/Chart.yaml @@ -0,0 +1,23 @@ +apiVersion: v2 +name: dev +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +appVersion: 1.16.0 diff --git a/charts/tileserver-gl/templates/_helpers.tpl b/charts/tileserver-gl/templates/_helpers.tpl new file mode 100644 index 000000000..fa55cd9e6 --- /dev/null +++ b/charts/tileserver-gl/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "dev.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). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "dev.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "dev.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/charts/tileserver-gl/templates/deployment.yaml b/charts/tileserver-gl/templates/deployment.yaml new file mode 100644 index 000000000..871db0cae --- /dev/null +++ b/charts/tileserver-gl/templates/deployment.yaml @@ -0,0 +1,52 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "dev.fullname" . }} + labels: + app: {{ template "dev.name" . }} + chart: {{ template "dev.chart" . }} + draft: {{ .Values.draft | default "draft-app" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ template "dev.name" . }} + release: {{ .Release.Name }} + template: + metadata: + labels: + app: {{ template "dev.name" . }} + draft: {{ .Values.draft | default "draft-app" }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + #command: ["sh", "-c", "tail -f /dev/null"] + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + volumeMounts: + - name: {{ .Values.volume.name }} + mountPath: {{ .Values.volume.mountPath }} + ports: + - name: http + containerPort: {{ .Values.deployment.containerPort }} + protocol: TCP + securityContext: + allowPrivilegeEscalation: false + runAsUser: 0 + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + volumes: + - name: {{ .Values.volume.name }} + persistentVolumeClaim: + claimName: {{ .Values.volume.persistentVolumeClaim.claimName }} + diff --git a/charts/tileserver-gl/templates/ingress.yaml b/charts/tileserver-gl/templates/ingress.yaml new file mode 100644 index 000000000..252d33564 --- /dev/null +++ b/charts/tileserver-gl/templates/ingress.yaml @@ -0,0 +1,18 @@ +apiVersion: traefik.containo.us/v1alpha1 +kind: IngressRoute +metadata: + name: openmaptileserver +{{- with .Values.ingress.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} +spec: + entryPoints: + - websecure + - web + routes: + - match: Host(`{{ .Values.ingress.dnsname }}`) + kind: Rule + services: + - name: {{ .Values.service.name }} + port: {{ .Values.service.port }} diff --git a/charts/tileserver-gl/templates/pv.yaml b/charts/tileserver-gl/templates/pv.yaml new file mode 100644 index 000000000..f40c6d15b --- /dev/null +++ b/charts/tileserver-gl/templates/pv.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{ .Values.volume.name }} + labels: + type: local +spec: + storageClassName: manual + capacity: + storage: {{ .Values.volume.storage }} + accessModes: + - ReadWriteOnce + hostPath: + path: {{ .Values.volume.mountPath }} diff --git a/charts/tileserver-gl/templates/pvc.yaml b/charts/tileserver-gl/templates/pvc.yaml new file mode 100644 index 000000000..8fead7b70 --- /dev/null +++ b/charts/tileserver-gl/templates/pvc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ .Values.volume.persistentVolumeClaim.claimName }} +spec: + storageClassName: manual + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.volume.storage }} \ No newline at end of file diff --git a/charts/tileserver-gl/templates/service.yaml b/charts/tileserver-gl/templates/service.yaml new file mode 100644 index 000000000..8a7e739f2 --- /dev/null +++ b/charts/tileserver-gl/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "dev.fullname" . }} + labels: + app: {{ template "dev.name" . }} + chart: {{ template "dev.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + app: {{ template "dev.name" . }} + release: {{ .Release.Name }} diff --git a/charts/tileserver-gl/values.yaml b/charts/tileserver-gl/values.yaml new file mode 100644 index 000000000..a96129490 --- /dev/null +++ b/charts/tileserver-gl/values.yaml @@ -0,0 +1,44 @@ +# Default values for OpenMapTiles. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 245136312710.dkr.ecr.ca-central-1.amazonaws.com/tileserverglolameter + tag: latest + pullPolicy: Always + +imagePullSecrets: [] + +ingress: + enabled: false + dnsname: openmaptilese.some-dns.com + annotations: {} + # kubernetes.io/tls-acme: "true" + path: / + # hosts: + # - chart-example.local + tls: {} + +service: + type: ClusterIP + port: 8081 + name: openmaptile-svc + +volume: + name: openmaptiles-dataset + persistentVolumeClaim: + claimName: openmaptilesefs-claim + persistentVolume: + pvName: openmaptiles-pv +#This mountPath is related to the config file configuration + mountPath: /data + storage: 20Gi + +storageClass: + name: openmaptilesefs + +#This port is related to the activated dockerfile port +deployment: + containerPort: 8080 \ No newline at end of file