Skip to content

Instantly share code, notes, and snippets.

@evanlucas
Last active September 26, 2017 00:05
Show Gist options
  • Save evanlucas/2d6307b945486d219f814ab7e13afcbc to your computer and use it in GitHub Desktop.
Save evanlucas/2d6307b945486d219f814ab7e13afcbc to your computer and use it in GitHub Desktop.
k8s template examples
{{/*
Renders all urls as env variables. This is done so adding new
service-to-service talk doesn't require a template change
so Values.urls.member_service_url will be rendered as MEMBER_SERVICE_URL
env var. :p
*/}}
{{- define "env.urls" -}}
{{- range $key, $val := .Values.urls -}}
{{ $env_name := $key | upper }}
- name: {{ $env_name }}
value: {{ $val | quote }}
{{- end -}}
{{- end -}}
{{/*
Get the filename of the current template
*/}}
{{- define "filename" }}
{{- .Template.Name | base | replace ".yaml" "" -}}
{{- end -}}
urls:
member_service_url: http://member-service:9000
visitor_service_url: http://visitor-service:9000
biscuits_service_url: http://biscuits-service:9000
@evanlucas
Copy link
Author

To use it, just {{- include "env.urls" . }} inside the env block of your deployment's container template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment