2017-05-08 10:24:56 +02:00
|
|
|
Kontemplate tips & tricks
|
|
|
|
=========================
|
|
|
|
|
2017-07-30 01:16:45 +02:00
|
|
|
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
|
|
|
|
**Table of Contents**
|
|
|
|
|
|
|
|
- [Kontemplate tips & tricks](#kontemplate-tips--tricks)
|
|
|
|
- [Update Deployments when ConfigMaps change](#update-deployments-when-configmaps-change)
|
|
|
|
- [direnv & pass](#direnv--pass)
|
|
|
|
|
|
|
|
<!-- markdown-toc end -->
|
2017-05-08 10:24:56 +02:00
|
|
|
|
|
|
|
## Update Deployments when ConfigMaps change
|
|
|
|
|
|
|
|
Kubernetes does [not currently][] have the ability to perform rolling updates
|
|
|
|
of Deployments and other resource types when `ConfigMap` or `Secret` objects
|
|
|
|
are updated.
|
|
|
|
|
|
|
|
It is possible to make use of annotations and templating functions in
|
2019-04-30 11:05:09 +02:00
|
|
|
Kontemplate to force updates to these resources anyways.
|
2017-05-08 10:24:56 +02:00
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
```yaml
|
2019-04-30 11:05:09 +02:00
|
|
|
# A ConfigMap that contains some configuration for your app
|
2017-05-08 10:24:56 +02:00
|
|
|
---
|
|
|
|
kind: ConfigMap
|
|
|
|
metadata:
|
|
|
|
name: app-config
|
|
|
|
data:
|
2019-04-30 11:05:09 +02:00
|
|
|
app.conf: |
|
|
|
|
name: {{ .appName }}
|
|
|
|
foo: bar
|
2017-05-08 10:24:56 +02:00
|
|
|
```
|
|
|
|
|
2019-04-30 11:05:09 +02:00
|
|
|
Now whenever the `appName` variable changes or we make an edit to the
|
|
|
|
`ConfigMap` we would like to update the `Deployment` making use of it, too. We
|
|
|
|
can do this by adding a hash of the parsed template to the annotations of the
|
|
|
|
created `Pod` objects:
|
2017-05-08 10:24:56 +02:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
|
|
|
---
|
|
|
|
kind: Deployment
|
|
|
|
metadata:
|
|
|
|
name: app
|
|
|
|
spec:
|
|
|
|
template:
|
|
|
|
metadata:
|
|
|
|
annotations:
|
2019-04-30 11:05:09 +02:00
|
|
|
configHash: {{ insertTemplate "app-config.yaml" | sha256sum }}
|
2017-05-08 10:24:56 +02:00
|
|
|
spec:
|
|
|
|
containers:
|
|
|
|
- name: app
|
|
|
|
# Some details omitted ...
|
|
|
|
volumeMounts:
|
|
|
|
- name: config
|
|
|
|
mountPath: /etc/app/
|
|
|
|
volumes:
|
|
|
|
- name: config
|
|
|
|
configMap:
|
|
|
|
name: app-config
|
|
|
|
```
|
|
|
|
|
2019-04-30 11:05:09 +02:00
|
|
|
Now any change to the `ConfigMap` - either by directly editing the yaml file or
|
|
|
|
via a changed template variable - will cause the annotation to change,
|
|
|
|
triggering a rolling update of all relevant pods.
|
2017-05-08 10:24:56 +02:00
|
|
|
|
|
|
|
## direnv & pass
|
|
|
|
|
|
|
|
Users of `pass` may have multiple different password stores on their machines.
|
|
|
|
Assuming that `kontemplate` configuration exists somewhere on the filesystem
|
|
|
|
per project, it is easy to use [direnv][] to switch to the correct
|
|
|
|
`PASSWORD_STORE_DIR` variable when entering the folder.
|
|
|
|
|
|
|
|
[not currently]: https://github.com/kubernetes/kubernetes/issues/22368
|
2017-07-30 01:16:45 +02:00
|
|
|
[direnv]: https://direnv.net/
|