Kubernetes中Helm回滚机制及实现相关问题咨询
Great question! Let's break down how Helm's rollback functionality operates, addressing each of your specific concerns clearly:
1. Core Implementation of Rollback
Every time you run helm install, helm upgrade, or even helm rollback, Helm creates a new version entry for your Release. Rollback itself is essentially restoring your cluster resources to the state defined by a specific historical Release version:
- First, Helm fetches the full configuration of your target version (including Chart templates, custom values, hooks, and metadata) from its storage.
- It then compares the current state of your cluster resources against the desired state from the target version, calculating exactly what changes are needed—whether that's recreating a deleted Deployment, reverting a ConfigMap's content, or adjusting a Service's ports.
- After applying these changes, Helm adds a new version entry to the Release's history to log the rollback action (so you can always roll forward again if needed).
2. Data Storage for Old Release Configs
By default, Helm uses Kubernetes ConfigMaps to store all Release history and configuration data. These ConfigMaps live in the kube-system namespace, with a naming pattern like sh.helm.release.v1.<release-name>.v<version>—each version gets its own dedicated ConfigMap.
If you're dealing with sensitive data (like passwords or API keys in your values), you can switch to using Kubernetes Secrets as the storage backend instead. Just add the --storage=secret flag when running helm install or helm upgrade, and Helm will store all Release data in Secrets for enhanced security.
3. Limit on Continuous Rollbacks
Out of the box, Helm retains the last 10 Release versions (this includes versions created by installs, upgrades, and rollbacks). So the maximum number of consecutive rollbacks you can perform depends on how many historical versions are saved—for example, if you have 10 versions, you can roll back 9 times to reach the oldest retained version.
Keep in mind that every rollback creates a new version entry, so rolling back from v10 to v9 adds an v11 entry, which counts towards the history limit.
4. Can You Modify This Limit?
Absolutely! You can adjust the number of retained versions in two ways:
- Per Release: When installing or upgrading a Release, use the
--history-max=<number>flag to set a custom limit for that specific Release. For example:
This will keep the last 20 versions forhelm upgrade my-app ./my-chart --history-max=20my-app, letting you roll back further than the default. - Global Default: Edit your Helm configuration file (typically located at
~/.config/helm/helm.yaml) and add or update thehistory-maxfield:
This sets a default limit for all new Releases you create, though you can still override it with the per-release flag if needed.history-max: 20
内容的提问来源于stack exchange,提问作者lokanadham100

