Skip to content

Instantly share code, notes, and snippets.

@martincalvert
Created November 9, 2017 16:30
Show Gist options
  • Save martincalvert/2e4f39e194ba26775303e5dd78bcbb36 to your computer and use it in GitHub Desktop.
Save martincalvert/2e4f39e194ba26775303e5dd78bcbb36 to your computer and use it in GitHub Desktop.
K8s: Templates
{{ define "affinity_notation" }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{ .Values.nodeAffinity.key }}
operator: In
values:
- {{ .Values.nodeAffinity.value }}
{{ end }}
{{ define "ruby_api_deployment" }}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ .Values.rubyApi.name }}-api
labels:
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
annotations:
"helm/created": {{ .Release.Time.Seconds | quote }}
spec:
replicas: {{ .Values.rubyApi.replicas }}
template:
metadata:
labels:
app: {{ .Values.rubyApi.name }}
tier: {{ .Values.rubyApi.name }}-api
annotations:
date: {{ .Release.Time.Seconds | quote }}
spec:
{{ include "affinity_notation" . | indent 6 }}
containers:
- name: {{ .Values.rubyApi.name }}
image: {{ .Values.rubyApi.image.name }}:{{ .Values.rubyApi.image.tag }}
imagePullPolicy: {{ .Values.rubyApi.image.pullPolicy }}
command:
- bundle
- exec
- unicorn
- "-E"
- {{ .Values.environment }}
- "-c"
- /etc/unicorn/unicorn.rb
- "-l"
- :3000
ports:
- containerPort: 3000
{{ include "pod_resources" .Values.rubyApi.resources | indent 8 }}
{{ include "http_get_probe" .Values.rubyApi.livenessProbe | indent 8 }}
{{ include "http_get_probe" .Values.rubyApi.readinessProbe | indent 8 }}
volumeMounts:
- mountPath: /etc/unicorn/unicorn.rb
subPath: unicorn.rb
name: {{ .Values.rubyApi.name }}-unicorn-config
readOnly: true
volumes:
- name: {{ .Values.rubyApi.name }}-unicorn-config
configMap:
name: {{ .Values.rubyApi.name }}-unicorn-config
{{ end }}
{{ define "pod_resources" }}
resources:
requests:
memory: {{ .request.memory }}
cpu: {{ .request.cpu }}
limits:
memory: {{ .limit.memory }}
cpu: {{ .limit.cpu }}
{{ end }}
{{ define "http_get_probe" }}
{{ .type }}:
httpGet:
path: {{ .path | default "/health.json" }}
port: {{ .port | default 3000 }}
initialDelaySeconds: {{ .initialDelay | default 60 }}
periodSeconds: {{ .periodSeconds | default 30 }}
timeoutSeconds: {{ .timeoutSeconds | default 5 }}
{{ end }}
environment: integration
nodeAffinity:
key: cloud.google.com/gke-nodepool
value: default
rubyApi:
name: guest
replicas: 1
livenessProbe:
type: livenessProbe
path: /health.json
port: 3000
initialDelay: 60
periodSeconds: 30
timeoutSeconds: 5
readinessProbe:
type: readinessProbe
path: /health.json
port: 3000
initialDelay: 60
periodSeconds: 1
timeoutSeconds: 1
image:
name: guest
tag: latest
pullPolicy: Always
resources:
request:
memory: 100Mi
cpu: 50m
limit:
memory: 1500Mi
cpu: 1000m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment