Service Splitter Configuration Reference

This reference page describes the structure and contents of service splitter configuration entries. Configure and apply service splitters to redirect a percentage of incoming traffic requests for a service to one or more specific service instances.

Configuration model

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

Complete configuration

When every field is defined, a service splitter configuration entry has the following form:

  1. Kind = "service-splitter" ## string | required
  2. Name = "config-entry-name" ## string | required
  3. Namespace = "main" ## string
  4. Partition = "partition" ## string
  5. Meta = { ## map
  6. key = "value"
  7. }
  8. Splits = [ ## list | required
  9. { ## map
  10. Weight = 90 ## number | required
  11. Service = "service" ## string
  12. ServiceSubset = "v1" ## string
  13. Namespace = "target-namespace" ## string
  14. Partition = "target-partition" ## string
  15. RequestHeaders = { ## map
  16. Set = {
  17. "X-Web-Version" : "from-v1"
  18. }
  19. }
  20. ResponseHeaders = { ## map
  21. Set = {
  22. "X-Web-Version" : "to-v1"
  23. }
  24. }
  25. },
  26. {
  27. Weight = 10
  28. Service = "service"
  29. ServiceSubset = "v2"
  30. Namespace = "target-namespace"
  31. Partition = "target-partition"
  32. RequestHeaders = {
  33. Set = {
  34. "X-Web-Version" : "from-v2"
  35. }
  36. }
  37. ResponseHeaders = {
  38. Set = {
  39. "X-Web-Version" : "to-v2"
  40. }
  41. }
  42. }
  43. ]
  1. {
  2. "Kind" : "service-splitter", ## string | required
  3. "Name" : "config-entry-name", ## string | required
  4. "Namespace" : "main", ## string
  5. "Partition" : "partition", ## string
  6. "Meta" : { ## map
  7. "_key_" : "_value_"
  8. },
  9. "Splits" : [ ## list | required
  10. { ## map
  11. "Weight" : 90, ## number | required
  12. "Service" : "service", ## string
  13. "ServiceSubset" : "v1", ## string
  14. "Namespace" : "target-namespace", ## string
  15. "Partition" : "target-partition", ## string
  16. "RequestHeaders" : { ## map
  17. "Set" : {
  18. "X-Web-Version": "from-v1"
  19. }
  20. },
  21. "ResponseHeaders" : { ## map
  22. "Set" : {
  23. "X-Web-Version": "to-v1"
  24. }
  25. }
  26. },
  27. {
  28. "Weight" : 10,
  29. "Service" : "service",
  30. "ServiceSubset" : "v2",
  31. "Namespace" : "target-namespace",
  32. "Partition" : "target-partition",
  33. "RequestHeaders" : {
  34. "Set" : {
  35. "X-Web-Version": "from-v2"
  36. }
  37. },
  38. "ResponseHeaders" : {
  39. "Set" : {
  40. "X-Web-Version": "to-v2"
  41. }
  42. }
  43. }
  44. ]
  45. }
  1. apiVersion: consul.hashicorp.com/v1alpha1 # string | required
  2. kind: ServiceSplitter # string | required
  3. metadata: # object | required
  4. name: config-entry-name # string | required
  5. namespace: main # string
  6. spec:
  7. splits: # list
  8. - weight: 90 # floating point | required
  9. service: service # string
  10. serviceSubset: v1 # string
  11. namespace: target-namespace # string
  12. partition: target-partition # string
  13. requestHeaders:
  14. set:
  15. x-web-version: from-v1 # string
  16. responseHeaders:
  17. set:
  18. x-web-version: to-v1 # string
  19. - weight: 10
  20. service: service
  21. serviceSubset: v2
  22. namespace: target-namespace
  23. partition: target-partition
  24. requestHeaders:
  25. set:
  26. x-web-version: from-v2
  27. responseHeaders:
  28. set:
  29. x-web-version: to-v2

Specification

This section provides details about the fields you can configure in the service splitter configuration entry.

Kind

Specifies the type of configuration entry to implement.

Values

  • Default: none
  • This field is required.
  • Data type: String value that must be set to service-splitter.

Name

Specifies a name for the configuration entry. The name is metadata that you can use to reference the configuration entry when performing Consul operations, such as applying a configuration entry to a specific cluster.

