Skip to content

Commit c26ed62

Browse files
committed
feat: add guide for configuring Service Entry and routing in Istio
Signed-off-by: Tom <[email protected]>
1 parent b307a77 commit c26ed62

File tree

2 files changed

+456
-0
lines changed

2 files changed

+456
-0
lines changed
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
---
2+
sidebar_position: 5
3+
title: Try Service Entry
4+
---
5+
6+
A Service Entry enables you to add entries to Istio's internal service registry so that services in the mesh can access and route to these manually specified services. This guide shows you how to configure external service access using Service Entry.
7+
8+
## Preparation
9+
10+
1. **Make default namespace managed by Kmesh**
11+
2. **Deploy Httpbin as sample application and Sleep as curl client**
12+
3. **Install waypoint for default namespace**
13+
14+
_The above steps could refer to [Install Waypoint | Kmesh](/docs/application-layer/install_waypoint.md#preparation)_
15+
16+
## Deploy Sample Applications
17+
18+
We need to deploy Httpbin as the target service:
19+
20+
```bash
21+
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.21/samples/httpbin/httpbin.yaml
22+
```
23+
24+
Check the deployment status:
25+
26+
```bash
27+
kubectl get pods
28+
```
29+
30+
You should see httpbin and sleep running:
31+
32+
```bash
33+
NAME READY STATUS RESTARTS AGE
34+
httpbin-6f4464f6c5-h9x2p 1/1 Running 0 30s
35+
sleep-9454cc476-86vgb 1/1 Running 0 5m
36+
```
37+
38+
## Configure Service Entry and Routing Rules
39+
40+
Now we will create a Service Entry to define an external service and configure a VirtualService to route traffic to the internal service.
41+
42+
Apply the following configuration:
43+
44+
```bash
45+
kubectl apply -f - <<EOF
46+
apiVersion: networking.istio.io/v1alpha3
47+
kind: ServiceEntry
48+
metadata:
49+
name: external-fake-svc
50+
namespace: default
51+
spec:
52+
exportTo:
53+
- "*"
54+
hosts:
55+
- kmesh-fake.com
56+
ports:
57+
- name: http
58+
number: 80
59+
protocol: HTTP
60+
addresses:
61+
- 240.240.0.1
62+
resolution: DNS
63+
---
64+
apiVersion: networking.istio.io/v1alpha3
65+
kind: VirtualService
66+
metadata:
67+
name: fake-service-route
68+
namespace: default
69+
spec:
70+
hosts:
71+
- kmesh-fake.com
72+
http:
73+
- match:
74+
- uri:
75+
prefix: /
76+
route:
77+
- destination:
78+
host: httpbin.default.svc.cluster.local
79+
port:
80+
number: 8000
81+
EOF
82+
```
83+
84+
## Understanding the Configuration
85+
86+
This configuration creates:
87+
88+
1. **ServiceEntry**: Defines an external service named `kmesh-fake.com` using IP address `240.240.0.1`
89+
2. **VirtualService**: Redirects traffic accessing `kmesh-fake.com` to the cluster-internal `httpbin` service
90+
91+
## Test Service Entry Configuration
92+
93+
1. **Test access to the virtual external service**:
94+
95+
```bash
96+
kubectl exec deploy/sleep -- curl -s http://kmesh-fake.com/headers
97+
```
98+
99+
You should see a response from the httpbin service:
100+
101+
```json
102+
{
103+
"headers": {
104+
"Accept": "*/*",
105+
"Host": "kmesh-fake.com",
106+
"User-Agent": "curl/8.16.0"
107+
}
108+
}
109+
```
110+
111+
2. **Verify request header information**:
112+
113+
```bash
114+
kubectl exec deploy/sleep -- curl -s http://kmesh-fake.com/get
115+
```
116+
117+
The output should show the request was successfully routed to the httpbin service:
118+
119+
```json
120+
{
121+
"args": {},
122+
"headers": {
123+
"Accept": "*/*",
124+
"Host": "kmesh-fake.com",
125+
"User-Agent": "curl/8.16.0"
126+
},
127+
"origin": "10.244.1.6",
128+
"url": "http://kmesh-fake.com/get"
129+
}
130+
```
131+
132+
3. **Test different HTTP endpoints**:
133+
134+
Test successful status code:
135+
136+
```bash
137+
kubectl exec deploy/sleep -- curl -s http://kmesh-fake.com/status/200
138+
```
139+
140+
Test specific status code and display the return code:
141+
142+
```bash
143+
kubectl exec deploy/sleep -- curl -s -o /dev/null -w "%{http_code}\n" http://kmesh-fake.com/status/418
144+
```
145+
146+
The second command should return the HTTP status code:
147+
148+
```txt
149+
418
150+
```
151+
152+
4. **Check response headers**:
153+
154+
```bash
155+
kubectl exec deploy/sleep -- curl -IsS http://kmesh-fake.com/headers
156+
```
157+
158+
You should see response headers containing envoy and routing information:
159+
160+
```txt
161+
HTTP/1.1 200 OK
162+
server: envoy
163+
date: Sat, 20 Sep 2025 07:51:51 GMT
164+
content-type: application/json
165+
content-length: 78
166+
access-control-allow-origin: *
167+
access-control-allow-credentials: true
168+
x-envoy-upstream-service-time: 1
169+
x-envoy-decorator-operation: httpbin.default.svc.cluster.local:8000/*
170+
```
171+
172+
## Understanding What Happened
173+
174+
When you make a request to `kmesh-fake.com`:
175+
176+
1. **Service Entry** tells Istio this is a valid service destination
177+
2. **VirtualService** redirects requests to that host to the cluster-internal `httpbin` service
178+
3. Kmesh handles this routing rule, forwarding traffic to the correct destination
179+
180+
This demonstrates how to use Service Entry to:
181+
182+
- Define external services
183+
- Redirect traffic to internal services
184+
- Control outbound traffic routing
185+
186+
## Advanced Use Cases
187+
188+
### Configure Real External Services
189+
190+
You can also configure access to real external services. For example:
191+
192+
```bash
193+
kubectl apply -f - <<EOF
194+
apiVersion: networking.istio.io/v1alpha3
195+
kind: ServiceEntry
196+
metadata:
197+
name: external-httpbin
198+
spec:
199+
hosts:
200+
- httpbin.org
201+
ports:
202+
- number: 80
203+
name: http
204+
protocol: HTTP
205+
- number: 443
206+
name: https
207+
protocol: HTTPS
208+
resolution: DNS
209+
EOF
210+
```
211+
212+
Test external service access:
213+
214+
```bash
215+
kubectl exec deploy/sleep -- curl -s http://httpbin.org/headers
216+
```
217+
218+
## Cleanup
219+
220+
Delete the created Service Entry and VirtualService:
221+
222+
```bash
223+
kubectl delete serviceentry external-fake-svc
224+
kubectl delete virtualservice fake-service-route
225+
kubectl delete serviceentry external-httpbin
226+
```
227+
228+
If you're not planning to explore any follow-up tasks, refer to the [Install Waypoint/Cleanup](/docs/application-layer/install_waypoint.md#cleanup) instructions to remove the waypoint and shut down the application.

0 commit comments

Comments
 (0)