2022-06-15 20:18:14 +00:00
---
layout: api
page_title: Cluster Peering - HTTP API
description: The /peering endpoints allow for managing cluster peerings.
---
# Cluster Peering - HTTP API
The functionality described here is available only in
[Consul](https://www.hashicorp.com/products/consul/) version 1.13.0 and later.
## Generate a Peering Token
This endpoint generates a peering token.
| Method | Path | Produces |
| ------- | -------------------- | ------------------ |
| `POST` | `/peering/token` | `application/json` |
The table below shows this endpoint's support for
2023-01-25 16:52:43 +00:00
[blocking queries](/consul/api-docs/features/blocking),
[consistency modes](/consul/api-docs/features/consistency),
[agent caching](/consul/api-docs/features/caching), and
[required ACLs](/consul/api-docs/api-structure#authentication).
2022-06-15 20:18:14 +00:00
| Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
| ---------------- | ----------------- | ------------- | ---------------- |
2022-08-08 17:44:25 +00:00
| `NO` | `none` | `none` | `peering:write` |
2022-06-15 20:18:14 +00:00
### JSON Request Body Schema
2022-11-21 17:45:51 +00:00
- `PeerName` `(string: <required>)` - The name assigned to the peer cluster.
The `PeerName` is used to reference the peer cluster in service discovery queries
2022-06-15 20:18:14 +00:00
and configuration entries such as `service-intentions`. This field must be a
valid DNS hostname label.
- `Partition` `(string: "")` - <EnterpriseAlert inline /> The admin partition that the
peering token is generated from. Uses `default` when not specified.
2022-11-21 17:51:09 +00:00
- `ServerExternalAddresses` `([]string: <optional>)` - The addresses for the cluster that generates the peering token. Addresses take the form `{host or IP}:port`.
2022-11-08 20:55:18 +00:00
You can specify one or more load balancers or external IPs that route external traffic to this cluster's Consul servers.
2022-06-15 20:18:14 +00:00
- `Meta` `(map<string|string>: <optional>)` - Specifies KV metadata to associate with
the peering. This parameter is not required and does not directly impact the cluster
peering process.
### Sample Payload
```json
{
2022-11-21 17:45:51 +00:00
"PeerName": "cluster-02",
2022-06-15 20:18:14 +00:00
"Meta": {
"env": "production"
}
}
```
### Sample Request
```shell-session
$ curl --request POST \
--header "X-Consul-Token: 5cdcae6c-0cce-4210-86fe-5dff3b984a6e" \
--data @payload.json \
http://127.0.0.1:8500/v1/peering/token
```
### Sample Response
```json
{
"PeeringToken": "eyJDQSI6bnVsbCwiU2V..."
}
```
2022-06-17 17:31:11 +00:00
## Establish a Peering Connection
2022-06-15 20:18:14 +00:00
2022-06-17 17:31:11 +00:00
This endpoint establishes a peering connection with a given peering token.
2022-06-15 20:18:14 +00:00
| Method | Path | Produces |
| ------- | -------------------- | ------------------ |
| `POST` | `/peering/establish` | `application/json` |
This endpoint returns no data. Success or failure is indicated by the status
code returned.
The table below shows this endpoint's support for
2023-01-25 16:52:43 +00:00
[blocking queries](/consul/api-docs/features/blocking),
[consistency modes](/consul/api-docs/features/consistency),
[agent caching](/consul/api-docs/features/caching), and
[required ACLs](/consul/api-docs/api-structure#authentication).
2022-06-15 20:18:14 +00:00
| Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
| ---------------- | ----------------- | ------------- | ---------------- |
2022-08-08 17:44:25 +00:00
| `NO` | `none` | `none` | `peering:write` |
2022-06-15 20:18:14 +00:00
### JSON Request Body Schema
2022-11-21 17:45:51 +00:00
- `PeerName` `(string: <required>)` - The name assigned to the peer cluster.
The `PeerName` is used to reference the peer cluster in service discovery queries
2022-06-15 20:18:14 +00:00
and configuration entries such as `service-intentions`. This field must be a
valid DNS hostname label.
- `Partition` `(string: "")` - <EnterpriseAlert inline /> The admin partition
that peers to the cluster that generated the peering token. Uses `default`
when not specified.
- `PeeringToken` `(string: <required>)` - The peering token fetched from the
peer cluster.
- `Meta` `(map<string|string>: <optional>)` - Specifies KV metadata to associate with
the peering. This parameter is not required and does not directly impact the cluster
peering process.
### Sample Payload
```json
{
2022-11-21 17:45:51 +00:00
"PeerName": "cluster-01",
2022-06-15 20:18:14 +00:00
"PeeringToken": "eyJDQSI6bnVsbCwiU2V...",
"Meta": {
"env": "production"
}
}
```
### Sample Request
```shell-session
$ curl --request POST \
--header "X-Consul-Token: 5cdcae6c-0cce-4210-86fe-5dff3b984a6e" \
--data @payload.json \
http://127.0.0.1:8500/v1/peering/establish
```
### Sample Response
```json
{}
```
2022-06-17 17:31:11 +00:00
## Read a Peering Connection
2022-06-15 20:18:14 +00:00
2022-06-17 17:31:11 +00:00
This endpoint returns information about a peering connection for the specified peer name.
2022-06-15 20:18:14 +00:00
| Method | Path | Produces |
| ------ | ------------------ | ------------------ |
| `GET` | `/peering/:name` | `application/json` |
The table below shows this endpoint's support for
2023-01-25 16:52:43 +00:00
[blocking queries](/consul/api-docs/features/blocking),
[consistency modes](/consul/api-docs/features/consistency),
[agent caching](/consul/api-docs/features/caching), and
[required ACLs](/consul/api-docs/api-structure#authentication).
2022-06-15 20:18:14 +00:00
2022-08-08 17:44:25 +00:00
| Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
| ---------------- | ----------------- | ------------- | -------------- |
2023-05-23 21:29:10 +00:00
| `YES` | `consistent` | `none` | `peering:read` |
2022-06-15 20:18:14 +00:00
### Path Parameters
- `name` `(string: <required>)` - Specifies the peering to read.
### Query Parameters
- `partition` `(string: "")` <EnterpriseAlert inline /> - Specifies the partition of the peering
to read. If not specified will default to `default`.
### Sample Request
```shell-session
$ curl --header "X-Consul-Token: b23b3cad-5ea1-4413-919e-c76884b9ad60" \
http://127.0.0.1:8500/v1/peering/cluster-02
```
### Sample Response
```json
{
"ID": "462c45e8-018e-f19d-85eb-1fc1bcc2ef12",
"Name": "cluster-02",
"State": "INITIAL",
"PeerID": "e83a315c-027e-bcb1-7c0c-a46650904a05",
"PeerServerName": "server.dc1.consul",
"PeerServerAddresses": [
"10.0.0.1:8300"
],
2023-12-14 06:37:35 +00:00
"StreamStatus": {
"ImportedServices": [
"db",
],
"ExportedServices": [
"backend",
"frontend",
"web"
],
"LastHeartbeat": "2023-12-13T06:31:28.227392Z",
"LastReceive": "2023-12-13T06:31:28.227392Z",
"LastSend": "2023-12-05T11:02:57.528676Z"
},
2022-06-15 20:18:14 +00:00
"CreateIndex": 89,
2023-12-14 06:37:35 +00:00
"ModifyIndex": 89,
"Remote": {
"Partition": "",
"Datacenter": "east"
}
2022-06-15 20:18:14 +00:00
}
```
2022-06-17 17:31:11 +00:00
## Delete a Peering Connection
2022-06-15 20:18:14 +00:00
2022-06-17 17:31:11 +00:00
Call this endpoint to delete a peering connection. Consul deletes all data imported from the peer in the background. The peering connection is removed after all associated data has been deleted.
Operators can still read the peering connections while the data is being removed. A `DeletedAt`
field will be populated with the timestamp of when the peering was marked for deletion.
2022-06-15 20:18:14 +00:00
| Method | Path | Produces |
| -------- | ------------------ | -------- |
| `DELETE` | `/peering/:name` | N/A |
This endpoint returns no data. Success or failure is indicated by the status
code returned.
The table below shows this endpoint's support for
2023-01-25 16:52:43 +00:00
[blocking queries](/consul/api-docs/features/blocking),
[consistency modes](/consul/api-docs/features/consistency),
[agent caching](/consul/api-docs/features/caching), and
[required ACLs](/consul/api-docs/api-structure#authentication).
2022-06-15 20:18:14 +00:00
2022-08-08 17:44:25 +00:00
| Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
| ---------------- | ----------------- | ------------- | ---------------- |
| `NO` | `none` | `none` | `peering:write` |
2022-06-15 20:18:14 +00:00
### Path Parameters
- `name` `(string: <required>)` - Specifies the name of the peering to delete.
2022-09-19 20:11:04 +00:00
### Query Parameters
- `partition` `(string: "")` <EnterpriseAlert inline /> - Specifies the partition of the peerings
to delete. If not specified will default to `default`.
2022-06-15 20:18:14 +00:00
### Sample Request
```shell-session
$ curl --request DELETE \
--header "X-Consul-Token: b23b3cad-5ea1-4413-919e-c76884b9ad60" \
http://127.0.0.1:8500/v1/peering/cluster-02
```
### Sample Read Output After Deletion Prior to Removal
```json
{
"ID": "462c45e8-018e-f19d-85eb-1fc1bcc2ef12",
"Name": "cluster-02",
"State": "TERMINATED",
"PeerID": "e83a315c-027e-bcb1-7c0c-a46650904a05",
"PeerServerName": "server.dc1.consul",
"PeerServerAddresses": [
"10.0.0.1:8300"
],
"DeletedAt": "2022-12-14T23:00:00Z",
"CreateIndex": 89,
"ModifyIndex": 89
}
```
## List all Peerings
This endpoint lists all the peerings.
@include 'http_api_results_filtered_by_acls.mdx'
| Method | Path | Produces |
| ------ | ------------- | ------------------ |
| `GET` | `/peerings` | `application/json` |
The table below shows this endpoint's support for
2023-01-25 16:52:43 +00:00
[blocking queries](/consul/api-docs/features/blocking),
[consistency modes](/consul/api-docs/features/consistency),
[agent caching](/consul/api-docs/features/caching), and
[required ACLs](/consul/api-docs/api-structure#authentication).
2022-06-15 20:18:14 +00:00
2023-05-23 21:29:10 +00:00
| Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
| ---------------- | ----------------- | -------------------- | -------------- |
| `YES` | `consistent` | `background refresh` | `peering:read` |
2022-06-15 20:18:14 +00:00
2022-09-19 20:11:04 +00:00
### Query Parameters
- `partition` `(string: "")` <EnterpriseAlert inline /> - Specifies the partition of the peerings
to list. If not specified will default to `default`.
2022-06-15 20:18:14 +00:00
### Sample Request
```shell-session
$ curl --header "X-Consul-Token: 0137db51-5895-4c25-b6cd-d9ed992f4a52" \
http://127.0.0.1:8500/v1/peerings
```
### Sample Response
```json
[
{
"ID": "462c45e8-018e-f19d-85eb-1fc1bcc2ef12",
"Name": "cluster-02",
"State": "ACTIVE",
"Partition": "default",
"PeerID": "e83a315c-027e-bcb1-7c0c-a46650904a05",
"PeerServerName": "server.dc1.consul",
"PeerServerAddresses": [
"10.0.0.1:8300"
],
2023-12-14 06:37:35 +00:00
"StreamStatus": {
"ImportedServices": [
"db",
],
"ExportedServices": [
"backend",
"frontend",
"web"
],
"LastHeartbeat": "2023-12-13T06:31:28.227392Z",
"LastReceive": "2023-12-13T06:31:28.227392Z",
"LastSend": "2023-12-05T11:02:57.528676Z"
},
2022-06-15 20:18:14 +00:00
"CreateIndex": 89,
2023-12-14 06:37:35 +00:00
"ModifyIndex": 89,
"Remote": {
"Partition": "",
"Datacenter": "east"
}
2022-06-15 20:18:14 +00:00
},
{
"ID": "1460ada9-26d2-f30d-3359-2968aa7dc47d",
"Name": "cluster-03",
"State": "INITIAL",
"Partition": "default",
"Meta": {
"env": "production"
},
2023-12-14 06:37:35 +00:00
"StreamStatus": {
"ImportedServices": null,
"ExportedServices": [
"backend",
"frontend",
],
"LastHeartbeat": "2023-12-13T06:31:28.227392Z",
"LastReceive": "2023-12-13T06:31:28.227392Z",
"LastSend": "2023-12-05T11:02:57.528676Z"
},
2022-06-15 20:18:14 +00:00
"CreateIndex": 109,
2023-12-14 06:37:35 +00:00
"ModifyIndex": 119,
"Remote": {
"Partition": "",
"Datacenter": "east"
}
2022-08-31 16:58:41 +00:00
}
2022-06-15 20:18:14 +00:00
]
```