We would like to watch if some change happens in ConfigMap
and/or Secret
; then perform a rolling upgrade on relevant DeploymentConfig
, Deployment
, Daemonset
, Statefulset
and Rollout
Reloader can watch changes in ConfigMap
and Secret
and do rolling upgrades on Pods with their associated DeploymentConfigs
, Deployments
, Daemonsets
Statefulsets
and Rollouts
.
Reloader is compatible with kubernetes >= 1.9
For a Deployment
called foo
have a ConfigMap
called foo-configmap
or Secret
called foo-secret
or both. Then add your annotation (by default reloader.stakater.com/auto
) to main metadata of your Deployment
kind: Deployment
metadata:
annotations:
reloader.stakater.com/auto: "true"
spec:
template: metadata:
This will discover deploymentconfigs/deployments/daemonsets/statefulset/rollouts automatically where foo-configmap
or foo-secret
is being used either via environment variable or from volume mount. And it will perform rolling upgrade on related pods when foo-configmap
or foo-secret
are updated.
You can restrict this discovery to only ConfigMap
or Secret
objects thatare tagged with a special annotation. To take advantage of that, annotateyour deploymentconfigs/deployments/daemonsets/statefulset/rollouts like this:
kind: Deployment
metadata:
annotations:
reloader.stakater.com/search: "true"
spec:
template:
and Reloader will trigger the rolling upgrade upon modification of anyConfigMap
or Secret
annotated like this:
kind: ConfigMap
metadata:
annotations:
reloader.stakater.com/match: "true"
data:
key: value
provided the secret/configmap is being used in an environment variable, or avolume mount.
Please note that reloader.stakater.com/search
andreloader.stakater.com/auto
do not work together. If you have thereloader.stakater.com/auto: "true"
annotation on your deployment, then itwill always restart upon a change in configmaps or secrets it uses, regardlessof whether they have the reloader.stakater.com/match: "true"
annotation ornot.
We can also specify a specific configmap or secret which would trigger rolling upgrade only upon change in our specified configmap or secret, this way, it will not trigger rolling upgrade upon changes in all configmaps or secrets used in a deploymentconfig, deployment, daemonset, statefulset or rollout.To do this either set the auto annotation to "false"
(reloader.stakater.com/auto: "false"
) or remove it altogether, and use annotations mentioned here or here
To perform rolling upgrade when change happens only on specific configmaps use below annotation.
For a Deployment
called foo
have a ConfigMap
called foo-configmap
. Then add this annotation to main metadata of your Deployment
kind: Deployment
metadata:
annotations:
configmap.reloader.stakater.com/reload: "foo-configmap"
spec:
template: metadata:
Use comma separated list to define multiple configmaps.
kind: Deployment
metadata:
annotations:
configmap.reloader.stakater.com/reload: "foo-configmap,bar-configmap,baz-configmap"
spec:
template:
metadata:
To perform rolling upgrade when change happens only on specific secrets use below annotation.
For a Deployment
called foo
have a Secret
called foo-secret
. Then add this annotation to main metadata of your Deployment
kind: Deployment
metadata:
annotations:
secret.reloader.stakater.com/reload: "foo-secret"
spec:
template:
metadata:
Use comma separated list to define multiple secrets.
kind: Deployment
metadata:
annotations:
secret.reloader.stakater.com/reload: "foo-secret,bar-secret,baz-secret"
spec:
template:
metadata:
reloader.stakater.com/auto: "true"
will only reload the pod, if the configmap or secret is used (as a volume mount or as an env) in DeploymentConfigs/Deployment/Daemonsets/Statefulsets
secret.reloader.stakater.com/reload
or configmap.reloader.stakater.com/reload
annotation will reload the pod upon changes in specified configmap or secret, irrespective of the usage of configmap or secret.--auto-annotation
flag--auto-search-annotation
flagand the match annotation with the --search-match-annotation
flag--configmap-annotation
flag--secret-annotation
flag--namespaces-to-ignore
flag--resources-to-ignore
flag--log-format=json
optionYou can deploy Reloader by following methods:
You can apply vanilla manifests by changing RELEASE-NAME
placeholder provided in manifest with a proper value and apply it by running the command given below:
kubectl apply -f https://raw.githubusercontent.com/stakater/Reloader/master/deployments/kubernetes/reloader.yaml
By default, Reloader gets deployed in default
namespace and watches changes secrets
and configmaps
in all namespaces.
Reloader can be configured to ignore the resources secrets
and configmaps
by passing the following args (spec.template.spec.containers.args
) to its container :
Args | Description |
---|---|
--resources-to-ignore=configMaps | To ignore configMaps |
--resources-to-ignore=secrets | To ignore secrets |
Note
: At one time only one of these resource can be ignored, trying to do it will cause error in Reloader. Workaround for ignoring both resources is by scaling down the reloader pods to 0
.
You can also apply the vanilla manifests by running the following command
kubectl apply -k https://github.com/stakater/Reloader/deployments/kubernetes
Similarly to vanilla manifests get deployed in default
namespace and watches changes secrets
and configmaps
in all namespaces.
You can write your own kustomization.yaml
using ours as a 'base' and write patches to tweak the configuration.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
- https://github.com/stakater/Reloader/deployments/kubernetes
namespace: reloader
Alternatively if you have configured helm on your cluster, you can add reloader to helm from our public chart repository and deploy it via helm using below mentioned commands. Follow this guide, in case you have trouble migrating reloader from Helm2 to Helm3
helm repo add stakater https://stakater.github.io/stakater-charts
helm repo update
helm install stakater/reloader # For helm3 add --generate-name flag or set the release name
Note: By default reloader watches in all namespaces. To watch in single namespace, please run following command. It will install reloader in test
namespace which will only watch Deployments
, Daemonsets
Statefulsets
and Rollouts
in test
namespace.
helm install stakater/reloader --set reloader.watchGlobally=false --namespace test # For helm3 add --generate-name flag or set the release name
Reloader can be configured to ignore the resources secrets
and configmaps
by using the following parameters of values.yaml
file:
Parameter | Description | Type |
---|---|---|
ignoreSecrets | To ignore secrets. Valid value are either true or false |
boolean |
ignoreConfigMaps | To ignore configMaps. Valid value are either true or false |
boolean |
Note
: At one time only one of these resource can be ignored, trying to do it will cause error in helm template compilation.
You can also set the log format of Reloader to json by setting logFormat
to json
in values.yaml and apply the chart
You can enable to scrape Reloader's Prometheus metrics by setting serviceMonitor.enabled
or podMonitor.enabled
to true
in values.yaml file. Service monitor will be removed in future releases of reloader in favour of Pod monitor.
Note: Reloading of OpenShift (DeploymentConfig) and/or Argo Rollouts has to be enabled explicitly because it might not be always possible to use it on a cluster with restricted permissions. This can be done by changing the following parameters:
Parameter | Description | Type |
---|---|---|
isOpenshift | Enable OpenShift DeploymentConfigs. Valid value are either true or false |
boolean |
isArgoRollouts | Enable Argo Rollouts. Valid value are either true or false |
boolean |
You can find more documentation here
File a GitHub issue, or send us an email.
Join and talk to us on Slack for discussing Reloader
Please use the issue tracker to report any bugs or file feature requests.
okteto up
to activate your development container.make build
../Reloader
PRs are welcome. In general, we follow the "fork-and-pull" Git workflow.
NOTE: Be sure to merge the latest from "upstream" before making a pull request!
View our closed Pull Requests.
Apache2 © Stakater
Reloader
is maintained by Stakater. Like it? Please let us know at hello@stakater.com
See our other projectsor contact us in case of professional services and queries on hello@stakater.com
推荐阅读 Helm3(K8S 资源对象管理工具)视频教程:https://edu.csdn.net/course/detail/32506 Helm3(K8S 资源对象管理工具)博客专栏:https://blog.csdn.net/xzk9381/category_10895812.html 本文原文链接:https://blog.csdn.net/xzk9381/article/details/
一. 概述 我们在 k8s 中使用 ConfigMap 作为配置文件的时候会遇到一个问题:修改 ConfigMap 后无法实现热部署,也就是更改了 ConfigMap 配置文件后需要手动重启 Pod 配置才会生效,为了处理这个问题 github 专门有个开源的项目 Reloader 来解决这个问题,项目地址如下: Reloader 项目地址:https://github.com/stakater/
werkzeug使用reloader可以在文件被改变时自动加载更改过的文件,使用方法也很简单,run_simple('localhost', 4000, application,use_reloader=True),ues_reloader=True即可。本文试图去品读一下reloader的实现以及一些小细节。 原理 先概述下整个reloader的原理,看起来会舒服一些。 非reloader的启动