Skip to content

Commit 2bfa5e2

Browse files
feat(k8s): add helm chart
1 parent c298442 commit 2bfa5e2

File tree

7 files changed

+293
-0
lines changed

7 files changed

+293
-0
lines changed

helm-chart/Chart.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v2
2+
name: chime
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
appVersion: 1.0.0

helm-chart/templates/_helpers.tpl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "chime.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
7+
{{- end }}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "chime.fullname" -}}
15+
{{- if .Values.fullnameOverride }}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
17+
{{- else }}
18+
{{- $name := default .Chart.Name .Values.nameOverride }}
19+
{{- if contains $name .Release.Name }}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
21+
{{- else }}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
23+
{{- end }}
24+
{{- end }}
25+
{{- end }}
26+
27+
{{/*
28+
Create chart name and version as used by the chart label.
29+
*/}}
30+
{{- define "chime.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
32+
{{- end }}
33+
34+
{{/*
35+
Common labels
36+
*/}}
37+
{{- define "chime.labels" -}}
38+
helm.sh/chart: {{ include "chime.chart" . }}
39+
{{ include "chime.selectorLabels" . }}
40+
{{- if .Chart.AppVersion }}
41+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
42+
{{- end }}
43+
app.kubernetes.io/managed-by: {{ .Release.Service }}
44+
{{- end }}
45+
46+
{{/*
47+
Selector labels
48+
*/}}
49+
{{- define "chime.selectorLabels" -}}
50+
app.kubernetes.io/name: {{ include "chime.name" . }}
51+
app.kubernetes.io/instance: {{ .Release.Name }}
52+
{{- end }}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "chime.fullname" . }}
5+
labels:
6+
{{- include "chime.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "chime.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
{{- with .Values.podAnnotations }}
17+
annotations:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "chime.selectorLabels" . | nindent 8 }}
22+
spec:
23+
{{- with .Values.imagePullSecrets }}
24+
imagePullSecrets:
25+
{{- toYaml . | nindent 8 }}
26+
{{- end }}
27+
containers:
28+
- name: {{ .Chart.Name }}
29+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
30+
imagePullPolicy: {{ .Values.image.pullPolicy }}
31+
ports:
32+
- name: http
33+
containerPort: 8000
34+
protocol: TCP
35+
volumeMounts:
36+
- name: google-api-creds
37+
mountPath: "/mnt/google-api-creds"
38+
readOnly: true
39+
livenessProbe:
40+
httpGet:
41+
path: /
42+
port: http
43+
readinessProbe:
44+
httpGet:
45+
path: /
46+
port: http
47+
resources:
48+
{{- toYaml .Values.resources | nindent 12 }}
49+
volumes:
50+
- name: google-api-creds
51+
secret:
52+
secretName: google-api-creds-json
53+
{{- with .Values.nodeSelector }}
54+
nodeSelector:
55+
{{- toYaml . | nindent 8 }}
56+
{{- end }}
57+
{{- with .Values.affinity }}
58+
affinity:
59+
{{- toYaml . | nindent 8 }}
60+
{{- end }}
61+
{{- with .Values.tolerations }}
62+
tolerations:
63+
{{- toYaml . | nindent 8 }}
64+
{{- end }}

