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