Consul
Service Defaults Configuration Entry
v1.8.4+: On Kubernetes, the ServiceDefaults
custom resource is supported in Consul versions 1.8.4+.
v1.5.0+: On other platforms, this config entry is supported in Consul versions 1.5.0+.
The service-defaults
config entry kind (ServiceDefaults
on Kubernetes) controls default global values for a
service, such as its protocol.
Sample Config Entries
Default protocol
NOTE: The default protocol can also be configured globally for all proxies using the proxy defaults config entry. However, if the protocol value is specified in a service defaults config entry for a given service, that value will take precedence over the globally configured value from proxy defaults.
Set the default protocol for a service in the default namespace to HTTP:
Kind = "service-defaults"
Name = "web"
Namespace = "default"
Protocol = "http"
Upstream configuration
Set default connection limits and mesh gateway mode across all upstreams of "counting", and also override the mesh gateway mode used when dialing the "dashboard" service.
Kind = "service-defaults"
Name = "counting"
UpstreamConfig = {
Defaults = {
MeshGateway = {
Mode = "local"
}
Limits = {
MaxConnections = 512
MaxPendingRequests = 512
MaxConcurrentRequests = 512
}
}
Overrides = [
{
Name = "dashboard"
MeshGateway = {
Mode = "remote"
}
}
]
}
Available Fields
Kind
- Must be set toservice-defaults
Name
(string: <required>)
- Set to the name of the service being configured.Namespace
(string: "default")
Enterprise - Specifies the namespace the config entry will apply to.Partition
(string: "default")
Enterprise - Specifies the name of the admin partition in which the configuration entry applies. Refer to the Admin Partitions documentation for additional information.Meta
(map<string|string>: nil)
- Specifies arbitrary KV metadata pairs. Added in Consul 1.8.4.Protocol
(string: "tcp")
- Sets the protocol of the service. This is used by Connect proxies for things like observability features and to unlock usage of theservice-splitter
andservice-router
config entries for a service. It also unlocks the ability to define L7 intentions viaservice-intentions
. Supported values are one oftcp
,http
,http2
, orgrpc
.Mode
(string: "")
- One ofdirect
ortransparent
.transparent
represents that inbound and outbound application traffic is being captured and redirected through the proxy. This mode does not enable the traffic redirection itself. Instead it signals Consul to configure Envoy as if traffic is already being redirected.direct
represents that the proxy's listeners must be dialed directly by the local application and other proxies. Added in v1.10.0.UpstreamConfig
(UpstreamConfiguration: <optional>)
- Controls default configuration settings that apply across all upstreams, and per-upstream configuration overrides. Note that per-upstream configuration applies across all federated datacenters to the pairing of source and upstream destination services. Added in v1.10.0.Overrides
(array<UpstreamConfig>: [])
- A list of optional overrides for per-upstream configuration.Name
(string: "")
- The upstream name to apply the configuration to. This should not be set to the wildcard specifier*
.Namespace
(string: "")
- The namespace of the upstream. This should not be set to the wildcard specifier*
.Protocol
(string: "")
- The protocol for the upstream listener.
NOTE: The protocol of a service should ideally be configured via theprotocol
field of aservice-defaults
config entry for the upstream destination service. Configuring it in a proxy upstream config will not fully enable some L7 features. It is supported here for backwards compatibility with Consul versions prior to 1.6.0.ConnectTimeoutMs
(int: 5000)
- The number of milliseconds to allow when making upstream connections before timing out.
NOTE: The connect timeout of a service should ideally be configured via theconnect_timeout
field of aservice-resolver
config entry for the upstream destination service. Configuring it in a proxy upstream config will not fully enable some L7 features. It is supported here for backwards compatibility with Consul versions prior to 1.6.0.MeshGateway
(MeshGatewayConfig: <optional>)
- Controls the default mesh gateway configuration for this upstream.Mode
(string: "")
- One ofnone
,local
, orremote
.
Limits
(Limits: <optional>)
- A set of limits to apply when connecting to the upstream service. These limits are applied on a per-service-instance basis. The following limits are respected.MaxConnections
(int: 0)
- The maximum number of connections a service instance will be allowed to establish against the given upstream. Use this to limit HTTP/1.1 traffic, since HTTP/1.1 has a request per connection.MaxPendingRequests
(int: 0)
- The maximum number of requests that will be queued while waiting for a connection to be established. For this configuration to be respected, a L7 protocol must be defined in theprotocol
field.MaxConcurrentRequests
(int: 0)
- The maximum number of concurrent requests that will be allowed at a single point in time. Use this to limit HTTP/2 traffic, since HTTP/2 has many requests per connection. For this configuration to be respected, a L7 protocol must be defined in theprotocol
field.
PassiveHealthCheck
(PassiveHealthCheck: <optional>)
- Passive health checks are used to remove hosts from the upstream cluster which are unreachable or are returning errors..Interval
(duration: 0s)
- The time between checks. Each check will cause hosts which have exceededmax_failures
to be removed from the load balancer, and any hosts which have passed their ejection time to be returned to the load balancer.MaxFailures
(int: 0)
- The number of consecutive failures which cause a host to be removed from the load balancer.
Defaults
(UpstreamConfig: <optional>)
- Default configuration that applies to all upstreams of this service.Protocol
(string: "")
- The protocol for the upstream listener.
NOTE: The protocol of a service should ideally be configured via theprotocol
field of aservice-defaults
config entry for the upstream destination service. Configuring it in a proxy upstream config will not fully enable some L7 features. It is supported here for backwards compatibility with Consul versions prior to 1.6.0.ConnectTimeoutMs
(int: 5000)
- The number of milliseconds to allow when making upstream connections before timing out.
NOTE: The connect timeout of a service should ideally be configured via theconnect_timeout
field of aservice-resolver
config entry for the upstream destination service. Configuring it in a proxy upstream config will not fully enable some L7 features. It is supported here for backwards compatibility with Consul versions prior to 1.6.0.MeshGateway
(MeshGatewayConfig: <optional>)
- Controls the default mesh gateway configuration for this upstream.Mode
(string: "")
- One ofnone
,local
, orremote
.
Limits
(Limits: <optional>)
- A set of limits to apply when connecting to the upstream service. These limits are applied on a per-service-instance basis. The following limits are respected.MaxConnections
(int: 0)
- The maximum number of connections a service instance will be allowed to establish against the given upstream. Use this to limit HTTP/1.1 traffic, since HTTP/1.1 has a request per connection.MaxPendingRequests
(int: 0)
- The maximum number of requests that will be queued while waiting for a connection to be established. For this configuration to be respected, a L7 protocol must be defined in theprotocol
field.MaxConcurrentRequests
(int: 0)
- The maximum number of concurrent requests that will be allowed at a single point in time. Use this to limit HTTP/2 traffic, since HTTP/2 has many requests per connection. For this configuration to be respected, a L7 protocol must be defined in theprotocol
field.
PassiveHealthCheck
(PassiveHealthCheck: <optional>)
- Passive health checks are used to remove hosts from the upstream cluster which are unreachable or are returning errors..Interval
(duration: 0s)
- The time between checks. Each check will cause hosts which have exceededmax_failures
to be removed from the load balancer, and any hosts which have passed their ejection time to be returned to the load balancer.MaxFailures
(int: 0)
- The number of consecutive failures which cause a host to be removed from the load balancer.
TransparentProxy
(TransparentProxyConfig: <optional>)
- Controls configuration specific to proxies in transparent mode. Added in v1.10.0.OutboundListenerPort
(int: "15001")
- The port the proxy should listen on for outbound traffic. This must be the port where outbound application traffic is redirected to.DialedDirectly
(bool: false)
- Determines whether this proxy instance's IP address can be dialed directly by transparent proxies. Typically transparent proxies dial upstreams using the "virtual" tagged address, which load balances across instances. Dialing individual instances can be helpful in cases like stateful services such as a database cluster with a leader.
MeshGateway
(MeshGatewayConfig: <optional>)
- Controls the default mesh gateway configuration for this service. Added in v1.6.0.Mode
(string: "")
- One ofnone
,local
, orremote
.
ExternalSNI
(string: "")
- This is an optional setting that allows for the TLS SNI value to be changed to a non-connect value when federating with an external system. Added in v1.6.0.Expose
(ExposeConfig: <optional>)
- Controls the default expose path configuration for Envoy. Added in v1.6.2.
Exposing paths through Envoy enables a service to protect itself by only listening on localhost, while still allowing non-Connect-enabled applications to contact an HTTP endpoint. Some examples include: exposing a/metrics
path for Prometheus or/healthz
for kubelet liveness checks.Checks
(bool: false)
- If enabled, all HTTP and gRPC checks registered with the agent are exposed through Envoy. Envoy will expose listeners for these checks and will only accept connections originating from localhost or Consul's advertise address. The port for these listeners are dynamically allocated from expose_min_port to expose_max_port. This flag is useful when a Consul client cannot reach registered services over localhost. One example is when running Consul on Kubernetes, and Consul agents run in their own pods.Paths
(array<Path>: [])
- A list of paths to expose through Envoy.Path
(string: "")
- The HTTP path to expose. The path must be prefixed by a slash. ie:/metrics
.LocalPathPort
(int: 0)
- The port where the local service is listening for connections to the path.ListenerPort
(int: 0)
- The port where the proxy will listen for connections. This port must be available for the listener to be set up. If the port is not free then Envoy will not expose a listener for the path, but the proxy registration will not fail.Protocol
(string: "http")
- Sets the protocol of the listener. One ofhttp
orhttp2
. For gRPC usehttp2
.
ACLs
Configuration entries may be protected by ACLs.
Reading a service-defaults
config entry requires service:read
on the resource.
Creating, updating, or deleting a service-defaults
config entry requires
service:write
on the resource.