helm-chart/templates/hpa.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2beta1
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "chime.fullname" . }}
6+
labels:
7+
{{- include "chime.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "chime.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
21+
{{- end }}
22+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
23+
- type: Resource
24+
resource:
25+
name: memory
26+
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
27+
{{- end }}
28+
{{- end }}

helm-chart/templates/ingress.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{{- if .Values.ingress.enabled -}}
2+
{{- $fullName := include "chime.fullname" . -}}
3+
{{- $svcPort := .Values.service.port -}}
4+
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
5+
apiVersion: networking.k8s.io/v1beta1
6+
{{- else -}}
7+
apiVersion: extensions/v1beta1
8+
{{- end }}
9+
kind: Ingress
10+
metadata:
11+
name: {{ $fullName }}
12+
labels:
13+
{{- include "chime.labels" . | nindent 4 }}
14+
{{- with .Values.ingress.annotations }}
15+
annotations:
16+
{{- toYaml . | nindent 4 }}
17+
{{- end }}
18+
spec:
19+
{{- if .Values.ingress.tls }}
20+
tls:
21+
{{- range .Values.ingress.tls }}
22+
- hosts:
23+
{{- range .hosts }}
24+
- {{ . | quote }}
25+
{{- end }}
26+
secretName: {{ .secretName }}
27+
{{- end }}
28+
{{- end }}
29+
rules:
30+
{{- range .Values.ingress.hosts }}
31+
- host: {{ .host | quote }}
32+
http:
33+
paths:
34+
{{- range .paths }}
35+
- path: {{ . }}
36+
backend:
37+
serviceName: {{ $fullName }}
38+
servicePort: {{ $svcPort }}
39+
{{- end }}
40+
{{- end }}
41+
{{- end }}

helm-chart/templates/service.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "chime.fullname" . }}
5+
labels:
6+
{{- include "chime.labels" . | nindent 4 }}
7+
spec:
8+
type: {{ .Values.service.type }}
9+
ports:
10+
- port: {{ .Values.service.port }}
11+
targetPort: http
12+
protocol: TCP
13+
name: http
14+
selector:
15+
{{- include "chime.selectorLabels" . | nindent 4 }}

helm-chart/values.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Default values for chime.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
5+
replicaCount: 1
6+
7+
image:
8+
repository: docker.pkg.github.com/codeforphilly/chime/penn-chime
9+
pullPolicy: IfNotPresent
10+
# Overrides the image tag whose default is the chart appVersion.
11+
tag: latest
12+
13+
imagePullSecrets:
14+
- name: regcred
15+
16+
nameOverride: ""
17+
fullnameOverride: ""
18+
19+
podAnnotations: {}
20+
21+
service:
22+
type: ClusterIP
23+
port: 80
24+
25+
ingress:
26+
enabled: true
27+
annotations:
28+
kubernetes.io/ingress.class: nginx
29+
nginx.ingress.kubernetes.io/proxy-body-size: "0"
30+
nginx.ingress.kubernetes.io/configuration-snippet: |
31+
# Inject Google Tag Manager:
32+
33+
proxy_set_header Accept-Encoding ""; # upstream compression must be disabled
34+
35+
sub_filter '</head>' '<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({"gtm.start": new Date().getTime(),event:"gtm.js"});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!="dataLayer"?"&l="+l:"";j.async=true;j.src="https://www.googletagmanager.com/gtm.js?id="+i+dl;f.parentNode.insertBefore(j,f); })(window,document,"script","dataLayer","GTM-KBZ6ZKX");</script></head>';
36+
37+
sub_filter '</body>' '<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KBZ6ZKX" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript></body>';
38+
39+
hosts:
40+
- host: penn-chime.phl.io
41+
paths: [ '/' ]
42+
tls:
43+
- secretName: penn-chime-tls
44+
hosts:
45+
- penn-chime.phl.io
46+
47+
resources: {}
48+
# We usually recommend not to specify default resources and to leave this as a conscious
49+
# choice for the user. This also increases chances charts run on environments with little
50+
# resources, such as Minikube. If you do want to specify resources, uncomment the following
51+
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
52+
# limits:
53+
# cpu: 100m
54+
# memory: 128Mi
55+
# requests:
56+
# cpu: 100m
57+
# memory: 128Mi
58+
59+
autoscaling:
60+
enabled: false
61+
minReplicas: 1
62+
maxReplicas: 100
63+
targetCPUUtilizationPercentage: 80
64+
# targetMemoryUtilizationPercentage: 80
65+
66+
nodeSelector: {}
67+
68+
tolerations: []
69+
70+
affinity: {}

0 commit comments

Comments
 (0)