Learnitweb

Upgrading an Existing Helm Release

Introduction

Helm is a package manager for Kubernetes that allows you to deploy, manage, and upgrade applications easily using Helm charts. In this tutorial, we will learn how to upgrade an existing Helm release, specifically focusing on a MySQL installation.

Prerequisites

Before proceeding, ensure that:

  • You have Helm installed on your system.
  • You have an existing MySQL release deployed via Helm.
  • You have access to a Kubernetes cluster.
  • You have appropriate permissions to perform Helm operations.

Step 1: Update the Helm Repository

Before upgrading, it is important to fetch the latest Helm charts from the repository to ensure we use the latest available versions. Run the following command:

helm repo update

This command will:

  • Connect to the configured Helm repositories.
  • Fetch the latest chart versions available.
  • Update the local cache with any changes.

Once completed, Helm will display a success message indicating the repositories are updated.

Step 2: Check Existing Helm Releases

To check the current Helm releases in your cluster, execute:

helm list

or its shortcut:

helm ls

This will display a list of deployed Helm releases. Suppose our MySQL release is named mydb, the output will show:

NAME    NAMESPACE REVISION UPDATED STATUS  CHART     APP VERSION
mydb    default   1        ...     Deployed mysql-8.0.0  8.0.30

The revision number is 1, indicating the initial installation.

Step 3: Verify Current Installation Status

Before upgrading, check the current status of the MySQL release:

helm status mydb

This provides details about the deployed release, including configuration and resources.

Step 4: Upgrade the MySQL Release

To upgrade, use the helm upgrade command. The MySQL Helm chart requires a root password, which must be set during the upgrade.

Using --set

helm upgrade mydb bitnami/mysql \
  --set auth.rootPassword=<your-root-password>

Using a values.yaml File

If you have a values.yaml file containing configurations (including the root password), use:

helm upgrade mydb bitnami/mysql -f values.yaml

Using --reuse-values

If you want to reuse the configuration from the previous installation without explicitly passing it again, use:

helm upgrade mydb bitnami/mysql --reuse-values

Explanation:

  • helm upgrade is used to update an existing Helm release.
  • mydb is the name of the release.
  • bitnami/mysql is the chart reference.
  • --set auth.rootPassword=<your-root-password> explicitly sets the root password.
  • -f values.yaml provides configurations from a file instead of passing values inline.
  • --reuse-values ensures that Helm fetches and reuses the values used during installation, avoiding the need to pass them again.

Important Note on Configuration Persistence

  • If you pass custom configurations using --set or --values during installation, you must pass them again during the upgrade.
  • If you do not specify any configuration, Helm will not retain the previously used values and will default to the chart’s default configuration.
  • To avoid this, you can use --reuse-values to automatically reuse the values from the last installation.

Step 5: Verify the Upgrade

After running the upgrade command, verify the changes:

helm status mydb

The revision number should now be 2, indicating an upgrade:

NAME    NAMESPACE REVISION UPDATED STATUS  CHART     APP VERSION
mydb    default   2        ...     Deployed mysql-8.0.1  8.0.31

To further confirm, list the releases again:

helm list

Step 6: Understanding Helm Upgrade Behavior

  • Helm will only push necessary changes to the Kubernetes cluster.
  • If the chart version has not changed, only updated configurations will be applied.
  • If a new chart version is available, Helm will upgrade the chart and apply all changes.
  • Using --reuse-values can simplify upgrades by maintaining previous configurations automatically.

Step 7: Understanding Helm Release Records

Helm maintains release records as Kubernetes secrets. Each installation and upgrade creates a new secret in the cluster.

Viewing Helm Secrets

To see the secrets Helm has created, execute:

kubectl get secrets

For each Helm release, Helm stores:

  • The initial installation record.
  • A new secret for each upgrade, preserving version history.

For example, after the first installation and one upgrade, there will be two secrets for the MySQL release.

Uninstalling a Helm Release

To uninstall a Helm release, run:

helm uninstall mydb

By default, this removes both:

  • The MySQL installation.
  • The release history (Helm secrets).

To retain release history for potential rollbacks, use:

helm uninstall mydb --keep-history

Important Changes in Helm 3

  • Before Helm 3.0, release history was retained by default.
  • Now, unless --keep-history is used, uninstalling a release removes all its version history.