Migrate your Consul datacenter to HCP Consul Dedicated
With the release of HashiCorp Cloud Platform (HCP) Consul, it is now possible to delegate the management of your Consul servers to HashiCorp's SREs, allowing your team to focus on application development and deployment. However, in some cases you might already have an existing Consul datacenter deployed.
In this tutorial, you will migrate your existing datacenter's KVs and ACLs to a new HCP Consul Dedicated cluster.
The steps you'll perform to achieve the migration are the following.
- Check Consul version compatibility
- Take a backup of the data in both your datacenters
- Build the migration tool
- Export the data from the source datacenter
- Import the data into your HCP Consul Dedicated cluster
- Verify data is imported correctly
- Migrate client agents
Note
This tutorial only covers the migration for Consul KV store content and ACLs. Other configuration and content, such as intentions or services, will have to be manually migrated or reconfigured on the HCP Consul Dedicated cluster after the migration.
Prerequisites
A Consul datacenter (1.4.0+) that will be the source of your data and represents the datacenter you want to migrate to HCP.
An HCP Consul Dedicated cluster that will be the destination of your data and will be your new datacenter. If you don't have an existing HCP Consul Dedicated cluster deployed, you can deploy one with the Deploy HCP Consul Dedicated tutorial.
Performance notes
for better performance, deploy the HCP Consul Dedicated cluster using an HVN in the same AWS region you are going to use for your clients.
- The consul-migrate tool that helps you export and import ACLs and namespaces.
- Golang 1.15+ installed and configured to
build the
consul-migrate
tool.
Notes on older Consul versions
The tutorial and the tools used for the migration assume that the Consul version you are running in the source datacenter you want to migrate is 1.4.0 or higher. In previous versions of Consul, the ACL system was radically different and the configuration is not directly compatible with the Consul version running on HCP Consul.
For this reason, if you are running a Consul version older than 1.4.0 in your source datacenter, you must first upgrade your Consul version and ACL system.
Take a snapshot of your existing data
The steps provided by this tutorial will alter the configuration and the data of your HCP Consul Dedicated cluster.
To make sure you can recover from any possible outage and that you can rollback to the initial state, it is recommended that you take a snapshot of both your source datacenter and HCP Consul Dedicated cluster.
- Take a snapshot of your existing datacenter
- Take a snapshot of your HCP Consul Dedicated cluster in the HCP portal
Build the ACL migration tool
To migrate your ACL data from your source datacenter, you will use the
consul-migrate
tool. It permits you to backup and restore your ACL
configuration from one Consul datacenter into another, while keeping the tokens
compatible.
First, clone the repository to your local machine.
Change directory to the cloned folder.
Build the tool from source.
If the build succeeds, you will find the binary in the working directory under
the name of consul-migrate
.
Verify the build.
Once you create the binary you can either copy it to a Consul agent node in your datacenter, or use it on an independent node that has network access to your source datacenter.
Export the KV and ACL data
This section will guide you through the steps necessary to export your KV store content, ACLs, and namespace configuration (for Consul Enterprise).
Setup your environment
To communicate with Consul, you must configure your environment to communicate with your source datacenter.
If you are using a non-local deployment, you can configure a local Consul binary
to interact with the deployment. Set the CONSUL_HTTP_ADDR
variable on your
local machine or jump host to the IP address of a server.
Note, this jump host will need to use an ACL token to access Consul data.
You can export the token with the CONSUL_HTTP_TOKEN
variable.
Note
You must use an ACL token created with the global-management
policy for this migration since it will grant you permissions to write ACLs, KV objects, and namespaces (for Consul enterprise). This will ensure the reliability of the migration as the content managed by the consul-migrate
tool might increase in the future.
Additionally, if you have TLS encryption configured, you will need to use valid certificates.
Export Consul KV data
Consul provides a CLI command to export the KV store data into a JSON file.
This command produces a file, named kv_export.json
containing the KV content.
Export Consul ACL and namespace data
Use the consul-migrate
tool to export your ACL and namespaces data.
You can verify the ACLs and namespaces data has been exported to the file.
Configure access to your HCP Consul Dedicated cluster
To import the data into your HCP Consul Dedicated cluster, you will need a node with network access over the HCP Consul Dedicated address.
There are several ways to achieve this result, and we provide some tutorials that show different approaches.
- (Recommended) Connect an Amazon Transit Gateway to your HashiCorp Virtual Network
- Connect a Consul Client to HCP Consul Dedicated
Move the data to the import node
Once you have decided which approach to use to connect to your HCP Consul Dedicated cluster, you must migrate the data to the node you configured to access the cluster.
Security note
The data migrated contains extremely sensitive data about your environment. Make sure you take every precaution to avoid the data being exposed outside the nodes involved in this process. You might consider encrypting the data after the export to reduce the risk of unwanted access.
Install the migration tool
To import the ACL data, you will use the consul-migrate
tool you built
earlier during this tutorial.
Copy the consul-migrate
tool to the node you configured to access the cluster.
Setup your environment
In the previous section, before exporting the data, you configured your node to be able to reach your Consul datacenter. In this section, before importing the data, you will need to perform the same operation using the HCP Consul Dedicated cluster info. Specifically, to be able to connect to your HCP Consul Dedicated cluster, you will need the following:
- The datacenter URL
- A valid token for the import operation
You can retrieve this information from the Overview tab of your HCP Consul Dedicated cluster page.
First, copy the Private link to get the URL of you datacenter. Then click on Generate token to get a token to use for the import.
Note
Use an ACL token created with the global-management
policy for this migration, since it will grant you permissions to write ACLs, KV objects, and namespaces (for Consul enterprise). This will ensure the reliability of the migration, since the content managed by the consul-migrate
tool might increase in the future.
You can use the datacenter URL and ACL token values to configure your environment variables.
You can test your configuration using the Consul binary to check the content of ACLs and KV store.
In a new cluster, the consul acl token list
command should return an empty response.
Import the data to HCP Consul Dedicated
Once you confirm that your node is able to communicate with your HCP Consul Dedicated cluster, restore your exported data to HCP Consul Dedicated.
Import KV data
First, import the KV data using the consul kv
command.
At the end of the process, you will be able to confirm the KV data is now
imported using the consul kv
command.
Run the migration tool to import the data
Use the consul-migrate
tool to import the ACLs and namespaces information.
The tool will perform the import, and maintain each token's accessor and secrets ID across the two datacenters. This allows you to plan your migration without the need to update tokens in the configuration, or to redistribute tokens to the clients.
Policy ID notes
The consul-migrate
tool will restore the policies, but
due to Consul internal structure, it is not possible to maintain the policy ID
across the two datacenters. For this reason, the tool outputs the id=
and
from=
information to indicate the new policy ID and the ID it was generated
from in case you need it to check the import outcomes.
Move clients over to HCP Consul Dedicated
To migrate your Consul clients to HCP Consul Dedicated, you will need to make sure they can reach the HCP Consul Dedicated servers. You can achieve that by peering your VPC network with the HashiCorp Virtual Network (HVN) you created for the cluster, or by connecting an Amazon Transit Gateway to your HashiCorp Virtual Network.
Performance notes
Deploy your clients in the same AWS region of your HCP Consul Dedicated cluster for best performance.
Once you enabled connectivity, and the data is migrated, you will be able to migrate over your clients using the same tokens you already have in your configuration.
To enable the clients to communicate with your HCP Consul Dedicated cluster, you will need to change the following parameters in your Consul client agent configuration.
- Gossip encryption key
- CA certificate for the HCP Consul Dedicated cluster
- Join address information
To simplify the configuration operations you can download a pre-compiled configuration package directly from the Overview page of your HCP Consul Dedicated cluster by clicking on the Download client config button. The download is a zip file containing two files.
ca.pem
- contains the CA certificate for your HCP Consul Dedicated clusterclient_config.json
- contains a working configuration for a client that needs to join the cluster.
With those files, you can configure your clients to connect to the new servers.
You can either edit the configuration file to remove unwanted options, or to add specific client parameters that are not present in the example to your existing configuration.
Consul catalog content
During the client migration process you must re-register the services in your new Consul datacenter. If you have your services defined in a configuration file inside your client configuration directory, they will be automatically registered to the new datacenter when the clients join.
Client downtime notes
When you plan a client migration, you should account for downtime in your applications. If your infrastructure permits it, you might want to spin up new instances of the clients, and their relative services, directly into the HCP Consul cluster and, once the client fleet is fully replicated, redirect the traffic into the new datacenter.
Network connectivity
This tutorial assumes you have your clients and services already on AWS either running inside VMs or in a EKS cluster. If your clients are running on a different platform, you can still use the steps listed in this tutorial to migrate ACLs, namespace, and KV store data into your HCP Consul Dedicated cluster, and then deploy your applications in AWS.
Next steps
In this tutorial, you learned how to migrate your existing Consul datacenter ACL, namespace, and KV data from a self hosted Consul datacenter into a HCP Consul Dedicated cluster.
If you want to learn more about how to deploy your clients in HCP Consul Dedicated, you can review our tutorials on how to deploy clients on a virtual machine or on Elastic Kubernetes Service (EKS).
If you encounter any issues, please contact the HCP team at support.hashicorp.com.