This commit is contained in:
Pitchaya Boonsarngsuk
2019-07-05 16:54:32 +01:00
commit c3d3dcbff7
96 changed files with 32248 additions and 0 deletions

22
api/helm/api/.helmignore Normal file
View File

@@ -0,0 +1,22 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/

7
api/helm/api/Chart.yaml Normal file
View File

@@ -0,0 +1,7 @@
apiVersion: v1
appVersion: 0.1.0
description: A Helm chart for an API Platform API
name: api
version: 0.1.0
home: https://api-platform.com
icon: https://api-platform.com/logo-250x250.png

View File

@@ -0,0 +1,9 @@
dependencies:
- name: postgresql
repository: https://kubernetes-charts.storage.googleapis.com/
version: 3.9.5
- name: mercure
repository: https://kubernetes-charts.storage.googleapis.com/
version: 1.0.0
digest: sha256:6466d376987cc08b70fe36945dd93474836aab05edc155955951bcb0774a0896
generated: 2019-03-26T18:14:32.4074+01:00

View File

@@ -0,0 +1,9 @@
dependencies:
- name: postgresql
version: ~3.9.0
repository: https://kubernetes-charts.storage.googleapis.com/
condition: postgresql.enabled
- name: mercure
version: ~1.0.0
repository: https://kubernetes-charts.storage.googleapis.com/
condition: mercure.enabled

View File

@@ -0,0 +1,5 @@
API deployed.
To get the ingress's IP:
kubectl --namespace {{ .Release.Namespace }} get ingress -o jsonpath="{.items[0].status.loadBalancer.ingress[0].ip}"

View File

@@ -0,0 +1,27 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "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 "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- define "postgresql.fullname" -}}
{{- printf "%s-%s" .Release.Name "postgresql" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "fullname" . }}
labels:
app.kubernetes.io/name: {{ include "name" . }}
app.kubernetes.io/part-of: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
data:
env: {{ .Values.php.env | quote }}
debug: {{ .Values.php.debug | quote }}
cors-allow-origin: {{ .Values.php.corsAllowOrigin | quote }}
varnish-url: {{ if .Values.varnish.enabled }}http://varnish{{ else }}{{ .Values.varnish.url | quote }}{{ end }}
trusted-hosts: {{ .Values.php.trustedHosts | quote }}
trusted-proxies: {{ join "," .Values.php.trustedProxies }}
mercure-publish-url: {{ .Values.mercure.publishUrl | quote }}
mercure-subscribe-url: {{ .Values.mercure.subscribeUrl | quote }}

View File

