2019-12-19 02:02:26 +00:00
---
2020-04-07 18:55:19 +00:00
layout: docs
2020-09-01 15:14:13 +00:00
page_title: Upgrade
description: Upgrade Consul on Kubernetes
2019-12-19 02:02:26 +00:00
---
2020-09-01 15:14:13 +00:00
# Upgrade Consul on Kubernetes
2019-12-19 02:02:26 +00:00
2020-10-01 21:36:15 +00:00
## Upgrade Types
2019-12-19 02:02:26 +00:00
2020-10-01 21:36:15 +00:00
Consul on Kubernetes will need to be upgraded/updated if you change your Helm configuration,
if a new Helm chart is released, or if you wish to upgrade your Consul version.
### Helm Configuration Changes
If you make a change to your Helm values file, you will need to perform a `helm upgrade`
for those changes to take effect.
For example, if you've installed Consul with the following:
2022-09-09 20:56:33 +00:00
<CodeBlockConfig filename="values.yaml">
2022-02-03 16:12:47 +00:00
2020-10-01 21:36:15 +00:00
```yaml
global:
name: consul
connectInject:
enabled: false
```
2022-09-09 20:56:33 +00:00
2022-02-03 16:12:47 +00:00
</CodeBlockConfig>
2020-10-01 21:36:15 +00:00
And you wish to set `connectInject.enabled` to `true`:
```diff
global:
name: consul
connectInject:
- enabled: false
+ enabled: true
```
2022-02-03 16:12:47 +00:00
To update your deployment configuration using Helm, perform the following steps.
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
```
**Before performing the upgrade, be sure you've read the other sections on this page,
continuing at [Determining What Will Change](#determining-what-will-change).**
~> NOTE: It's important to always set the `--version` flag, because otherwise Helm
will use the most up-to-date version in its local cache, which may result in an
unintended upgrade.
### Helm Chart Version Upgrade
You may wish to upgrade your Helm chart version to take advantage of new features,
bugfixes, or because you want to upgrade your Consul version, and it requires a
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.
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,
continuing at [Determining What Will Change](#determining-what-will-change).**
2020-10-01 21:36:15 +00:00
### Consul Version Upgrade
If a new version of Consul is released, you will need to perform a Helm upgrade
to update to the new version.
1. Ensure you've read the [Upgrading Consul](/docs/upgrading) documentation.
1. Ensure you've read any [specific instructions](/docs/upgrading/upgrade-specific) for the version you're upgrading
2021-06-29 21:04:24 +00:00
to and the Consul [changelog](https://github.com/hashicorp/consul/blob/main/CHANGELOG.md) for that version.
2022-04-11 18:41:35 +00:00
1. Read our [Compatibility Matrix](/docs/k8s/installation/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-02-03 16:12:47 +00:00
1. Determine your current installed chart version. 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,
continuing at [Determining What Will Change](#determining-what-will-change).**
2020-10-01 21:36:15 +00:00
~> NOTE: It's important to always set the `--version` flag, because otherwise Helm
will use the most up-to-date version in its local cache, which may result in an
unintended upgrade.
## Determining What Will Change
Before upgrading, it's important to understand what changes will be made to your
cluster. For example, you will need to take more care if your upgrade will result
2022-01-12 23:05:01 +00:00
in the Consul server StatefulSet being redeployed.
2020-10-01 21:36:15 +00:00
There is no built-in functionality in Helm that shows what a helm upgrade will
change. There is, however, a Helm plugin [helm-diff](https://github.com/databus23/helm-diff)
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-02-03 16:12:47 +00:00
This will print out the manifests that will be updated and their diffs.
2020-10-01 21:36:15 +00:00
1. To see only the objects that will be updated, add `| grep "has changed"`:
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-01-26 22:22:12 +00:00
1. Take specific note if `consul-client, DaemonSet` or `consul-server, StatefulSet` are listed.
2020-10-01 21:36:15 +00:00
This means that your Consul client daemonset or Consul server statefulset (or both) will be redeployed.
2022-02-03 16:12:47 +00:00
If either is being redeployed, we will follow the same pattern for upgrades as
on other platforms: the servers will be redeployed one-by-one, and then the
clients will be redeployed in batches. Read [Upgrading Consul](/docs/upgrading) and then continue
reading below.
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
If neither the client daemonset nor the server statefulset is being redeployed,
then you can continue with the helm upgrade without any specific sequence to follow.
2020-10-01 21:36:15 +00:00
## Service Mesh
If you are using Consul's service mesh features, as opposed to the [service sync](/docs/k8s/service-sync)
functionality, you must be aware of the behavior of the service mesh during upgrades.
2022-05-10 14:28:33 +00:00
Consul clients operate as a daemonset across all Kubernetes nodes. During an upgrade,
2020-10-01 21:36:15 +00:00
if the Consul client daemonset has changed, the client pods will need to be restarted
because their spec has changed.
When a Consul client pod is restarted, it will deregister itself from Consul when it stops.
When the pod restarts, it will re-register itself with Consul.
Thus, during the period between the Consul client on a node stopping and restarting,
the following will occur:
1. The node will be deregistered from Consul. It will not show up in the Consul UI
nor in API requests.
1. Because the node is deregistered, all service pods that were on that node will
also be deregistered. This means they will not receive service mesh traffic
until the Consul client pod restarts.
1. Service pods on that node can continue to make requests through the service
mesh because each Envoy proxy maintains a cache of the locations of upstream
services. However, if the upstream services change IPs, Envoy will not be able
to refresh its cluster information until its local Consul client is restarted.
So services can continue to make requests without downtime for a short period
of time, however, it's important for the local Consul client to be restarted
as quickly as possible.
2022-01-19 21:41:30 +00:00
Once the local Consul client pod restarts, each service pod needs to be re-registered
with its local Consul client. This is done automatically by the connect inject controller.
2020-10-01 21:36:15 +00:00
Because service mesh pods are briefly deregistered during a Consul client restart,
it's **important that you do not restart all Consul clients at once**. Otherwise
you may experience downtime because no replicas of a specific service will be in the mesh.
In addition, it's **important that you have multiple replicas** for each service.
If you only have one replica, then during restart of the Consul client on the
node hosting that replica, it will be briefly deregistered from the mesh. Since
it's the only replica, other services will not be able to make calls to that
service. (NOTE: This can also be avoided by stopping that replica so it is rescheduled to
a node whose Consul client has already been updated.)
Given the above, we recommend that after Consul servers are upgraded, the Consul
client daemonset is set to use the `OnDelete` update strategy and Consul clients
are deleted one by one or in batches. See [Upgrading Consul Servers](#upgrading-consul-server)
and [Upgrading Consul Clients](#upgrading-consul-clients) for more details.
2019-12-19 02:02:26 +00:00
## Upgrading Consul Servers
2020-10-01 21:36:15 +00:00
To initiate the upgrade:
1. Change the `global.image` value to the desired Consul version
1. Set the `server.updatePartition` value _equal to the number of server replicas_.
By default there are 3 servers, so you would set this value to `3`
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
client:
updateStrategy: |
type: OnDelete
```
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
it equal to replicas, none should update yet.
The `updateStrategy` controls how Kubernetes rolls out changes to the client daemonset.
By setting it to `OnDelete`, no clients will be restarted until their pods are deleted.
Without this, they would be redeployed alongside the servers because their Docker
image versions have changed. This is not desirable because we want the Consul
servers to be upgraded _before_ the clients.
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-02-03 16:12:47 +00:00
This will not cause the servers to redeploy (although the resource will be updated). If
everything is stable, begin by decreasing the `updatePartition` value by one,
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
## Upgrading Consul Clients
2020-10-01 21:36:15 +00:00
With the servers upgraded, it is time to upgrade the clients.
If you are using Consul's service mesh features, you will want to be careful
restarting the clients as outlined in [Service Mesh](#service-mesh).
You can either:
1. Manually issue `kubectl delete pod <id>` for each consul daemonset pod
2022-02-03 16:12:47 +00:00
1. Set the updateStrategy to rolling update with a small number:
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
```yaml
client:
updateStrategy: |
rollingUpdate:
maxUnavailable: 2
type: RollingUpdate
```
2020-10-01 21:36:15 +00:00
2022-02-03 16:12:47 +00:00
Then, run `helm upgrade`. This will upgrade the clients in batches, waiting
until the clients come up healthy before continuing.
2020-01-22 03:29:55 +00:00
2022-02-03 16:12:47 +00:00
1. Cordon and drain each node to ensure there are no connect pods active on it, and then delete the
2020-10-01 21:36:15 +00:00
consul client pod on that node.
-> NOTE: If you are using only the Service Sync functionality, you can perform an upgrade without
following a specific sequence since that component is more resilient to brief restarts of
Consul clients.
2020-01-22 03:29:55 +00:00
## Configuring TLS on an Existing Cluster
If you already have a Consul cluster deployed on Kubernetes and
would like to turn on TLS for internal Consul communication,
please see
2022-01-10 23:36:16 +00:00
[Configuring TLS on an Existing Cluster](/docs/k8s/operations/tls-on-existing-cluster).