Kubernetes Services for Egress Traffic
Kubernetes ExternalName
services and Kubernetes services with
Endpoints
let you create a local DNS alias to an external service.
This DNS alias has the same form as the DNS entries for local services, namely
<service name>.<namespace name>.svc.cluster.local
. DNS aliases provide location transparency for your workloads:
the workloads can call local and external services in the same way. If at some point in time you decide to deploy the
external service inside your cluster, you can just update its Kubernetes service to reference the local version. The workloads will continue to operate without any change.
This task shows that these Kubernetes mechanisms for accessing external services continue to work with Istio. The only configuration step you must perform is to use a TLS mode other than Istio’s mutual TLS. The external services are not part of an Istio service mesh so they cannot perform the mutual TLS of Istio. You must set the TLS mode according to the TLS requirements of the external service and according to the way your workload accesses the external service. If your workload issues plain HTTP requests and the external service requires TLS, you may want to perform TLS origination by Istio. If your workload already uses TLS, the traffic is already encrypted and you can just disable Istio’s mutual TLS.
While the examples in this task use HTTP protocols, Kubernetes Services for egress traffic work with other protocols as well.
Before you begin
Setup Istio by following the instructions in the Installation guide7.
Deploy the curl9 sample app to use as a test source for sending requests. If you have automatic sidecar injection enabled, run the following command to deploy the sample app:
Otherwise, manually inject the sidecar before deploying the
curl
application with the following command:Set the
SOURCE_POD
environment variable to the name of your source pod:
Create a namespace for a source pod without Istio control:
Start the curl9 sample in the
without-istio
namespace.To send requests, create the
SOURCE_POD_WITHOUT_ISTIO
environment variable to store the name of the source pod:Verify that the Istio sidecar was not injected, that is the pod has one container:
Kubernetes ExternalName service to access an external service
Create a Kubernetes ExternalName service for
httpbin.org
in the default namespace:Observe your service. Note that it does not have a cluster IP.
Access
httpbin.org
via the Kubernetes service’s hostname from the source pod without Istio sidecar. Note that the curl command below uses the Kubernetes DNS format for services:<service name>.<namespace>.svc.cluster.local
.In this example, unencrypted HTTP requests are sent to
httpbin.org
. For the sake of the example only, you disable the TLS mode and allow the unencrypted traffic to the external service. In the real life scenarios, we recommend to perform Egress TLS origination11 by Istio.Access
httpbin.org
via the Kubernetes service’s hostname from the source pod with Istio sidecar. Notice the headers added by Istio sidecar, for exampleX-Envoy-Peer-Metadata
. Also note that theHost
header equals to your service’s hostname.
Cleanup of Kubernetes ExternalName service
Use a Kubernetes service with endpoints to access an external service
Create a Kubernetes service without selector for Wikipedia:
Create endpoints for your service. Pick a couple of IPs from the Wikipedia ranges list12.
Observe your service. Note that it has a cluster IP which you can use to access
wikipedia.org
.Send HTTPS requests to
wikipedia.org
by your Kubernetes service’s cluster IP from the source pod without Istio sidecar. Use the--resolve
option ofcurl
to accesswikipedia.org
by the cluster IP:In this case, the workload send HTTPS requests (open TLS connection) to the
wikipedia.org
. The traffic is already encrypted by the workload so you can safely disable Istio’s mutual TLS:Access
wikipedia.org
by your Kubernetes service’s cluster IP from the source pod with Istio sidecar:Check that the access is indeed performed by the cluster IP. Notice the sentence
Connected to en.wikipedia.org (172.21.156.230)
in the output ofcurl -v
, it mentions the IP that was printed in the output of your service as the cluster IP.