Skip to content

Commit 8cadfc4

Browse files
authored
Merge pull request #27088 from maplain/service-internal-traffic-policy
Add documentation for Service InternalTrafficPolicy
2 parents bfa3449 + 66cb8f9 commit 8cadfc4

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
reviewers:
3+
- maplain
4+
title: Service Internal Traffic Policy
5+
content_type: concept
6+
---
7+
8+
9+
<!-- overview -->
10+
11+
{{< feature-state for_k8s_version="v1.21" state="alpha" >}}
12+
13+
_Service Internal Traffic Policy_ enables internal traffic restrictions to only route
14+
internal traffic to endpoints within the node the traffic originated from. The
15+
"internal" traffic here refers to traffic originated from Pods in the current
16+
cluster. This can help to reduce costs and improve performance.
17+
18+
<!-- body -->
19+
20+
## Using Service Internal Traffic Policy
21+
22+
You can enable Internal Traffic Policy for a Service by setting the
23+
`spec.internalTrafficPolicy` to "Local". This tells kube-proxy to only use node
24+
local endpoints for cluster internal traffic. Importantly, for pods on nodes with
25+
no endpoints for a given Service, the Service will behave as if it has zero
26+
endpoints (for Pods on this node) even if the service does have endpoints on other
27+
nodes.
28+
29+
The following example shows what a Service looks like when internalTrafficPolicy
30+
is set to "Local":
31+
32+
```yaml
33+
apiVersion: v1
34+
kind: Service
35+
metadata:
36+
name: my-service
37+
spec:
38+
selector:
39+
app: MyApp
40+
ports:
41+
- protocol: TCP
42+
port: 80
43+
targetPort: 9376
44+
internalTrafficPolicy: Local
45+
```
46+
47+
## How it Works
48+
49+
kube-proxy filters the endpoints it routes to based on the
50+
`spec.internalTrafficPolicy` setting. When it's "Local", only node local
51+
endpoints are considered. When it's "Cluster" or missing, all endpoints are
52+
considered.
53+
When the feature gate `ServiceInternalTrafficPolicy` is on,
54+
`spec.internalTrafficPolicy` defaults to "Cluster".
55+
56+
## Constraints
57+
58+
* Service Internal Traffic Policy is not used when `externalTrafficPolicy` is set
59+
to "Local" on a Service. It is possible to use both features in the same cluster
60+
on different Services, just not on the same Service.
61+
62+
## {{% heading "whatsnext" %}}
63+
64+
* Read about [enabling Topology Aware Hints](/docs/tasks/administer-cluster/enabling-topology-aware-hints)
65+
* Read about [Service External Traffic Policy](/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip)
66+
* Read [Connecting Applications with Services](/docs/concepts/services-networking/connect-applications-service/)

content/en/docs/reference/command-line-tools-reference/feature-gates.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ different Kubernetes components.
162162
| `SCTPSupport` | `true` | Beta | 1.19 | |
163163
| `ServerSideApply` | `false` | Alpha | 1.14 | 1.15 |
164164
| `ServerSideApply` | `true` | Beta | 1.16 | |
165+
| `ServiceInternalTrafficPolicy` | `false` | Alpha | 1.21 | |
165166
| `ServiceLBNodePortControl` | `false` | Alpha | 1.20 | |
166167
| `ServiceLoadBalancerClass` | `false` | Alpha | 1.21 | |
167168
| `ServiceNodeExclusion` | `false` | Alpha | 1.8 | 1.18 |
@@ -772,6 +773,7 @@ Each feature gate is designed for enabling/disabling a specific feature:
772773
[Configure Service Accounts for Pods](/docs/tasks/configure-pod-container/configure-service-account/#service-account-issuer-discovery)
773774
for more details.
774775
- `ServiceAppProtocol`: Enables the `AppProtocol` field on Services and Endpoints.
776+
- `ServiceInternalTrafficPolicy`: Enables the `InternalTrafficPolicy` field on Services
775777
- `ServiceLBNodePortControl`: Enables the `spec.allocateLoadBalancerNodePorts`
776778
field on Services.
777779
- `ServiceLoadBalancerClass`: Enables the `LoadBalancerClass` field on Services. See [Specifying class of load balancer implementation](/docs/concepts/services-networking/service/#specifying-class-of-load-balancer-implementation-load-balancer-class) for more details.

0 commit comments

Comments
 (0)