- Notifications
You must be signed in to change notification settings - Fork0
A Kubernetes controller to watch changes in ConfigMap and Secrets and do rolling upgrades on Pods with their associated Deployment, StatefulSet, DaemonSet and DeploymentConfig – [✩Star] if you're using it!
License
ZanisO/Reloader
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
We would like to watch if some change happens inConfigMap and/orSecret; then perform a rolling upgrade on relevantDeploymentConfig,Deployment,Daemonset,Statefulset andRollout
Reloader can watch changes inConfigMap andSecret and do rolling upgrades on Pods with their associatedDeploymentConfigs,Deployments,DaemonsetsStatefulsets andRollouts.
Reloader is available in two different versions:
- Open Source Version
- Enterprise Version, which includes:
- SLA (Service Level Agreement) for support and unique requests
- Slack support
- Certified images
Contactsales@stakater.com for info about Reloader Enterprise.
Reloader is compatible with Kubernetes >= 1.19
You have aDeployment calledfoo and aConfigMap and/or aSecret either mounted as a volume or defined as a environment variable. TheConfigMap andSecret can be named whatever, but for the sake of this example, lets refer to theConfigMap asfoo-configmap and the secret asfoo-secret.
Add the annotation to the main metadata of yourDeployment. By default this would bereloader.stakater.com/auto.
kind:Deploymentmetadata:name:fooannotations:reloader.stakater.com/auto:"true"spec:template:metadata:
This will discover deploymentconfigs/deployments/daemonsets/statefulset/rollouts/cronjobs/jobs automatically wherefoo-configmap orfoo-secret is being used either via environment variable or from volume mount. And it will perform rolling upgrade on related pods whenfoo-configmap orfoo-secretare updated.
You can filter it by the type of monitored resource and use typed versions ofauto annotation. If you want to discover changes only in mountedSecrets and ignore changes inConfigMaps, addsecret.reloader.stakater.com/auto annotation instead. Analogously, you can useconfigmap.reloader.stakater.com/auto annotation to look for changes in mountedConfigMap, changes in any of mountedSecrets will not trigger a rolling upgrade on related pods.
You can also restrict this discovery to onlyConfigMap orSecret objects thatare tagged with a special annotation. To take advantage of that, annotateyour deploymentconfigs/deployments/daemonsets/statefulset/rollouts/cronjobs/jobs like this:
kind:Deploymentmetadata:annotations:reloader.stakater.com/search:"true"spec:template:
and Reloader will trigger the rolling upgrade upon modification of anyConfigMap orSecret annotated like this:
kind:ConfigMapmetadata: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 thatreloader.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 thereloader.stakater.com/match: "true" annotation ornot.
Similarly,reloader.stakater.com/auto and its typed version (secret.reloader.stakater.com/auto orconfigmap.reloader.stakater.com/auto) do not work together. If you have both annotations in your deployment, then only one of them needs to be true to trigger the restart. For example, having bothreloader.stakater.com/auto: "true" andsecret.reloader.stakater.com/auto: "false" or bothreloader.stakater.com/auto: "false" andsecret.reloader.stakater.com/auto: "true" will restart upon a change in a secret it uses.
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 adeploymentconfig,deployment,daemonset,statefulset,rollout,cronJob orjob.To do this either set the auto annotation to"false" (reloader.stakater.com/auto: "false") or remove it altogether, and use annotations forConfigmap orSecret.
It's also possible to enable auto reloading for all resources, by setting the--auto-reload-all flag.In this case, all resources that do not have the auto annotation (or its typed version) set to"false", will be reloaded automatically when their Configmaps or Secrets are updated.Notice that setting the auto annotation to an undefined value counts as false as-well.
To perform rolling upgrade when change happens only on specific configmaps use below annotation.
For aDeployment calledfoo have aConfigMap calledfoo-configmap. Then add this annotation to main metadata of yourDeployment
kind:Deploymentmetadata:annotations:configmap.reloader.stakater.com/reload:"foo-configmap"spec:template:metadata:
Use comma separated list to define multiple configmaps.
kind:Deploymentmetadata: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 aDeployment calledfoo have aSecret calledfoo-secret. Then add this annotation to main metadata of yourDeployment
kind:Deploymentmetadata:annotations:secret.reloader.stakater.com/reload:"foo-secret"spec:template:metadata:
Use comma separated list to define multiple secrets.
kind:Deploymentmetadata:annotations:secret.reloader.stakater.com/reload:"foo-secret,bar-secret,baz-secret"spec:template:metadata:
- Reloader also supportssealed-secrets.Here are the steps to use sealed-secrets with Reloader.
- For
rolloutsReloader simply triggers a change is up to you how you configure therolloutstrategy. 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) inDeploymentConfigs/Deployment/Daemonsets/Statefulsets/CronJobs/Jobssecret.reloader.stakater.com/reloadorconfigmap.reloader.stakater.com/reloadannotation will reload the pod upon changes in specified configmap or secret, irrespective of the usage of configmap or secret.- you may override the auto annotation with the
--auto-annotationflag - you may override the secret typed auto annotation with the
--secret-auto-annotationflag - you may override the configmap typed auto annotation with the
--configmap-auto-annotationflag - you may override the search annotation with the
--auto-search-annotationflagand the match annotation with the--search-match-annotationflag - you may override the configmap annotation with the
--configmap-annotationflag - you may override the secret annotation with the
--secret-annotationflag - you may want to prevent watching certain namespaces with the
--namespaces-to-ignoreflag - you may want to watch only a set of namespaces with certain labels by using the
--namespace-selectorflag - you may want to watch only a set of secrets/configmaps with certain labels by using the
--resource-label-selectorflag - you may want to prevent watching certain resources with the
--resources-to-ignoreflag - you can configure logging in JSON format with the
--log-format=jsonoption - you can configure the "reload strategy" with the
--reload-strategy=<strategy-name>option (details below) - you can configure rollout reload strategy with
reloader.stakater.com/rollout-strategyannotation,restartorrolloutvalues are available (defaults torollout)
Reloader supports multiple "reload" strategies for performing rolling upgrades to resources. The following list describes them:
- env-vars: When a tracked
configMap/secretis updated, this strategy attaches a Reloader specific environment variable to any containers referencing the changedconfigMaporsecreton the owning resource (e.g.,Deployment,StatefulSet, etc.). This strategy can be specified with the--reload-strategy=env-varsargument. Note: This is the default reload strategy. - annotations: When a tracked
configMap/secretis updated, this strategy attaches areloader.stakater.com/last-reloaded-frompod template annotation on the owning resource (e.g.,Deployment,StatefulSet, etc.). This strategy is useful when using resource syncing tools like ArgoCD, since it will not cause these tools to detect configuration drift after a resource is reloaded. Note: Since the attached pod template annotation only tracks the last reload source, this strategy will reload any tracked resource should itsconfigMaporsecretbe deleted and recreated. This strategy can be specified with the--reload-strategy=annotationsargument.
You can deploy Reloader by following methods:
You can apply vanilla manifests by changingRELEASE-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 indefault namespace and watches changessecrets andconfigmaps in all namespaces. Additionally, in the default Reloader deployment, the following resource limits and requests are set:
resources:limits:cpu:150mmemory:512Mirequests:cpu:10mmemory:128Mi
Reloader can be configured to ignore the resourcessecrets andconfigmaps by passing the following arguments (spec.template.spec.containers.args) to its container:
| Argument | 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 to0.
Reloader can be configured to only watch secrets/configmaps with one or more labels using the--resource-label-selector parameter. Supported operators are!, in, notin, ==, =, !=, if no operator is found the 'exists' operator is inferred (i.e. key only). Additional examples of these selectors can be found in theKubernetes Docs.
Note: The old: delimited key value mappings are deprecated and if provided will be translated tokey=value. Likewise, if a wildcard value is provided (e.g.key:*) it will be translated to the standalonekey which checks for key existence.
These selectors can be combined, for example with:
--resource-label-selector=reloader=enabled,key-exists,another-label in (value1,value2,value3)Only configmaps or secrets labeled like the following will be watched:
kind:ConfigMapapiVersion:v1metadata:labels:reloader:enabledkey-exists:yesanother-label:value1
Reloader can be configured to only watch namespaces labeled with one or more labels using the--namespace-selector parameter. Supported operators are!, in, notin, ==, =, !=, if no operator is found the 'exists' operator is inferred (i.e. key only). Additional examples of these selectors can be found in theKubernetes Docs.
Note: The old: delimited key value mappings are deprecated and if provided will be translated tokey=value. Likewise, if a wildcard value is provided (e.g.key:*) it will be translated to the standalonekey which checks for key existence.
These selectors can be combined, for example with:
--namespace-selector=reloader=enabled,test=trueOnly namespaces labeled as below would be watched and eligible for reloads:
kind:NamespaceapiVersion:v1metadata:labels:reloader:enabledtest:true
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 indefault namespace and watches changessecrets andconfigmaps in all namespaces.
You can write your ownkustomization.yaml using ours as a 'base' and write patches to tweak the configuration.
apiVersion:kustomize.config.k8s.io/v1beta1kind:Kustomizationresources: -https://github.com/stakater/Reloader/deployments/kubernetesnamespace: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. Followthis guide, in case you have trouble migrating Reloader from Helm2 to Helm3.
helm repo add stakater https://stakater.github.io/stakater-chartshelm repo updatehelm install stakater/reloader# For helm3 add --generate-name flag or set the release namehelm install {{RELEASE_NAME}} stakater/reloader -n {{NAMESPACE}} --set reloader.watchGlobally=false# By default, Reloader watches in all namespaces. To watch in single namespace, set watchGlobally=falsehelm install stakater/reloader --set reloader.watchGlobally=false --namespacetest --generate-name# Install Reloader in `test` namespace which will only watch `Deployments`, `Daemonsets` `Statefulsets` and `Rollouts` in `test` namespace.
helm uninstall {{RELEASE_NAME}} -n {{NAMESPACE}}| Parameter | Description | Type | Default |
|---|---|---|---|
global.imagePullSecrets | Reference to one or more secrets to be used when pulling images | array | [] |
| Parameter | Description | Type | Default |
|---|---|---|---|
nameOverride | replace the name of the chart | string | "" |
fullnameOverride | replace the generated name | string | "" |
| Parameter | Description | Type | Default |
|---|---|---|---|
reloader.autoReloadAll | boolean | false | |
reloader.isArgoRollouts | Enable ArgoRollouts. Valid value are eithertrue orfalse | boolean | false |
reloader.isOpenshift | Enable OpenShift DeploymentConfigs. Valid value are eithertrue orfalse | boolean | false |
reloader.ignoreSecrets | To ignore secrets. Valid value are eithertrue orfalse. EitherignoreSecrets orignoreConfigMaps can be ignored, not both at the same time | boolean | false |
reloader.ignoreConfigMaps | To ignore configmaps. Valid value are eithertrue orfalse | boolean | false |
reloader.reloadOnCreate | Enable reload on create events. Valid value are eithertrue orfalse | boolean | false |
reloader.reloadOnDelete | Enable reload on delete events. Valid value are eithertrue orfalse | boolean | false |
reloader.syncAfterRestart | Enable sync after Reloader restarts forAdd events, works only when reloadOnCreate istrue. Valid value are eithertrue orfalse | boolean | false |
reloader.reloadStrategy | Strategy to trigger resource restart, set to eitherdefault,env-vars orannotations | enumeration | default |
reloader.ignoreNamespaces | List of comma separated namespaces to ignore, if multiple are provided, they are combined with the AND operator | string | "" |
reloader.namespaceSelector | List of comma separated namespaces to select, if multiple are provided, they are combined with the AND operator | string | "" |
reloader.resourceLabelSelector | List of comma separated label selectors, if multiple are provided they are combined with the AND operator | string | "" |
reloader.logFormat | Set type of log format. Value could be eitherjson or"" | string | "" |
reloader.watchGlobally | Allow Reloader to watch in all namespaces (true) or just in a single namespace (false) | boolean | true |
reloader.enableHA | Enable leadership election allowing you to run multiple replicas | boolean | false |
reloader.readOnlyRootFileSystem | Enforce readOnlyRootFilesystem | boolean | false |
reloader.legacy.rbac | boolean | false | |
reloader.matchLabels | Pod labels to match | map | {} |
reloader.enableMetricsByNamespace | Expose an additional Prometheus counter of reloads by namespace (this metric may have high cardinality in clusters with many namespaces) | boolean | false |
| Parameter | Description | Type | Default |
|---|---|---|---|
reloader.deployment.replicas | Number of replicas, if you wish to run multiple replicas setreloader.enableHA = true. The replicas will be limited to 1 whenreloader.enableHA = false | int | 1 |
reloader.deployment.revisionHistoryLimit | Limit the number of revisions retained in the revision history | int | 2 |
reloader.deployment.nodeSelector | Scheduling pod to a specific node based on set labels | map | {} |
reloader.deployment.affinity | Set affinity rules on pod | map | {} |
reloader.deployment.securityContext | Set pod security context | map | {} |
reloader.deployment.containerSecurityContext | Set container security context | map | {} |
reloader.deployment.tolerations | A list oftolerations to be applied to the deployment | array | [] |
reloader.deployment.topologySpreadConstraints | Topology spread constraints for pod assignment | array | [] |
reloader.deployment.annotations | Set deployment annotations | map | {} |
reloader.deployment.labels | Set deployment labels, default to stakater settings | array | see values.yaml |
reloader.deployment.image | Set container image name, tag and policy | array | see values.yaml |
reloader.deployment.env | Support for extra environment variables | array | [] |
reloader.deployment.livenessProbe | Set liveness probe timeout values | map | {} |
reloader.deployment.readinessProbe | Set readiness probe timeout values | map | {} |
reloader.deployment.resources | Set container requests and limits (e.g. CPU or memory) | map | {} |
reloader.deployment.pod.annotations | Set annotations for pod | map | {} |
reloader.deployment.priorityClassName | Set priority class for pod in cluster | string | "" |
| Parameter | Description | Type | Default |
|---|---|---|---|
reloader.service | map | {} | |
reloader.rbac.enabled | Specifies whether a role based access control should be created | boolean | true |
reloader.serviceAccount.create | Specifies whether a ServiceAccount should be created | boolean | true |
reloader.custom_annotations | Add custom annotations | map | {} |
reloader.serviceMonitor.enabled | Enable to scrape Reloader's Prometheus metrics (legacy) | boolean | false |
reloader.podMonitor.enabled | Enable to scrape Reloader's Prometheus metrics | boolean | false |
reloader.podDisruptionBudget.enabled | Limit the number of pods of a replicated application | boolean | false |
reloader.netpol.enabled | boolean | false | |
reloader.volumeMounts | Mount volume | array | [] |
reloader.volumes | Add volume to a pod | array | [] |
reloader.webhookUrl | Add webhook to Reloader | string | "" |
- Both
namespaceSelector&resourceLabelSelectorcan be used together. If they are then both conditions must be met for the configmap or secret to be eligible to trigger reload events. (e.g. If a configmap matchesresourceLabelSelectorbutnamespaceSelectordoes not match the namespace the configmap is in, it will be ignored). - At one time only one of the resources
ignoreConfigMapsorignoreSecretscan be ignored, trying to do both will cause error in helm template compilation - Reloading of OpenShift (DeploymentConfig) and/or Argo
Rolloutshas to be enabled explicitly because it might not be always possible to use it on a cluster with restricted permissions isOpenShiftRecent versions of OpenShift (tested on 4.13.3) require the specified user to be in anuidrange which is dynamically assigned by the namespace. The solution is to unset the runAsUser variable viadeployment.securityContext.runAsUser=nulland let OpenShift assign it at installreloadOnCreatecontrols how Reloader handles secrets being added to the cache for the first time. IfreloadOnCreateis set to true:- Configmaps/secrets being added to the cache will cause Reloader to perform a rolling update of the associated workload
- When applications are deployed for the first time, Reloader will perform a rolling update of the associated workload
- If you are running Reloader in HA mode all workloads will have a rolling update performed when a new leader is elected
reloadOnDeletecontrols how Reloader handles secrets being deleted. IfreloadOnDeleteis set to true:- Configmaps/secrets being deleted will cause Reloader to perform a rolling update of the associated workload
serviceMonitorwill be removed in future releases of Reloader in favour of Pod monitor- If
reloadOnCreateis set to false:- Updates to configmaps/secrets that occur while there is no leader will not be picked up by the new leader until a subsequent update of the configmap/secret occurs
- In the worst case the window in which there can be no leader is 15s as this is the LeaseDuration
- If
reloadOnDeleteis set to false:- Deleting of configmaps/secrets has no effect to pods that references these resources.
- By default,
reloadOnCreate,reloadOnDeleteandsyncAfterRestartare all set to false. All need to be enabled explicitly
The Reloader documentation can be viewed fromthe doc site. The doc source is in thedocs folder.
File a GitHubissue.
Join and talk to us on Slack for discussing Reloader:
Please use theissue tracker to report any bugs or file feature requests.
- Deploy Reloader
- Run
okteto upto activate your development container make build./Reloader
PRs are welcome. In general, we follow the "fork-and-pull" Git workflow:
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit aPull request so that we can review your changes
NOTE: Be sure to merge the latest from "upstream" before making a pull request!
Repository GitHub releases: As requested by the community inissue 685, Reloader is now based on a manual release process. Releases are no longer done on every merged PR to the main branch, but manually on request.
To make a GitHub release:
- Code owners create a release branch
release-vX.Y.Z - Code owners run a dispatch mode workflow to automatically generate version and manifests on the release branch
- A PR is created to bump the image version on the release branch, example:PR-798
- Code owners create a GitHub release with tag
vX.Y.Zand target branchrelease-vX.Y.Z, which triggers creation of images
Repository git tagging: Push to the main branch will create a merge-image and merge-tag namedmerge-${{ github.event.number }}, for examplemerge-800 when pull request number 800 is merged.
Helm chart versioning: The Reloader Helm chart is maintained inthis repository. The Helm chart has its own semantic versioning. Helm charts and code releases are separate artifacts and separately versioned. Manifest making strategy relies on Kustomize. The Reloader Helm chart manages the two artifacts with these two fields:
appVersionpoints to released Reloader application image version listed on thereleases pageversionsets the Reloader Helm chart version
Helm chart will be released to the chart registry whenever files indeployments/kubernetes/chart/reloader/** change on the main branch.
Helm Chart will be released by the maintainers, on labelling a PR withrelease/helm-chart and pre-maturely updating theversion field inChart.yaml file.
View thereleases page to see what has changed in each release.
Apache2 ©Stakater
Reloader is maintained byStakater. Like it? Please let us know athello@stakater.com
Seeour other projectsor contact us in case of professional services and queries onhello@stakater.com
- ConfigmapController; We documentedhere why we re-created Reloader
About
A Kubernetes controller to watch changes in ConfigMap and Secrets and do rolling upgrades on Pods with their associated Deployment, StatefulSet, DaemonSet and DeploymentConfig – [✩Star] if you're using it!
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- Go97.9%
- Makefile1.3%
- Other0.8%



