2019-12-19 02:02:26 +00:00
---
2020-04-07 18:55:19 +00:00
layout: docs
2022-09-14 22:21:47 +00:00
page_title: Upgrading Consul on Kubernetes Components
description: >-
2022-09-16 15:28:32 +00:00
Consul on Kubernetes relies on packages and binaries that have individual upgrade requirements. Learn how to update Helm configurations, Helm versions, Consul versions, and Consul agents, as well as how to determine what will change and its impact on your service mesh.
2019-12-19 02:02:26 +00:00
---
2022-09-14 22:21:47 +00:00
# Upgrading Consul on Kubernetes Components
2019-12-19 02:02:26 +00:00
2022-11-17 23:04:29 +00:00
## Upgrade types
2019-12-19 02:02:26 +00:00
2022-11-17 23:04:29 +00:00
We recommend updating Consul on Kubernetes when:
- You change your Helm configuration
- A new Helm chart is released
- You want to upgrade your Consul version.
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
### Helm configuration changes
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
If you make a change to your Helm values file, you need to perform a `helm upgrade`
2020-10-01 21:36:15 +00:00
for those changes to take effect.
2022-11-17 23:04:29 +00:00
For example, if you installed Consul with `connectInject.enabled: false` and you want to change its value to `true`:
2020-10-01 21:36:15 +00:00
1. Determine your current installed chart version.
2022-02-03 16:12:47 +00:00
```shell-session
2022-09-09 20:56:33 +00:00
$ helm list --filter consul --namespace consul
2022-02-03 16:12:47 +00:00
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
consul consul 2 2022-02-02 21:49:45.647678 -0800 PST deployed consul-0.40.0 1.11.2
```
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
In this example, version `0.40.0` (from `consul-k8s:0.40.0`) is being used, and Consul on Kubernetes is installed in the `consul` namespace.
2020-10-01 21:36:15 +00:00
1. Perform a `helm upgrade`:
2022-01-12 23:05:01 +00:00
```shell-session
2022-02-03 16:12:47 +00:00
$ helm upgrade consul hashicorp/consul --namespace consul --version 0.40.0 --values /path/to/my/values.yaml
2020-10-01 21:36:15 +00:00
```
2022-11-17 23:04:29 +00:00
**Before performing the upgrade, be sure you read the other sections on this page,
2023-04-03 21:21:51 +00:00
continuing at [Determine scope of changes](#determine-scope-of-changes).**
2020-10-01 21:36:15 +00:00
2023-04-03 21:21:51 +00:00
~> Note: You should always set the `--version` flag when upgrading Helm. Otherwise, Helm uses the most up-to-date version in its local cache, which may result in an unintended upgrade.
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
### Upgrade Helm chart version
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
You may wish to upgrade your Helm chart version to take advantage of new features and
bug fixes, or because you want to upgrade your Consul version and it requires a
2020-10-01 21:36:15 +00:00
certain Helm chart version.
1. Update your local Helm repository cache:
2022-02-03 16:12:47 +00:00
```shell-session
$ helm repo update
```
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
1. List all available versions. Here you can observe that the latest version of `0.40.0`.
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
```shell-session hideClipboard
$ helm search repo hashicorp/consul --versions
NAME CHART VERSION APP VERSION DESCRIPTION
hashicorp/consul 0.40.0 1.11.2 Official HashiCorp Consul Chart
hashicorp/consul 0.39.0 1.11.1 Official HashiCorp Consul Chart
hashicorp/consul 0.38.0 1.10.4 Official HashiCorp Consul Chart
hashicorp/consul 0.37.0 1.10.4 Official HashiCorp Consul Chart
...
```
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
1. To determine which version you have installed, issue the following command:
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
```shell-session
$ helm list --filter consul --namespace consul
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
consul consul 2 2022-02-02 21:49:45.647678 -0800 PST deployed consul-0.39.0 1.11.1
```
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
In this example, version `0.39.0` (from `consul-k8s:0.39.0`) is being used.
2022-11-17 23:04:29 +00:00
If you want to upgrade to the latest `0.40.0` version, use the following procedure:
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
1. Check the changelog for any breaking changes from that version and any versions in between: [CHANGELOG.md](https://github.com/hashicorp/consul-k8s/blob/main/CHANGELOG.md).
2020-10-01 21:36:15 +00:00
1. Upgrade by performing a `helm upgrade` with the `--version` flag:
2022-02-03 16:12:47 +00:00
```shell-session
$ helm upgrade consul hashicorp/consul --namespace consul --version 0.40.0 --values /path/to/my/values.yaml
```
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
**Before performing the upgrade, be sure you've read the other sections on this page,
2023-04-03 21:21:51 +00:00
continuing at [Determine scope of changes](#determine-scope-of-changes).**
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
### Upgrade Consul version
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
If a new version of Consul is released, you need to perform a Helm upgrade
to update to the new version. Before you upgrade to a new version:
2020-10-01 21:36:15 +00:00
2023-01-25 16:52:43 +00:00
1. Read the [Upgrading Consul](/consul/docs/upgrading) documentation.
1. Read any [specific instructions](/consul/docs/upgrading/upgrade-specific) for the version you want to upgrade
2022-11-17 23:04:29 +00:00
to, as well as the Consul [changelog](https://github.com/hashicorp/consul/blob/main/CHANGELOG.md) for that version.
2023-01-25 16:52:43 +00:00
1. Read our [Compatibility Matrix](/consul/docs/k8s/compatibility) to ensure
2020-10-01 21:36:15 +00:00
your current Helm chart version supports this Consul version. If it does not,
you may need to also upgrade your Helm chart version at the same time.
2021-07-31 01:37:33 +00:00
1. Set `global.image` in your `values.yaml` to the desired version:
<CodeBlockConfig filename="values.yaml" highlight="2">
2020-10-01 21:36:15 +00:00
```yaml
global:
2022-02-03 16:12:47 +00:00
image: consul:1.11.2
2020-10-01 21:36:15 +00:00
```
2022-01-19 21:41:30 +00:00
2021-07-31 01:37:33 +00:00
</CodeBlockConfig>
2022-11-17 23:04:29 +00:00
2. Determine the version of your exisiting Helm installation. In this example, version `0.39.0` (from `consul-k8s:0.39.0`) is being used.
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
```shell-session
$ helm list --filter consul --namespace consul
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
consul consul 2 2022-02-02 21:49:45.647678 -0800 PST deployed consul-0.39.0 1.11.1
```
2020-10-01 21:36:15 +00:00
1. Perform a `helm upgrade`:
2022-02-03 16:12:47 +00:00
```shell-session
$ helm upgrade consul hashicorp/consul --namespace consul --version 0.39.0 --values /path/to/my/values.yaml
```
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
**Before performing the upgrade, be sure you have read the other sections on this page,
2023-04-03 21:21:51 +00:00
continuing at [Determine scope of changes](#determine-scope-of-changes).**
2020-10-01 21:36:15 +00:00
2023-04-03 21:21:51 +00:00
~> Note: You should always set the `--version` flag when upgrading Helm. Otherwise, Helm uses the most up-to-date version in its local cache, which may result in an unintended upgrade.
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
## Determine scope of changes
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
Before upgrading, it is important to understand the changes that affect your
cluster. For example, you need to take more care if your upgrade results
2022-01-12 23:05:01 +00:00
in the Consul server StatefulSet being redeployed.
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
There is no built-in functionality in Helm that shows what a helm upgrade
changes. There is, however, a Helm plugin [helm-diff](https://github.com/databus23/helm-diff)
2020-10-01 21:36:15 +00:00
that can be used.
1. Install `helm-diff` with:
2022-02-03 16:12:47 +00:00
```shell-session
$ helm plugin install https://github.com/databus23/helm-diff
```
2020-10-01 21:36:15 +00:00
1. If you are updating your `values.yaml` file, do so now.
1. Take the same `helm upgrade` command you were planning to issue but perform `helm diff upgrade` instead of `helm upgrade`:
2022-02-03 16:12:47 +00:00
```shell-session
$ helm diff upgrade consul hashicorp/consul --namespace consul --version 0.40.0 --values /path/to/your/values.yaml
```
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
This command prints out the manifests that will be updated and their diffs.
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
1. To see only updated objects, add `| grep "has changed"`:
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
```shell-session
$ helm diff upgrade consul hashicorp/consul --namespace consul --version 0.40.0 --values /path/to/your/values.yaml |
grep "has changed"
```
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
1. Take specific note if `consul-server, StatefulSet` is listed, as it means your Consul server statefulset will be redeployed.
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
If your Consul server statefulset needs to be redeployed, follow the same pattern for upgrades as
2023-01-25 16:52:43 +00:00
on other platforms by redploying servers one by one. Refer tp [Upgrading Consul](/consul/docs/upgrading) for more information.
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
If neither the server statefulset is not being redeployed,
then you can continue with the Helm upgrade without any specific sequence to follow.
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
## Upgrade Consul servers
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
Initiate the server upgrade:
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
1. Change the `global.image` value to the desired Consul version.
2023-04-03 21:21:51 +00:00
1. Set the `server.updatePartition` value to the number of server replicas. By default, there are 3 servers, so you would set this value to `3`.
2022-11-17 23:04:29 +00:00
1. Set the `updateStrategy` for clients to `OnDelete`.
2019-12-19 02:02:26 +00:00
2022-09-09 20:56:33 +00:00
<CodeBlockConfig filename="values.yaml">
2022-02-03 16:12:47 +00:00
```yaml
global:
image: 'consul:123.456'
server:
updatePartition: 3
```
2022-09-09 20:56:33 +00:00
2022-02-03 16:12:47 +00:00
</CodeBlockConfig>
The `updatePartition` value controls how many instances of the server
cluster are updated. Only instances with an index _greater than_ the
`updatePartition` value are updated (zero-indexed). Therefore, by setting
2022-11-17 23:04:29 +00:00
it equal to replicas, updates should not occur immediately.
2019-12-19 02:02:26 +00:00
2020-10-01 21:36:15 +00:00
1. Next, perform the upgrade:
2022-02-03 16:12:47 +00:00
```shell-session
$ helm upgrade consul hashicorp/consul --namespace consul --version <your-version> --values /path/to/your/values.yaml
```
2019-12-19 02:02:26 +00:00
2022-11-17 23:04:29 +00:00
This command does not cause the servers to redeploy, although the resource is updated. If
everything is stable, decrease the `updatePartition` value by one
2022-02-03 16:12:47 +00:00
and performing `helm upgrade` again. This will cause the first Consul server
to be stopped and restarted with the new image.
2019-12-19 02:02:26 +00:00
2020-10-01 21:36:15 +00:00
1. Wait until the Consul server cluster is healthy again (30s to a few minutes).
This can be confirmed by issuing `consul members` on one of the previous servers,
and ensuring that all servers are listed and are `alive`.
2020-11-13 23:19:21 +00:00
1. Decrease `updatePartition` by one and upgrade again. Continue until
`updatePartition` is `0`. At this point, you may remove the
`updatePartition` configuration. Your server upgrade is complete.
2019-12-19 02:02:26 +00:00
2022-11-17 23:04:29 +00:00
## Upgrading to Consul Dataplane
2019-12-19 02:02:26 +00:00
2023-01-25 16:52:43 +00:00
In earlier versions, Consul on Kubernetes used client agents in its deployments. As of v1.14.0, Consul uses [Consul Dataplane](/consul/docs/connect/dataplane/) in Kubernetes deployments instead of client agents.
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
If you upgrade Consul from a version that uses client agents to a version the uses dataplanes, complete the following steps to upgrade your deployment safely and without downtime.
2020-10-01 21:36:15 +00:00
2023-06-23 22:26:57 +00:00
1. Before you upgrade, edit your Helm chart configuration to enable Consul client agents by setting `client.enabled` and `client.updateStrategy`:
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
```yaml filename="values.yaml"
2022-02-03 16:12:47 +00:00
client:
2022-11-17 23:04:29 +00:00
enabled: true
2023-05-25 21:00:44 +00:00
updateStrategy: |
2022-11-17 23:04:29 +00:00
type: OnDelete
2022-02-03 16:12:47 +00:00
```
2020-10-01 21:36:15 +00:00
2023-06-23 22:26:57 +00:00
1. Update the `connect-injector` to not log out on restart
to make sure that the ACL tokens used by existing services are still valid during the migration to `consul-dataplane`.
Note that you must remove the token manually after completing the migration.
The following command triggers the deployment rollout. Wait for the rollout to complete before proceeding to next step.
```bash
kubectl config set-context --current --namespace=<consul installation namespace>
2023-06-27 17:26:05 +00:00
INJECTOR_DEPLOYMENT=$(kubectl get deploy -l "component=connect-injector" -o=jsonpath='{.items[0].metadata.name}')
2023-06-23 22:26:57 +00:00
kubectl patch deploy $INJECTOR_DEPLOYMENT --type='json' -p='[{"op": "remove", "path": "/spec/template/spec/containers/0/lifecycle"}]'
```
2023-06-14 00:41:34 +00:00
1. Follow our [recommended procedures to upgrade servers](#upgrade-consul-servers) on Kubernetes deployments to upgrade Helm values for the new version of Consul.
2022-11-17 23:04:29 +00:00
1. Run `kubectl rollout restart` to restart your service mesh applications. Restarting service mesh application causes Kubernetes to re-inject them with the webhook for dataplanes.
2020-01-22 03:29:55 +00:00
2022-11-17 23:04:29 +00:00
1. Restart all gateways in your service mesh.
2020-10-01 21:36:15 +00:00
2023-06-15 15:59:29 +00:00
1. Disable client agents in your Helm chart by deleting the `client` stanza or setting `client.enabled` to `false` and running a `consul-k8s` or Helm upgrade.
2020-10-01 21:36:15 +00:00
2022-11-17 23:04:29 +00:00
## Configuring TLS on an existing cluster
2020-01-22 03:29:55 +00:00
If you already have a Consul cluster deployed on Kubernetes and
would like to turn on TLS for internal Consul communication,
2023-01-25 16:52:43 +00:00
refer to [Configuring TLS on an Existing Cluster](/consul/docs/k8s/operations/tls-on-existing-cluster).