@@ -0,0 +1,35 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ template "fullname" . }}
labels:
app.kubernetes.io/name: {{ include "name" . }}-ingress
app.kubernetes.io/part-of: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ .host | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
- path: /*
backend:
serviceName: {{ .serviceName }}
servicePort: {{ .servicePort | default 80 }}
{{- end }}

View File

@@ -0,0 +1,33 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}-nginx
labels:
app.kubernetes.io/name: {{ include "name" . }}-nginx
app.kubernetes.io/part-of: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.nginx.replicaCount }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "name" . }}-nginx
app.kubernetes.io/part-of: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
containers:
- name: {{ .Chart.Name }}-nginx
image: "{{ .Values.nginx.repository }}:{{ .Values.nginx.tag }}"
imagePullPolicy: {{ .Values.nginx.pullPolicy }}
ports:
- containerPort: 80
resources:
{{ toYaml .Values.resources | indent 12 }}
{{- if .Values.nodeSelector }}
nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
{{- end }}

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: api
labels:
app.kubernetes.io/name: {{ include "name" . }}-nginx
app.kubernetes.io/part-of: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app.kubernetes.io/name: {{ include "name" . }}-nginx
app.kubernetes.io/instance: {{ .Release.Name }}

View File

@@ -0,0 +1,89 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}-php
labels:
app.kubernetes.io/name: {{ include "name" . }}-php
app.kubernetes.io/part-of: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.php.replicaCount }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "name" . }}-php
app.kubernetes.io/part-of: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
containers:
- name: {{ .Chart.Name }}-php
image: "{{ .Values.php.repository }}:{{ .Values.php.tag }}"
imagePullPolicy: {{ .Values.php.pullPolicy }}
ports:
- containerPort: 9000
env:
- name: TRUSTED_HOSTS
valueFrom:
configMapKeyRef:
name: {{ template "fullname" . }}
key: trusted-hosts
- name: TRUSTED_PROXIES
valueFrom:
configMapKeyRef:
name: {{ template "fullname" . }}
key: trusted-proxies
- name: APP_ENV
valueFrom:
configMapKeyRef:
name: {{ template "fullname" . }}
key: env
- name: APP_DEBUG
valueFrom:
configMapKeyRef:
name: {{ template "fullname" . }}
key: debug
- name: CORS_ALLOW_ORIGIN
valueFrom:
configMapKeyRef:
name: {{ template "fullname" . }}
key: cors-allow-origin
- name: VARNISH_URL
valueFrom:
configMapKeyRef:
name: {{ template "fullname" . }}
key: varnish-url
- name: APP_SECRET
valueFrom:
secretKeyRef:
name: {{ template "fullname" . }}
key: secret
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: {{ template "fullname" . }}
key: database-url
- name: MERCURE_PUBLISH_URL
valueFrom:
configMapKeyRef:
name: {{ template "fullname" . }}
key: mercure-publish-url
- name: MERCURE_SUBSCRIBE_URL
valueFrom:
configMapKeyRef:
name: {{ template "fullname" . }}
key: mercure-subscribe-url
- name: MERCURE_JWT_SECRET
valueFrom:
secretKeyRef:
name: {{ template "fullname" . }}
key: mercure-jwt-secret
resources:
{{ toYaml .Values.resources | indent 12 }}
{{- if .Values.nodeSelector }}
nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
{{- end }}

View File

@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: php
labels:
app.kubernetes.io/name: {{ include "name" . }}-php
app.kubernetes.io/part-of: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
type: ClusterIP
ports:
- port: 9000
selector:
app.kubernetes.io/name: {{ include "name" . }}-php
app.kubernetes.io/instance: {{ .Release.Name }}

View File

@@ -0,0 +1,20 @@
{{- $postgresqlServiceName := include "postgresql.fullname" . -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ template "fullname" . }}
labels:
app.kubernetes.io/name: {{ include "name" . }}
app.kubernetes.io/part-of: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
type: Opaque
data:
{{ if .Values.postgresql.enabled }}
database-url: {{ printf "pgsql://%s:%s@%s/%s?serverVersion=9.6" .Values.postgresql.postgresqlUsername .Values.postgresql.postgresqlPassword $postgresqlServiceName .Values.postgresql.postgresqlDatabase | b64enc | quote }}
{{ else }}
database-url: {{ .Values.postgresql.url | b64enc | quote }}
{{ end }}
secret: {{ .Values.php.secret | default (randAlphaNum 40) | b64enc | quote }}
mercure-jwt-secret: {{ .Values.php.mercure.jwtSecret | b64enc | quote }}

View File

@@ -0,0 +1,44 @@
{{- if .Values.varnish.enabled -}}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}-varnish
labels:
app.kubernetes.io/name: {{ include "name" . }}-varnish
app.kubernetes.io/part-of: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.varnish.replicaCount }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "name" . }}-varnish
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
containers:
- name: {{ .Chart.Name }}-varnish
image: "{{ .Values.varnish.repository }}:{{ .Values.varnish.tag }}"
imagePullPolicy: {{ .Values.varnish.pullPolicy }}
command: ["varnishd"]
args: ["-F", "-f", "/usr/local/etc/varnish/default.vcl", "-p", "http_resp_hdr_len=65536", "-p", "http_resp_size=98304"]
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /healthz
port: 80
readinessProbe:
httpGet:
path: /healthz
port: 80
resources:
{{ toYaml .Values.resources | indent 12 }}
{{- if .Values.nodeSelector }}
nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
{{- end }}
{{- end -}}

View File

@@ -0,0 +1,21 @@
{{- if .Values.varnish.enabled -}}
apiVersion: v1
kind: Service
metadata:
name: varnish
labels:
app.kubernetes.io/name: {{ include "name" . }}-varnish
app.kubernetes.io/part-of: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app.kubernetes.io/name: {{ include "name" . }}-varnish
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

92
api/helm/api/values.yaml Normal file
View File

@@ -0,0 +1,92 @@
# Default values for api.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
php:
repository: quay.io/api-platform/php
tag: latest
pullPolicy: Always
replicaCount: 1
mercure:
jwtSecret: ""
env: prod
debug: '0'
secret: ""
corsAllowOrigin: "^https?://.*?\\.example\\.com$"
trustedHosts: "^.*\\.example\\.com$"
trustedProxies:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
nginx:
repository: quay.io/api-platform/nginx
tag: latest
pullPolicy: Always
replicaCount: 1
varnish:
enabled: true
#url: https://example.com
repository: quay.io/api-platform/varnish
tag: latest
pullPolicy: Always
replicaCount: 1
postgresql:
enabled: true
imageTag: 10-alpine
# If bringing your own PostgreSQL, the full uri to use
#url: pgsql://api-platform:!ChangeMe!@example.com/api?serverVersion=10.1
postgresqlUsername: "example"
postgresqlPassword: "!ChangeMe!"
postgresqlDatabase: "api"
# Persistent Volume Storage configuration.
# ref: https://kubernetes.io/docs/user-guide/persistent-volumes
persistence:
enabled: false
pullPolicy: IfNotPresent
# image:
# repository: postgres
# tag: alpine
mercure:
enabled: true
publishUrl: http://mercure/hub
subscribeUrl: https://mercure.example.com/hub
allowAnonymous: "1"
corsAllowedOrigins: "^https?://.*?\\.example\\.com$"
acmeHosts: "" # TODO: Fix the Mercure chart
service:
type: NodePort
port: 80
ingress:
annotations:
# kubernetes.io/ingress.global-static-ip-name: chart-ip
# kubernetes.io/ingress.class: gce
# kubernetes.io/tls-acme: "true"
tls:
# Secrets must be manually created in the namespace, you can also use cert-manager.
# - hosts:
# - example.com
# - mercure.example.com
hosts:
api:
host: example.com
serviceName: varnish
mercure:
host: mercure.example.com
serviceName: mercure
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi