~> This topic requires familiarity with [Mesh Gateways](/docs/connect/mesh-gateway) and [WAN Federation Via Mesh Gateways](/docs/connect/wan-federation-via-mesh-gateways).
-> Looking for a step-by-step guide? Please follow our Learn Guide: [Secure and Route Service Mesh Communication Across Kubernetes](https://learn.hashicorp.com/consul/kubernetes/mesh-gateways).
This page describes how to federate multiple Kubernetes clusters. See [Multi-Cluster Overview](/docs/k8s/installation/multi-cluster/overview)
for more information on use-cases and how it works.
## Primary Datacenter
Consul treats each Kubernetes cluster as a separate Consul datacenter.
In order to federate clusters, one cluster must be designated the
primary datacenter. This datacenter will be
responsible for creating the certificate authority that signs the TLS certificates
Connect uses to encrypt and authorize traffic. It also handles validating global ACL tokens. All other clusters
that are federated are considered secondaries.
#### First Time Installation
If you haven't installed Consul on your cluster, continue reading below. If you've
already installed Consul on a cluster and want to upgrade it to
support federation, see [Upgrading An Existing Cluster](#upgrading-an-existing-cluster).
You will need to use the following `config.yaml` file for your primary cluster,
with the possible modifications listed below.
```yaml
global:
name: consul
datacenter: dc1
# TLS configures whether Consul components use TLS.
tls:
# TLS must be enabled for federation in Kubernetes.
enabled: true
federation:
enabled: true
# This will cause a Kubernetes secret to be created that
# can be imported by secondary datacenters to configure them
# for federation.
createFederationSecret: true
acls:
manageSystemACLs: true
# If ACLs are enabled, we must create a token for secondary
# datacenters to replicate ACLs.
createReplicationToken: true
# Gossip encryption secures the protocol Consul uses to quickly
# discover new nodes and detect failure.
gossipEncryption:
secretName: consul-gossip-encryption-key
secretKey: key
connectInject:
# Consul Connect service mesh must be enabled for federation.
enabled: true
meshGateway:
# Mesh gateways are gateways between datacenters. They must be enabled
# for federation in Kubernetes since the communication between datacenters
# goes through the mesh gateways.
enabled: true
```
Modifications:
1. The Consul datacenter name is `dc1`. The datacenter name in each federated
cluster **must be unique**.
1. ACLs are enabled in the above config file. They can be disabled by setting:
```yaml
global:
acls:
manageSystemACLs: false
createReplicationToken: false
```
ACLs secure Consul by requiring every API call to present an ACL token that
is validated to ensure it has the proper permissions. If you are only testing Consul,
this is not required.
1. Gossip encryption is enabled in the above config file. To disable it, comment
out or delete the `gossipEncryption` key:
```yaml
global:
# gossipEncryption:
# secretName: consul-gossip-encryption-key
# secretKey: key
```
Gossip encryption encrypts the communication layer used to discover other
nodes in the cluster and report on failure. If you are only testing Consul,
this is not required.
**NOTE:** This config assumes you've already
created a Kubernetes secret called `consul-gossip-encryption-key`. See
[the docs for this setting](/docs/k8s/helm#v-global-gossipencryption) for
more information on how to create this secret.
1. The default mesh gateway configuration
creates a Kubernetes Load Balancer service. If you wish to customize the
mesh gateway, for example using a Node Port service or a custom DNS entry,
see the [Helm reference](/docs/k8s/helm#v-meshgateway) for that setting.
With your `config.yaml` ready to go, follow our [Installation Guide](/docs/k8s/installation/overview
to install Consul on your primary cluster and then skip ahead to the [Federation Secret](#federation-secret)
With your Kubernetes clusters federated, try out using Consul service mesh to
route between services deployed on each cluster by following our Learn Guide: [Secure and Route Service Mesh Communication Across Kubernetes](https://learn.hashicorp.com/consul/kubernetes/mesh-gateways#deploy-microservices).
You can also read our in-depth documentation on [Consul Service Mesh In Kubernetes](/docs/k8s/connect).