Values

  • Default: Defaults to the name of the node after writing the entry to the Consul server.
  • This field is required.
  • Data type: String

Namespace EnterpriseService splitter - 图8Enterprise

Specifies the namespace to apply the configuration entry.

Values

  • Default: None
  • Data type: String

Partition EnterpriseService splitter - 图9Enterprise

Specifies the admin partition to apply the configuration entry.

Values

  • Default: Default
  • Data type: String

Meta

Specifies key-value pairs to add to the KV store.

Values

  • Default: none
  • Data type: Map of one or more key-value pairs
    • keys: String
    • values: String, integer, or float

Splits

Defines how much traffic to send to sets of service instances during a traffic split.

Values

Splits[].Weight

Specifies the percentage of traffic sent to the set of service instances specified in the Service field. Each weight must be a floating integer between 0 and 100. The smallest representable value is .01. The sum of weights across all splits must add up to 100.

Values

  • Default: null
  • This field is required.
  • Data type: Floating number from .01 to 100.

Splits[].Service

Specifies the name of the service to resolve.

Values

  • Default: Inherits the value of the Name field.
  • Data type: String

Splits[].ServiceSubset

Specifies a subset of the service to resolve. A service subset assigns a name to a specific subset of discoverable service instances within a datacenter, such as version2 or canary. All services have an unnamed default subset that returns all healthy instances.

You can define service subsets in a service resolver configuration entry, which are referenced by their names throughout the other configuration entries. This field overrides the default subset value in the service resolver configuration entry.

Values

  • Default: If empty, the split uses the default subset.
  • Data type: String

Splits[].Namespace EnterpriseService splitter - 图10Enterprise

Specifies the namespace to use in the FQDN when resolving the service.

Values

  • Default: Inherits the value of Namespace from the top-level of the configuration entry.
  • Data type: String

Splits[].Partition EnterpriseService splitter - 图11Enterprise

Specifies the admin partition to use in the FQDN when resolving the service.

Values

Splits[].RequestHeaders

Specifies a set of HTTP-specific header modification rules applied to requests routed with the service split. You cannot configure request headers if the listener protocol is set to tcp. Refer to Set HTTP Headers for an example configuration.

Values

  • Default: None
  • Values: Object containing one or more fields that define header modification rules
    • Add: Map of one or more key-value pairs
    • Set: Map of one or more key-value pairs
    • Remove: Map of one or more key-value pairs

The following table describes how to configure values for request headers:

RuleDescriptionType
AddDefines a set of key-value pairs to add to the header. Use header names as the keys. Header names are not case-sensitive. If header values with the same name already exist, the value is appended and Consul applies both headers. You can use variable placeholders.map of strings
SetDefines a set of key-value pairs to add to the request header or to replace existing header values with. Use header names as the keys. Header names are not case-sensitive. If header values with the same names already exist, Consul replaces the header values. You can use variable placeholders.map of strings
RemoveDefines an list of headers to remove. Consul removes only headers containing exact matches. Header names are not case-sensitive.list of strings

Use variable placeholders

For Add and Set, if the service is configured to use Envoy as the proxy, the value may contain variables to interpolate dynamic metadata into the value. For example, using the variable %DOWNSTREAM_REMOTE_ADDRESS% in your configuration entry allows you to pass a value that is generated when the split occurs.

Splits[].ResponseHeaders

Specifies a set of HTTP-specific header modification rules applied to responses routed with the service split. You cannot configure request headers if the listener protocol is set to tcp. Refer to Set HTTP Headers for an example configuration.

Values

  • Default: None
  • Values: Object containing one or more fields that define header modification rules
    • Add: Map of one or more string key-value pairs
    • Set: Map of one or more string key-value pairs
    • Remove: Map of one or more string key-value pairs

The following table describes how to configure values for response headers:

RuleDescriptionType
AddDefines a set of key-value pairs to add to the header. Use header names as the keys. Header names are not case-sensitive. If header values with the same name already exist, the value is appended and Consul applies both headers. You can use variable placeholders.map of strings
SetDefines a set of key-value pairs to add to the request header or to replace existing header values with. Use header names as the keys. Header names are not case-sensitive. If header values with the same names already exist, Consul replaces the header values. You can use variable placeholders.map of strings
RemoveDefines an list of headers to remove. Consul removes only headers containing exact matches. Header names are not case-sensitive.list of strings

