Skip to content

Instantly share code, notes, and snippets.

@ahawkins
Created May 4, 2017 17:26
Show Gist options
  • Save ahawkins/22f92bc2431f2a3172a0bce6ca48ae10 to your computer and use it in GitHub Desktop.
Save ahawkins/22f92bc2431f2a3172a0bce6ca48ae10 to your computer and use it in GitHub Desktop.
kviberg sample deployment template
{{- $stage := .Values.stage }}
{{- range $pod := .Values.topology.pods }}
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: '{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-{{ $pod.tier }}'
labels:
release: "{{ $.Release.Name }}"
chart: '{{ $.Chart.Name }}-{{ $.Chart.Version | replace "+" "-" }}'
app: '{{ template "fullname" $ }}'
component: '{{ $pod.name }}'
tier: '{{ $pod.tier }}'
source: kviberg
spec:
replicas: 1
template:
metadata:
labels:
release: "{{ $.Release.Name }}"
chart: '{{ $.Chart.Name }}-{{ $.Chart.Version | replace "+" "-" }}'
app: '{{ template "fullname" $ }}'
component: '{{ $pod.name }}'
tier: '{{ $pod.tier }}'
source: kviberg
{{- if $pod.init }}
annotations:
pod.beta.kubernetes.io/init-containers: '[
{{- range $index, $item := $pod.init }}
{{- if index $item.stages $stage }}
{{- if $index -}},{{- end -}}
{
"name": "{{ $item.name | replace "_" "-" }}",
"image": "{{ or $item.image (index $.Values.images $pod.name) }}",
"imagePullPolicy": "IfNotPresent",
"command": [
{{- range $index, $arg := $item.command }}
{{- if $index }},{{- end }}
"{{ $arg }}"
{{- end }}
],
"env": [
{{- range $item := $.Values.service_discovery }}
{
"name": "{{ $item.name }}",
"value": "{{ $item.protocol }}://{{ template "fullname" $ }}-{{ $item.service }}-{{ $item.tier }}:{{ $item.port }}"
},
{{- end }}
{{- if eq $.Values.stage "sandbox" }}
{
"name": "SANDBOX_NAME",
"value": "{{ $.Values.sandbox_name }}"
},
{{- range $item := index $.Values.sandbox_dbs $pod.name -}}
{{- if eq $item "mongodb" }}
{
"name": "MONGO_URL",
"value": "mongodb://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:27017/{{ $pod.name | replace "_" "-" }}"
},
{{- end }}
{{- if eq $item "mysql" }}
{
"name": "MYSQL_URL",
"value": "mysql://root:saltside@{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:3306/{{ $pod.name | replace "_" "-" }}"
},
{{- end }}
{{- if eq $item "dynamodb" }}
{
"name": "DYNAMODB_URL",
"value": "http://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:8000"
},
{{- end }}
{{- if eq $item "redis" }}
{
"name": "REDIS_URL",
"value": "redis://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:6379"
},
{{- end }}
{{- if eq $item "elasticsearch" }}
{
"name": "ELASTICSEARCH_URL",
"value": "http://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:9200"
},
{{- end }}
{{- if eq $item "mailcatcher" }}
{
"name": "SMTP_URL",
"value": "smtp://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:1025"
},
{
"name": "MAILCATCHER_URL",
"value": "http://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:1080"
},
{{- end }}
{{- end }}
{{- end }}
{{- range $key, $_value := index $.Values.secrets $pod.name $.Values.stage $.Values.market }}
{
"name": "{{ $key }}",
"valueFrom": {
"secretKeyRef": {
"name": "{{ template "fullname" $ }}-secrets",
"key": "{{ $pod.name }}.{{ $key }}"
}
}
},
{{- end }}
{{- range $key, $value := index $.Values.env $pod.name $.Values.stage $.Values.market }}
{
"name": "{{ $key }}",
"value": "{{ $value }}"
},
{{- end }}
{
"name": "__BOOOKEND",
"value": "PLACEHOLDER"
}
]
}
{{- end }}
{{- end }}
]'
{{- end }}
spec:
imagePullSecrets:
- name: "{{ template "fullname" $ }}-image-pull"
containers:
{{- range $container := $pod.containers }}
- name: {{ $container.name }}
image: {{ index $.Values.images $pod.name }}
imagePullPolicy: IfNotPresent
{{- if $container.command }}
command:
{{ toYaml $container.command | indent 12 }}
{{- end }}
{{- if $container.ports }}
ports:
- containerPort: {{ $container.ports.container }}
protocol: TCP
{{- end }}
{{- if $container.livenessProbe }}
livenessProbe:
{{ toYaml $container.livenessProbe | indent 12 }}
{{- end }}
{{- if $container.readinessProbe }}
readinessProbe:
{{ toYaml $container.readinessProbe | indent 12 }}
{{- end }}
{{- if (index $container "resources" $stage) }}
resources:
{{ index $container "resources" $stage | toYaml | indent 12 }}
{{- end }}
env:
{{- range $item := $.Values.service_discovery }}
- name: {{ $item.name }}
value: {{ $item.protocol }}://{{ template "fullname" $ }}-{{ $item.service }}-{{ $item.tier }}:{{ $item.port }}
{{- end }}
{{- if eq $.Values.stage "sandbox" }}
- name: SANDBOX_NAME
value: {{ $.Values.sandbox_name }}
{{- range $item := index $.Values.sandbox_dbs $pod.name -}}
{{- if eq $item "mongodb" }}
- name: MONGO_URL
value: mongodb://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:27017/{{ $pod.name | replace "_" "-" }}
{{- end }}
{{- if eq $item "mysql" }}
- name: MYSQL_URL
value: mysql://root:saltside@{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:3306/{{ $pod.name | replace "_" "-" }}
{{- end }}
{{- if eq $item "dynamodb" }}
- name: DYNAMODB_URL
value: http://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:8000
{{- end }}
{{- if eq $item "redis" }}
- name: REDIS_URL
value: redis://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:6379
{{- end }}
{{- if eq $item "elasticsearch" }}
- name: ELASTICSEARCH_URL
value: http://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:9200
{{- end }}
{{- if eq $item "mailcatcher" }}
- name: SMTP_URL
value: smtp://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:1025
- name: MAILCATCHER_URL
value: http://{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-db:1080
{{- end }}
{{- end }}
{{- range $key, $value := index $.Values.secrets $pod.name $.Values.stage $.Values.market }}
- name: "{{ $key }}"
valueFrom:
secretKeyRef:
name: "{{ template "fullname" $ }}-secrets"
key: "{{ $pod.name }}.{{ $key }}"
{{- end }}
{{- range $key, $value := index $.Values.env $pod.name $.Values.stage $.Values.market }}
- name: "{{ $key }}"
value: "{{ $value }}"
{{- end }}
{{- end }}
{{- end }}
{{- end -}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment