Service Defaults
The service-defaults
config entry kind (ServiceDefaults
on Kubernetes) controls default global values for a service, such as its 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:
HCL
- HCL
- Kubernetes YAML
- JSON
Kind = "service-defaults"
Name = "web"
Namespace = "default"
Protocol = "http"
apiVersion: consul.hashicorp.com/v1alpha1
kind: ServiceDefaults
metadata:
name: web
spec:
protocol: http
apiVersion: consul.hashicorp.com/v1alpha1
kind: ServiceDefaults
metadata:
name: web
spec:
protocol: 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.
HCL
- HCL
- Kubernetes YAML
- JSON
Kind = "service-defaults"
Name = "counting"
UpstreamConfig = {
Defaults = {
MeshGateway = {
Mode = "local"
}
Limits = {
MaxConnections = 512
MaxPendingRequests = 512
MaxConcurrentRequests = 512
}
}
Overrides = [
{
Name = "dashboard"
MeshGateway = {
Mode = "remote"
}
}
]
}
Kind = "service-defaults"
Name = "counting"
UpstreamConfig = {
Defaults = {
MeshGateway = {
}
Limits = {
MaxConnections = 512
MaxPendingRequests = 512
MaxConcurrentRequests = 512
}
}
Overrides = [
{
Name = "dashboard"
MeshGateway = {
Mode = "remote"
}
}
]
}
kind: ServiceDefaults
metadata:
name: counting
spec:
upstreamConfig:
defaults:
meshGateway:
mode: local
limits:
maxConnections: 512
maxPendingRequests: 512
maxConcurrentRequests: 512
overrides:
- name: dashboard
meshGateway:
mode: remote
{
"Kind": "service-defaults",
"Name": "counting",
"UpstreamConfig": {
"Defaults": {
"MeshGateway": {
"Mode": "local"
},
"Limits": {
"MaxConnections": 512,
"MaxPendingRequests": 512,
"MaxConcurrentRequests": 512
}
},
"Overrides": [
{
"Name": "dashboard",
"MeshGateway": {
"Mode": "remote"
}
}
]
}
}
{
"Kind": "service-defaults",
"Name": "counting",
"UpstreamConfig": {
"Defaults": {
"Mode": "local"
},
"Limits": {
"MaxConnections": 512,
"MaxPendingRequests": 512,
"MaxConcurrentRequests": 512
}
},
"Overrides": [
{
"Name": "dashboard",
"MeshGateway": {
"Mode": "remote"
}
}
]
}
}
Kind - Must be set to
service-defaults
(string: <required>)
- Set to the name of the service being configured.Namespace
(string: "default")
Enterprise
- Specifies the namespace the config entry will apply to.
(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.
(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 the and service-router config entries for a service. It also unlocks the ability to define L7 intentions via . Supported values are one oftcp
,http
, , orgrpc
.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.(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*
.(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 the field of a service-defaults config entry for the upstream destination service. Configuring it in a proxy upstream config will not fully enable some . 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 the field of a service-resolver config entry for the upstream destination service. Configuring it in a proxy upstream config will not fully enable some . It is supported here for backwards compatibility with Consul versions prior to 1.6.0.
MeshGateway
(MeshGatewayConfig: <optional>)
- Controls the default for this upstream.- Mode
(string: "")
- One ofnone
,local
, orremote
.
- Mode
(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.(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: <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.(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.(string: "")
- The protocol for the upstream listener.NOTE: The protocol of a service should ideally be configured via the protocol field of a 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.
(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 the connect_timeout field of a 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.
(MeshGatewayConfig: <optional>)
- Controls the default mesh gateway configuration for this upstream.-
(string: "")
- One ofnone
,local
, orremote
.
-
-
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.(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: <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.(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.(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.
(MeshGatewayConfig: <optional>)
- Controls the default mesh gateway configuration for this service. Added in v1.6.0.-
(string: "")
- One ofnone
,local
, orremote
.
-
ExternalSNI
(string: "")
- This is an optional setting that allows for the TLS 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 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 . The port for these listeners are dynamically allocated from expose_min_port to . 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.(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.(string: "http")
- Sets the protocol of the listener. One ofhttp
orhttp2
. For gRPC usehttp2
.
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 on the resource.