Running using a service IP address

You can access a microservice through its dynamic IP address. This can change if the microservice is scheduled to another node:

  1. The pod's IP address is linked to the service IP address, which is constant throughout its lifetime:
$ kubectl -n istio-lab get svc -o custom-columns=NAME:.metadata.name,CLUSTER_IP:.spec.clusterIP
NAME CLUSTER_IP
details 10.106.179.233
productpage 10.100.221.255
ratings 10.109.32.8
reviews 10.107.73.66

In the preceding code, the productpage service IP address is 10.100.221.255. The IP might be different in your output.

  1. You can test this productpage service using the curl command. Substitute the service IP address as per your output:
$ PRODUCTPAGE_IP=$(kubectl -n istio-lab get svc -l app=productpage -o jsonpath='{.items...spec.clusterIP}') ; echo $PRODUCTPAGE_IP
10.100.221.255
$ curl -s http://$PRODUCTPAGE_IP:9080 | grep title
<title>Simple Bookstore App</title>

Note that the service IP address remains the same during its lifetime and may change if the service is dropped and recreated.

Accessing a service by its name is preferred as the Kubernetes DNS server will translate the name in to the proper IP address.

  1. The connection between a pod's IP address and service IP address is done through endpoints:
$ kubectl -n istio-lab get ep productpage
NAME ENDPOINTS AGE
productpage 10.142.230.241:9080 89m

Notice that the productpage service endpoint is 10.142.230.241, which is the pod's IP address. This IP address will be different in your case since it is ephemeral and may change when a service is deleted and recreated.

  1. Check the IP address of the internal service name:
$ dig +short productpage.istio-lab.svc.cluster.local @10.96.0.10
10.100.221.255

This IP address, 10.100.221.255, is the IP address of the FQDN of the service name. The IP address might be different in your case.

  1. Open a browser from inside the VM and try http://10.100.221.255:9080 to view the product page. Replace the IP address as per the output in your VM environment. 

We'll learn how to run a Node Port in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.56.45