Use variable placeholders

For Add and Set, if the service is configured to use Envoy as the proxy, the value may contain variables to interpolate dynamic metadata into the value. For example, using the variable %DOWNSTREAM_REMOTE_ADDRESS% in your configuration entry allows you to pass a value that is generated when the split occurs.

apiVersion

Kubernetes-only parameter that specifies the version of the Consul API that the configuration entry maps to Kubernetes configurations. The value must be consul.hashicorp.com/v1alpha1.

kind

Specifies the type of configuration entry to implement.

Values

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

metadata.name

Specifies a name for the configuration entry. The name is metadata that you can use to reference the configuration entry when performing Consul operations, such as applying a configuration entry to a specific cluster.

Values

  • Default: Inherits name from the host node
  • This field is required.
  • Data type: String

metadata.namespace EnterpriseService splitter - 图12Enterprise

Specifies the Consul namespace to use for resolving the service. You can map Consul namespaces to Kubernetes Namespaces in different ways. Refer to Custom Resource Definitions (CRDs) for Consul on Kubernetes for additional information.

Values

  • Default: None
  • Data type: String

spec

Kubernetes-only field that contains all of the configurations for service splitter pods.

Values

  • Default: none
  • This field is required.
  • Data type: Object containing spec.splits configuration

spec.meta

Specifies key-value pairs to add to the KV store.

Values

  • Default: none
  • Data type: Map of one or more key-value pairs
    • keys: String
    • values: String, integer, or float

spec.splits

Defines how much traffic to send to sets of service instances during a traffic split.

Values

spec.splits[].weight

Specifies the percentage of traffic sent to the set of service instances specified in the spec.splits.service field. Each weight must be a floating integer between 0 and 100. The smallest representable value is .01. The sum of weights across all splits must add up to 100.

Values

  • Default: null
  • This field is required.
  • Data type: Floating integer from .01 to 100

spec.splits[].service

Specifies the name of the service to resolve.

Values

  • Default: The service matching the configuration entry meta.name field.
  • Data type: String

spec.splits[].serviceSubset

Specifies a subset of the service to resolve. This field overrides the DefaultSubset.

Values

  • Default: Inherits the name of the default subset.
  • Data type: String

spec.splits[].namespace EnterpriseService splitter - 图13Enterprise

Specifies the namespace to use when resolving the service.

Values

  • Default: The namespace specified in the top-level configuration entry.
  • Data type: String

spec.splits[].partition EnterpriseService splitter - 图14Enterprise

Specifies which admin partition to use in the FQDN when resolving the service.

Values

  • Default: default
  • Data type: String

spec.splits[].requestHeaders

Specifies a set of HTTP-specific header modification rules applied to requests routed with the service split. You cannot configure request headers if the listener protocol is set to tcp. Refer to Set HTTP Headers for an example configuration.

Values

  • Default: None
  • Values: Object containing one or more fields that define header modification rules
    • add: Map of one or more key-value pairs
    • set: Map of one or more key-value pairs
    • remove: Map of one or more key-value pairs

The following table describes how to configure values for request headers:

RuleDescriptionType
addDefines a set of key-value pairs to add to the header. Use header names as the keys. Header names are not case-sensitive. If header values with the same name already exist, the value is appended and Consul applies both headers. You can use variable placeholders.map of strings
setDefines a set of key-value pairs to add to the request header or to replace existing header values with. Use header names as the keys. Header names are not case-sensitive. If header values with the same names already exist, Consul replaces the header values. You can use variable placeholders.map of strings
removeDefines an list of headers to remove. Consul removes only headers containing exact matches. Header names are not case-sensitive.list of strings

Use variable placeholders

For add and set, if the service is configured to use Envoy as the proxy, the value may contain variables to interpolate dynamic metadata into the value. For example, using the variable %DOWNSTREAM_REMOTE_ADDRESS% in your configuration entry allows you to pass a value that is generated when the split occurs.

spec.splits[].responseHeaders

Specifies a set of HTTP-specific header modification rules applied to responses routed with the service split. You cannot configure request headers if the listener protocol is set to tcp. Refer to Set HTTP Headers for an example configuration.

Values

  • Default: None
  • Values: Object containing one or more fields that define header modification rules
    • add: Map of one or more string key-value pairs
    • set: Map of one or more string key-value pairs
    • remove: Map of one or more string key-value pairs

