Sameness groups configuration entry reference

This page provides reference information for sameness group configuration entries. Sameness groups associate services with identical names across partitions and cluster peers.

To learn more about creating a sameness group, refer to Create sameness groups or Create sameness groups on Kubernetes.

Sameness Group - 图1

Warning

Sameness groups are a beta feature for all Consul v1.16.x releases. Functionality is subject to change. You should never use the beta release in secure environments or production scenarios. Features in beta may experience performance issues, scaling issues, and limited support.

Configuration model

The following list outlines field hierarchy, language-specific data types, and requirements in the sameness group configuration entry. Click on a property name to view additional details, including default values.

Complete configuration

When every field is defined, a sameness group configuration entry has the following form:

  1. Kind = "sameness-group" # required
  2. Name = "<group-name>" # required
  3. Partition = "<partition-configuration-applies-to>"
  4. DefaultForFailover = false
  5. Members = [ # required
  6. { Partition = "<partition-with-services-in-group>" },
  7. { Peer = "<cluster-peer-with-services-in-group>" }
  8. ]
  1. {
  2. "Kind": "sameness-group", // required
  3. "Name": "<group-name>", // required
  4. "Partition": "<partition-configuration-applies-to>",
  5. "DefaultForFailover": false,
  6. "Members": [ // required
  7. {
  8. "Partition": "<partition-with-services-in-group>"
  9. },
  10. {
  11. "Peer": "<cluster-peer-with-services-in-group>"
  12. }
  13. ]
  14. }
  1. apiVersion: consul.hashicorp.com/v1alpha1 # required
  2. kind: SamenessGroup # required
  3. metadata:
  4. name: <groupName>
  5. spec:
  6. defaultForFailover: false
  7. members: # required
  8. - partition: <partitionWithServicesInGroup>
  9. - peer: <clusterPeerWithServicesInGroup>

Specifications

This section provides details about the fields you can configure in the sameness group configuration entry.

Kind

Specifies the type of configuration entry to implement. Must be set to sameness-group.

Values

  • Default: None
  • This field is required.
  • Data type: String value that must be set to sameness-group.

Name

Specifies a name for the configuration entry that is used to identify the sameness group. To ensure consistency, use descriptive names and make sure that the same name is used when creating configuration entries to add each member to the sameness group.

Values

  • Default: None
  • This field is required.
  • Data type: String

Partition

Specifies the local admin partition that the sameness group applies to. Refer to admin partitions for more information.

Values

  • Default: default
  • Data type: String

DefaultForFailover

Determines whether the sameness group should be used to establish connections to services with the same name during failover scenarios. When this field is set to true, DNS queries and upstream requests automatically failover to services in the sameness group according to the order of the members in the Members list.

When this field is set to false, you can still use a sameness group for failover by configuring the Failover block of a service resolver configuration entry.

Values

  • Default: false
  • Data type: Boolean

Members

Specifies the partitions and cluster peers that are members of the sameness group from the perspective of the local partition.

The local partition should be the first member listed. The order of the members determines their precedence during failover scenarios. If a member is listed but Consul cannot connect to it, failover proceeds with the next healthy member in the list. For an example demonstrating how to configure this parameter, refer to Failover between sameness groups.

Each partition can belong to a single sameness group. You cannot associate a partition or cluster peer with multiple sameness groups.

Values

  • Default: None
  • This field is required.
  • Data type: List that can contain maps of the following parameters:

Members[].Partition

Specifies a partition in the local datacenter that is a member of the sameness group. When the value of this field is set to *, all local partitions become members of the sameness group.

Values

  • Default: None
  • Data type: String

Members[].Peer

Specifies the name of a cluster peer that is a member of the sameness group.

Cluster peering connections must be established before adding a peer to the list of members. Refer to establish cluster peering connections for more information.

Values

  • Default: None
  • Data type: String

apiVersion

Specifies the version of the Consul API for integrating with Kubernetes. The value must be consul.hashicorp.com/v1alpha1.

