Skip to content

Commit 8e64c56

Browse files
author
Matt Turner
committed
Add simple examples of DestinationRules
1 parent cdf024a commit 8e64c56

File tree

8 files changed

+164
-0
lines changed

8 files changed

+164
-0
lines changed

Istio/DestinationRule/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# DestinationRule
2+
3+
After a destination Service is chosen by a `VirtualService` (the request is routed), a `DestinationRule` specifies how that Service should be talked to.
4+
5+
> In this directory, "endpoint pool" means the set of endpoints to which traffic has been routed; a Service or a Subset of a Service
6+
7+
It describes how to load balance between the network endpoints of the Service (as found in the Service Registry).
8+
It also says how connections should be made to those network endpoints (HTTP version, TLS stance) and how they should be managed (keep-alive times, maximum active connections to load-balance onto any individual endpoint at once).
9+
10+
`DestinationRules` configure the _client_ sidecars, eg for the flow `service-a -> sidecar-a -> sidecar-b -> service-b` the `DestinationRule` for host "service-b" configures each instance of "sidecar-a".
11+
Thus the connection options technically configure how "sidecar-a" talks to _"sidecar-b"_ (if the destination is also in the mesh, or directly to the service or whatever proxies are in front of it if it's not).
12+
The only time to bear in mind that you're talking to the server's sidecar rather than the actual "app" is when considering TLS, as the server sidecar will terminate this.
13+
There is no way to configure the behaviour from "sidecar-b" to "service-b"; this is basically a passthrough, except the mutual TLS upgrade noted above.
14+
15+
`DestinationRules` are implemented locally by each sidecar; there is no global coordination between sidecars.
16+
For example
17+
* circuit-breaker detection and elimination is done per client sidecar; each holds their own state for this which might differ from other sidecars'
18+
19+
`DestinationRules` configure how one client should talk to the _pool_ of endpoints (a Service or subset of a Service).
20+
For example
21+
* load-balancer config controls how each individual client should pick one of the _n_ servers (endpoint instances) each time there's a new outbound connection
22+
* circuit-breaking applies across the pool (of servers); it temporarily removes instances from the pool (even if Service Discovery says they're healthy thus they're in the service registry)
23+
* TLS config applies to all connections from the client to any server (in the pool)
24+
The exception is connection-pool settings, which apply to each client-server pair individually.
25+
Recall though that they apply to `sidecar-a -> sidecar-b`, not `sidecar-b -> service-b`.
26+
27+
It also somewhat confusingly details the Subsets of the Service available as routing targets in `VirtualServices`.
28+
You might think this would be on something like a `ServiceEntry` resource that obviously manipulates the Service Registry.
29+
However, `DestinationRule` settings can be per-subset (as they're different workload binaries and might need treating differently).
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Evaluates error rates for each endpoint in the pool against the settings here, ejecting them if they cross the thresholds.
2+
---
3+
apiVersion: networking.istio.io/v1beta1
4+
kind: DestinationRule
5+
metadata:
6+
name: circuit-breaker
7+
spec:
8+
host: service-a
9+
trafficPolicy:
10+
outlierDetection:
11+
consecutive5xxErrors: 7 # Default 5
12+
interval: 5m # Interval over which errors are counted and compared to the threshold. This is a periodic check, not a rolling one.
13+
baseEjectionTime: 10s # Initial period for which the endpoint is ejected from the endpoint pool. Repeated ejections are longer each time. Default 30s
14+
maxEjectionPercent: 50 # Max % of endpoints that can ejected from the endpoint pool. Default 10
15+
minHealthPercent: 50 # Min % of endpoints in the endpoint pool that must be healthy for circuit-breaking to activate. Default 0
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# NB: these apply per server workload (Pod).
2+
# eg `maxConnections: 100` means each *client* Pod's sidecar will open max 100 connections to each individual *server* endpoint.
3+
---
4+
apiVersion: networking.istio.io/v1beta1
5+
kind: DestinationRule
6+
metadata:
7+
name: connection-pool-settings
8+
spec:
9+
host: service-a
10+
trafficPolicy:
11+
connectionPool:
12+
tcp:
13+
maxConnections: 100 # Default 4bn
14+
connectTimeout: 50ms # Default 10s
15+
tcpKeepalive: # TCP-level keepalives ie SO_KEEPALIVE
16+
time: 3600s # Default 2h
17+
interval: 50s # Default 75s
18+
http:
19+
maxRequestsPerConnection: 1 # Disables HTTP connection keep-alive/reuse. Default unlimited
20+
idleTimeout: 1m # How long a keep-alive tcp connection will stay open if unused for any http requests. Default 1h
21+
h2UpgradePolicy: UPGRADE # Upgrade http1.1 connections arriving at the sidecar to h2 from sidecar -> workload. Default: use mesh-wide setting
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: networking.istio.io/v1beta1
2+
kind: DestinationRule
3+
metadata:
4+
name: load-balance-simple
5+
spec:
6+
host: service-a
7+
trafficPolicy:
8+
loadBalancer:
9+
simple: LEAST_CONN # Default: ROUND_ROBIN, others: RANDOM
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: networking.istio.io/v1beta1
2+
kind: DestinationRule
3+
metadata:
4+
name: sticky-sessions-user-cookie
5+
spec:
6+
host: service-a
7+
trafficPolicy:
8+
loadBalancer:
9+
consistentHash:
10+
httpCookie:
11+
name: user
12+
ttl: 0s
13+
---
14+
apiVersion: networking.istio.io/v1beta1
15+
kind: DestinationRule
16+
metadata:
17+
name: sticky-sessions-user-header
18+
spec:
19+
host: service-a
20+
trafficPolicy:
21+
loadBalancer:
22+
consistentHash:
23+
httpHeaderName: x-remote-user
24+
---
25+
apiVersion: networking.istio.io/v1beta1
26+
kind: DestinationRule
27+
metadata:
28+
name: sticky-sessions-source-ip
29+
spec:
30+
host: service-a
31+
trafficPolicy:
32+
loadBalancer:
33+
consistentHash:
34+
useSourceIp: true

Istio/DestinationRule/subsets.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: networking.istio.io/v1beta1
2+
kind: DestinationRule
3+
metadata:
4+
name: subsets
5+
spec:
6+
host: service-a
7+
subsets:
8+
- name: v1 # Arbitrary name for subset
9+
labels: # Kubernetes Pod labels to match
10+
version: v1
11+
- name: v2
12+
labels:
13+
version: v2

Istio/DestinationRule/tls.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: networking.istio.io/v1beta1
2+
kind: DestinationRule
3+
metadata:
4+
name: accept-external-tls
5+
spec:
6+
host: external-host-a
7+
trafficPolicy:
8+
tls:
9+
mode: SIMPLE
10+
---
11+
# NB: This establishes an mTLS connection with an upstream endpoint.
12+
# It's for _mesh-external_ endpoints; within the mesh Istio automatically establishes mTLS connections between pairs of sidecars.
13+
apiVersion: networking.istio.io/v1beta1
14+
kind: DestinationRule
15+
metadata:
16+
name: mutual-external-tls
17+
spec:
18+
host: external-host-a
19+
trafficPolicy:
20+
tls:
21+
mode: MUTUAL
22+
privateKey: /etc/certs/client_key.pem
23+
clientCertificate: /etc/certs/client_certificiate.pem
24+
caCertificates: /etc/certs/server_root_certificates.pem

Istio/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Resource Types
2+
Colloquially
3+
* `ServiceEntry` - what Services exist and how are their network endpoints found?
4+
* `VirtualService` - to which Service should traffic for a given hostname be sent?
5+
* `DestinationRule` - how do I talk to that Service?
6+
7+
### Services in Istio
8+
_Services_ are the *destination* of Route Rules (the `host` which a `VirtualService` matches is an arbitrary string).
9+
_Services_ by the Istio definition are morally "units of application behaviour".
10+
They are made of network _endpoints_: Pods, and external endpoints.
11+
Istio has a _Service Registry_ of all the Services it knows about.
12+
In some configurations it will refuse to send traffic to Services that aren't in the Service Registry (in others it'll assume the Service exists and take some guesses about how to find its endpoints and how to talk to them).
13+
14+
In a Kubernetes environment, the Service Registry is populated from Kubernetes `Service` instances.
15+
Extra Service Registry entries (eg for internet endpoints, VMs) can be added with the `ServiceEntry` resource.
16+
Recall that, in some mesh configurations, such `ServiceEntries` are *necessary* for workloads in the mesh to talk to anything outside the cluster.
17+
`ServiceEntry` is a higher-level resource - doesn't necessarily specify all endpoints in a Service, instead it says where to discover them.
18+
19+
There is no (easy) way to view the contents of the Service Registry; the imported Kubernetes `Services`, DNS query results, etc aren't reflected as a read-only resource like Kubernetes' `Endpoint`.

0 commit comments

Comments
 (0)