The following table describes how to configure values for response headers:

RuleDescriptionType
addDefines a set of key-value pairs to add to the header. Use header names as the keys. Header names are not case-sensitive. If header values with the same name already exist, the value is appended and Consul applies both headers. You can use variable placeholders.map of strings
setDefines a set of key-value pairs to add to the request header or to replace existing header values with. Use header names as the keys. Header names are not case-sensitive. If header values with the same names already exist, Consul replaces the header values. You can use variable placeholders.map of strings
removeDefines an list of headers to remove. Consul removes only headers containing exact matches. Header names are not case-sensitive.list of strings

Use variable placeholders

For add and set, if the service is configured to use Envoy as the proxy, the value may contain variables to interpolate dynamic metadata into the value. For example, using the variable %DOWNSTREAM_REMOTE_ADDRESS% in your configuration entry allows you to pass a value that is generated when the split occurs.

Examples

The following examples demonstrate common service splitter configuration patterns for specific use cases.

Two subsets of same service

Split traffic between two subsets of the same service:

  1. Kind = "service-splitter"
  2. Name = "web"
  3. Splits = [
  4. {
  5. Weight = 90
  6. ServiceSubset = "v1"
  7. },
  8. {
  9. Weight = 10
  10. ServiceSubset = "v2"
  11. },
  12. ]
  1. {
  2. "Kind": "service-splitter",
  3. "Name": "web",
  4. "Splits": [
  5. {
  6. "Weight": 90,
  7. "ServiceSubset": "v1"
  8. },
  9. {
  10. "Weight": 10,
  11. "ServiceSubset": "v2"
  12. }
  13. ]
  14. }
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceSplitter
  3. metadata:
  4. name: web
  5. spec:
  6. splits:
  7. - weight: 90
  8. serviceSubset: v1
  9. - weight: 10
  10. serviceSubset: v2

Two different services

Split traffic between two services:

  1. Kind = "service-splitter"
  2. Name = "web"
  3. Splits = [
  4. {
  5. Weight = 50
  6. # will default to service with same name as config entry ("web")
  7. },
  8. {
  9. Weight = 50
  10. Service = "web-rewrite"
  11. },
  12. ]
  1. {
  2. "Kind": "service-splitter",
  3. "Name": "web",
  4. "Splits": [
  5. {
  6. "Weight": 50
  7. },
  8. {
  9. "Weight": 50,
  10. "Service": "web-rewrite"
  11. }
  12. ]
  13. }
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceSplitter
  3. metadata:
  4. name: web
  5. spec:
  6. splits:
  7. - weight: 50
  8. # defaults to the service with same name as the configuration entry ("web")
  9. - weight: 50
  10. service: web-rewrite

Set HTTP Headers

Split traffic between two subsets with extra headers added so clients can tell which version:

  1. Kind = "service-splitter"
  2. Name = "web"
  3. Splits = [
  4. {
  5. Weight = 90
  6. ServiceSubset = "v1"
  7. ResponseHeaders {
  8. Set {
  9. "X-Web-Version": "v1"
  10. }
  11. }
  12. },
  13. {
  14. Weight = 10
  15. ServiceSubset = "v2"
  16. ResponseHeaders {
  17. Set {
  18. "X-Web-Version": "v2"
  19. }
  20. }
  21. },
  22. ]
  1. {
  2. "Kind": "service-splitter",
  3. "Name": "web",
  4. "Splits": [
  5. {
  6. "Weight": 90,
  7. "ServiceSubset": "v1",
  8. "ResponseHeaders": {
  9. "Set": {
  10. "X-Web-Version": "v1"
  11. }
  12. }
  13. },
  14. {
  15. "Weight": 10,
  16. "ServiceSubset": "v2",
  17. "ResponseHeaders": {
  18. "Set": {
  19. "X-Web-Version": "v2"
  20. }
  21. }
  22. }
  23. ]
  24. }
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceSplitter
  3. metadata:
  4. name: web
  5. spec:
  6. splits:
  7. - weight: 90
  8. serviceSubset: v1
  9. responseHeaders:
  10. set:
  11. x-web-version: v1
  12. - weight: 10
  13. serviceSubset: v2
  14. responseHeaders:
  15. set:
  16. x-web-version: v2