This guide demonstrates how to install Istio, lock down egress so that pods can only reach registered destinations, and use ServiceEntry + WorkloadEntry to allow pods to access an external (or external-looking) workload. Prerequisites: a running Kubernetes cluster andDocumentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
kubectl access.
1) Verify Kubernetes is running
List pods across all namespaces to confirm the cluster is healthy:2) Download Istio and configure the demo profile
Download Istio (example uses v1.18.2) and addistioctl to your PATH:
demo profile to YAML, edit the mesh config to restrict egress, then install:
demo.yaml change the meshConfig section so egress is locked to registered destinations:
Setting
outboundTrafficPolicy.mode to REGISTRY_ONLY ensures pods can only reach destinations that are explicitly registered in Istio using ServiceEntry and/or WorkloadEntry. This is the recommended method to lock down egress in an Istio mesh.3) Prepare a simulated external nginx service (host-based)
For this demo we simulate an external workload by installingnginx on the control-plane host (outside the cluster). In production, this would be an external VM or host.
On the host (not in Kubernetes):
weave interface and note its inet address, e.g. 10.50.0.1. Test that this IP responds from the host:
10.50.0.1) — it will be used in the WorkloadEntry.
4) Create a test pod in Kubernetes and enable Istio injection
Start a test pod that will attempt to access the external address:REGISTRY_ONLY, direct IP access will be blocked until the destination is registered:
502 Bad Gateway for unregistered destinations when REGISTRY_ONLY is enabled.
If you enable namespace injection, you must recreate pods in that namespace for the sidecar to be injected. Deleting and recreating the pod is the simplest approach.
5) Register the external host as a WorkloadEntry
Create a WorkloadEntry to represent the external nginx host. Save this aswe.yaml:
6) Create a ServiceEntry to expose an internal hostname
Create a ServiceEntry that maps an internal hostname used by applications to the registered WorkloadEntry. Save asse.yaml:
resolution: STATIC is used because the ServiceEntry maps to explicit workloads (via WorkloadEntry or static endpoints).
7) Test access from the test pod using the internal hostname
From the test pod, curl the hostname declared in the ServiceEntry:app.internal.com (ServiceEntry) and routes to the WorkloadEntry address.
8) Add an in-cluster pod behind the same WorkloadEntry for load balancing
You can include in-cluster pods as additional endpoints for the same logical service by sharing the label referenced by theworkloadSelector. Istio will treat both the external IP and in-cluster pod(s) as endpoints for the hostname.
Create a labeled nginx pod:
workloadSelector, Istio will load-balance between them. Use Istio traffic-management features (VirtualService, DestinationRule) to control traffic weights and routing as needed.
9) WorkloadEntry and ServiceEntry quick reference
Key fields to remember:| Resource Type | Important fields | Notes / Example |
|---|---|---|
| WorkloadEntry | address, labels, serviceAccount, network, locality, weight | Example: address: 10.50.0.1 and labels: { app: external } |
| ServiceEntry | hosts, ports, resolution (STATIC, DNS), location, workloadSelector | Use resolution: STATIC with WorkloadEntry; hosts lists the hostname apps will use |
