Destination Rule
Version specific policies can be specified by defining a namedsubset
and overriding the settings specified at the service level. Thefollowing rule uses a round robin load balancing policy for all trafficgoing to a subset named testversion that is composed of endpoints (e.g.,pods) with labels (version:v3).
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: bookinfo-ratings
spec:
host: ratings.prod.svc.cluster.local
trafficPolicy:
loadBalancer:
simple: LEAST_CONN
subsets:
- name: testversion
labels:
version: v3
trafficPolicy:
loadBalancer:
simple: ROUND_ROBIN
Note: Policies specified for subsets will not take effect untila route rule explicitly sends traffic to this subset.
Traffic policies can be customized to specific ports as well. Thefollowing rule uses the least connection load balancing policy for alltraffic to port 80, while uses a round robin load balancing setting fortraffic to the port 9080.
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
name: bookinfo-ratings-port
spec:
host: ratings.prod.svc.cluster.local
trafficPolicy: # Apply to all ports
portLevelSettings:
- port:
number: 80
loadBalancer:
simple: LEAST_CONN
- port:
number: 9080
loadBalancer:
simple: ROUND_ROBIN
Connection pool settings for an upstream host. The settings apply toeach individual host in the upstream service. See Envoy’s circuitbreakerfor more details. Connection pool settings can be applied at the TCPlevel as well as at HTTP level.
For example, the following rule sets a limit of 100 connections to redisservice called myredissrv with a connect timeout of 30ms
ConnectionPoolSettings.HTTPSettings
Settings applicable to HTTP1.1/HTTP2/GRPC connections.
Field | Type | Description | Required |
---|---|---|---|
http1MaxPendingRequests | int32 | Maximum number of pending HTTP requests to a destination. Default 2^32-1. | No |
http2MaxRequests | int32 | Maximum number of requests to a backend. Default 2^32-1. | No |
maxRequestsPerConnection | int32 | Maximum number of requests per connection to a backend. Setting thisparameter to 1 disables keep alive. Default 0, meaning “unlimited”,up to 2^29. | No |
maxRetries | int32 | Maximum number of retries that can be outstanding to all hosts in acluster at a given time. Defaults to 2^32-1. | No |
idleTimeout | Duration | The idle timeout for upstream connection pool connections. The idle timeout is defined as the period in which there are no active requests.If not set, there is no idle timeout. When the idle timeout is reached the connection will be closed.Note that request based timeouts mean that HTTP/2 PINGs will not keep the connection alive. Applies to both HTTP1.1 and HTTP2 connections. | No |
h2UpgradePolicy |
| Specify if http1.1 connection should be upgraded to http2 for the associated destination. | No |
ConnectionPoolSettings.HTTPSettings.H2UpgradePolicy
Policy for upgrading http1.1 connections to http2.
Name | Description |
---|---|
DEFAULT | Use the global default. |
DO_NOT_UPGRADE | Do not upgrade the connection to http2.This opt-out option overrides the default. |
UPGRADE | Upgrade the connection to http2.This opt-in option overrides the default. |
ConnectionPoolSettings.TCPSettings
Settings common to both HTTP and TCP upstream connections.
Field | Type | Description | Required |
---|---|---|---|
maxConnections | int32 | Maximum number of HTTP1 /TCP connections to a destination host. Default 2^32-1. | No |
connectTimeout | Duration | TCP connection timeout. | No |
tcpKeepalive |
| If set then set SO_KEEPALIVE on the socket to enable TCP Keepalives. | No |
ConnectionPoolSettings.TCPSettings.TcpKeepalive
Field | Type | Description | Required |
---|---|---|---|
probes | uint32 | Maximum number of keepalive probes to send without response beforedeciding the connection is dead. Default is to use the OS level configuration(unless overridden, Linux defaults to 9.) | No |
time |
| The time duration a connection needs to be idle before keep-aliveprobes start being sent. Default is to use the OS level configuration(unless overridden, Linux defaults to 7200s (ie 2 hours.) | No |
interval | Duration | The time duration between keep-alive probes.Default is to use the OS level configuration(unless overridden, Linux defaults to 75s.) | No |
DestinationRule defines policies that apply to traffic intended for a serviceafter routing has occurred.
LoadBalancerSettings
Load balancing policies to apply for a specific destination. See Envoy’sload balancingdocumentationfor more details.
For example, the following rule uses a round robin load balancing policyfor all traffic going to the ratings service.
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: bookinfo-ratings
spec:
host: ratings.prod.svc.cluster.local
trafficPolicy:
loadBalancer:
simple: ROUND_ROBIN
The following example sets up sticky sessions for the ratings servicehashing-based load balancer for the same ratings service using thethe User cookie as the hash key.
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: bookinfo-ratings
spec:
host: ratings.prod.svc.cluster.local
trafficPolicy:
loadBalancer:
consistentHash:
httpCookie:
name: user
ttl: 0s
Field | Type | Description | Required |
---|---|---|---|
simple |
| Yes | |
consistentHash | ConsistentHashLB (oneof) | Yes |
LoadBalancerSettings.ConsistentHashLB
Consistent Hash-based load balancing can be used to provide softsession affinity based on HTTP headers, cookies or otherproperties. This load balancing policy is applicable only for HTTPconnections. The affinity to a particular destination host will belost when one or more hosts are added/removed from the destinationservice.
Field | Type | Description | Required |
---|---|---|---|
httpHeaderName | string (oneof) | Hash based on a specific HTTP header. | Yes |
httpCookie | HTTPCookie (oneof) | Hash based on HTTP cookie. | Yes |
useSourceIp | bool (oneof) | Hash based on the source IP address. | Yes |
minimumRingSize | uint64 | The minimum number of virtual nodes to use for the hashring. Defaults to 1024. Larger ring sizes result in more granularload distributions. If the number of hosts in the load balancingpool is larger than the ring size, each host will be assigned asingle virtual node. | No |
LoadBalancerSettings.ConsistentHashLB.HTTPCookie
Describes a HTTP cookie that will be used as the hash key for theConsistent Hash load balancer. If the cookie is not present, it willbe generated.
Field | Type | Description | Required |
---|---|---|---|
name | string | Name of the cookie. | Yes |
path | string | Path to set for the cookie. | No |
ttl | Duration | Lifetime of the cookie. | Yes |
LoadBalancerSettings.SimpleLB
Standard load balancing algorithms that require no tuning.
Name | Description |
---|---|
ROUND_ROBIN | Round Robin policy. Default |
LEAST_CONN | The least request load balancer uses an O(1) algorithm which selectstwo random healthy hosts and picks the host which has fewer activerequests. |
RANDOM | The random load balancer selects a random healthy host. The randomload balancer generally performs better than round robin if no healthchecking policy is configured. |
PASSTHROUGH | This option will forward the connection to the original IP addressrequested by the caller without doing any form of loadbalancing. This option must be used with care. It is meant foradvanced use cases. Refer to Original Destination load balancer inEnvoy for further details. |
A Circuit breaker implementation that tracks the status of eachindividual host in the upstream service. Applicable to both HTTP andTCP services. For HTTP services, hosts that continually return 5xxerrors for API calls are ejected from the pool for a pre-defined periodof time. For TCP services, connection timeouts or connectionfailures to a given host counts as an error when measuring theconsecutive errors metric. See Envoy’s outlierdetectionfor more details.
Subset
A subset of endpoints of a service. Subsets can be used for scenarioslike A/B testing, or routing to a specific version of a service. Referto VirtualService documentation for examples of usingsubsets in these scenarios. In addition, traffic policies defined at theservice-level can be overridden at a subset-level. The following ruleuses a round robin load balancing policy for all traffic going to asubset named testversion that is composed of endpoints (e.g., pods) withlabels (version:v3).
kind: DestinationRule
metadata:
name: bookinfo-ratings
spec:
host: ratings.prod.svc.cluster.local
trafficPolicy:
loadBalancer:
simple: LEAST_CONN
subsets:
- name: testversion
labels:
version: v3
loadBalancer:
simple: ROUND_ROBIN
Note: Policies specified for subsets will not take effect untila route rule explicitly sends traffic to this subset.
One or more labels are typically required to identify the subset destination,however, when the corresponding DestinationRule represents a host thatsupports multiple SNI hosts (e.g., an egress gateway), a subset without labelsmay be meaningful. In this case a traffic policy with can be used to identify a specific SNI host corresponding to the named subset.
Field | Type | Description | Required |
---|---|---|---|
name | string | Name of the subset. The service name and the subset name canbe used for traffic splitting in a route rule. | Yes |
labels | map<string, string> | Labels apply a filter over the endpoints of a service in theservice registry. See route rules for examples of usage. | No |
trafficPolicy | TrafficPolicy | Traffic policies that apply to this subset. Subsets inherit thetraffic policies specified at the DestinationRule level. Settingsspecified at the subset level will override the corresponding settingsspecified at the DestinationRule level. | No |
TLSSettings
SSL/TLS related settings for upstream connections. See Envoy’s TLScontextfor more details. These settings are common to both HTTP and TCP upstreams.
For example, the following rule configures a client to use mutual TLSfor connections to upstream database cluster.
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: db-mtls
spec:
host: mydbserver.prod.svc.cluster.local
trafficPolicy:
tls:
mode: MUTUAL
clientCertificate: /etc/certs/myclientcert.pem
privateKey: /etc/certs/client_private_key.pem
caCertificates: /etc/certs/rootcacerts.pem
The following rule configures a client to use TLS when talking to aforeign service whose domain matches *.foo.com.
The following rule configures a client to use Istio mutual TLS when talkingto rating services.
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: ratings-istio-mtls
spec:
host: ratings.prod.svc.cluster.local
trafficPolicy:
mode: ISTIO_MUTUAL
Field | Type | Description | Required |
---|---|---|---|
mode |
| Indicates whether connections to this port should be securedusing TLS. The value of this field determines how TLS is enforced. | Yes |
clientCertificate | string | REQUIRED if mode is MUTUAL . The path to the file holding theclient-side TLS certificate to use.Should be empty if mode is ISTIO_MUTUAL . | No |
privateKey | string | REQUIRED if mode is MUTUAL . The path to the file holding theclient’s private key.Should be empty if mode is ISTIO_MUTUAL . | No |
caCertificates | string | OPTIONAL: The path to the file containing certificate authoritycertificates to use in verifying a presented server certificate. Ifomitted, the proxy will not verify the server’s certificate.Should be empty if mode is ISTIO_MUTUAL . | No |
subjectAltNames | string[] | A list of alternate names to verify the subject identity in thecertificate. If specified, the proxy will verify that the servercertificate’s subject alt name matches one of the specified values.If specified, this list overrides the value of subject_alt_namesfrom the ServiceEntry. | No |
sni | string | SNI string to present to the server during TLS handshake. | No |
TLSSettings.TLSmode
TLS connection mode
Name | Description |
---|---|
DISABLE | Do not setup a TLS connection to the upstream endpoint. |
SIMPLE | Originate a TLS connection to the upstream endpoint. |
MUTUAL | Secure connections to the upstream using mutual TLS by presentingclient certificates for authentication. |
ISTIO_MUTUAL | Secure connections to the upstream using mutual TLS by presentingclient certificates for authentication.Compared to Mutual mode, this mode uses certificates generatedautomatically by Istio for mTLS authentication. When this mode isused, all other fields in TLSSettings should be empty. |
TrafficPolicy
Field | Type | Description | Required |
---|---|---|---|
loadBalancer | LoadBalancerSettings | Settings controlling the load balancer algorithms. | No |
connectionPool |
| Settings controlling the volume of connections to an upstream service | No |
outlierDetection | OutlierDetection | Settings controlling eviction of unhealthy hosts from the load balancing pool | No |
tls |
| TLS related settings for connections to the upstream service. | No |
portLevelSettings | PortTrafficPolicy[] | Traffic policies specific to individual ports. Note that port levelsettings will override the destination-level settings. Trafficsettings specified at the destination-level will not be inherited whenoverridden by port-level settings, i.e. default values will be appliedto fields omitted in port-level traffic policies. | No |
Traffic policies that apply to specific ports of the service