Values

  • Default: None
  • This field is required.
  • String value that must be set to consul.hashicorp.com/v1alpha1.

kind

Specifies the type of configuration entry to implement. Must be set to SamenessGroup.

Values

  • Default: None
  • This field is required.
  • Data type: String value that must be set to SamenessGroup.

metadata

Map that contains an arbitrary name for the configuration entry and the namespace it applies to.

Values

  • Default: None
  • Data type: Map

metadata.name

Specifies a name for the configuration entry that is used to identify the sameness group. To ensure consistency, use descriptive names and make sure that the same name is used when creating configuration entries to add each member to the sameness group.

Values

  • Default: None
  • This field is required.
  • Data type: String

spec

Map that contains the details about the SamenessGroup configuration entry. The apiVersion, kind, and metadata fields are siblings of the spec field. All other configurations are children.

Values

  • Default: None
  • This field is required.
  • Data type: Map

spec.defaultForFailover

Determines whether the sameness group should be used to establish connections to services with the same name during failover scenarios. When this field is set to true, DNS queries and upstream requests automatically failover to services in the sameness group according to the order of the members in the spec.members list.

When this field is set to false, you can still use a sameness group for failover by configuring the Failover block of a service resolver configuration entry.

Values

  • Default: false
  • Data type: Boolean

spec.members

Specifies the partitions and cluster peers that are members of the sameness group from the perspective of the local partition.

The local partition should be the first member listed. The order of the members determines their precedence during failover scenarios. If a member is listed but Consul cannot connect to it, failover proceeds with the next healthy member in the list. For an example demonstrating how to configure this parameter, refer to Failover between sameness groups.

Each partition can belong to a single sameness group. You cannot associate a partition or cluster peer with multiple sameness groups.

Values

  • Default: None

  • This field is required.

  • Data type: List that can contain maps of the following parameters:

spec.members[].partition

Specifies a partition in the local datacenter that is a member of the sameness group. When the value of this field is set to *, all local partitions become members of the sameness group.

Values

  • Default: None
  • Data type: String

spec.members[].peer

Specifies the name of a cluster peer that is a member of the sameness group.

Cluster peering connections must be established before adding a peer to the list of members. Refer to establish cluster peering connections for more information.

Values

  • Default: None
  • Data type: String

Examples

The following examples demonstrate common sameness group configuration patterns for specific use cases.

Failover between members of a sameness group

In the following example, the configuration entry defines a sameness group named products-api that applies to the store-east partition in the local datacenter. The sameness group is configured so that when its services’ instances in store-east fails, Consul will attempt to establish a failover connection in the following order:

  • Services with the same name in the store-east partition
  • Services with the same name in the inventory-east partition in the same datacenter
  • Services with the same name in the store-west partition of datacenter dc2, which has an established cluster peering connection.
  • Services with the same name in the inventory-west partition of dc2, which has an established cluster peering connection.
  1. Kind = "sameness-group"
  2. Name = "products-api"
  3. Partition = "store-east"
  4. DefaultForFailover = true
  5. Members = [
  6. { Partition = "store-east" },
  7. { Partition = "inventory-east" },
  8. { Peer = "dc2-store-west" },
  9. { Peer = "dc2-inventory-west" }
  10. ]
  1. {
  2. "Kind": "sameness-group",
  3. "Name": "products-api",
  4. "Partition": "store-east",
  5. "DefaultForFailover": true,
  6. "Members": [
  7. {
  8. "Partition": "store-east"
  9. },
  10. {
  11. "Partition": "inventory-east"
  12. },
  13. {
  14. "Peer": "dc2-store-west"
  15. },
  16. {
  17. "Peer": "dc2-inventory-west"
  18. }
  19. ]
  20. }
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: SamenessGroup
  3. metadata:
  4. name: products-api
  5. spec:
  6. defaultForFailover: true
  7. members:
  8. - partition: store-east
  9. - partition: inventory-east
  10. - peer: dc2-store-west
  11. - peer: dc2-inventory-west