Accessing micro service end point from deployed micro service using Kubernetes orchestration

4/24/2018

I am trying to deploy my sample micro service Docker image in Kubernetes cluster having 2 node. I explored everything about Pods, Services, Deployment, StatefulSets and Daemon-sets etc.

I am trying to create a sample deployment and Service for that. Here I explored about how deployment provides the scalability and load balancing functionality. And exploring about service discovery by providing Services ClusterIp.

I have two questions:

My scenario is that I am trying to deploy microservice on my on-premise Ubuntu machine. The machine has the IP address of 192.168.1.15. When I am referring Kubernetes, service will also have one clusterIP.

  1. If my microservice end point is /api/v1/loadCustomer, how I can call this end point? Do I need to use clusterIP also ? Can I call simply 192.168.1.15:8080/api/v1/loadCustomers ?

  2. What is the role of clusterIP when I am calling my end point ? Can I directly use port?

I am referring to the following link for exploration:

https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/

-- Jacob
kubernetes

1 Answer

4/24/2018

tldr:

you can not access the application using the clusterIP from the outside of the cluster. you can access the application using either loadbalancer's IP (type=LoadBalaner) or Node's IP (type=NodePort).

benefit of clusterIP: As you know that pods can be created and terminated during its life-cycle consequently IP (endpoint IP)address created and terminated.Therefore, clusterIP is static which does not depends of the life-cycle of the pods.

Long Answer

In a Kubernetes cluster an application or pod has following abstraction.

Endpoint IP and Port:It is provided by the CNI Plugins such as flannel, calico.

  • Each pod has an IP and tragetPort which is UNIQUE.

you can list and watch the endpoints by the following commands.

kubectl get endpoints --all-namespaces 

clusterIP and port : It is provided by the kube-proxy component.

  • The replicated pods share a clusterIP and Port.

  • Load-balancing of request to the replicated pods.

  • internally expose so that other pod can discover it

you can list and watch clusterIP and port with the following command

kubectl get services --all-namespaces 

externalIP and port: It can be layer 3-4 load balancer's IP and port or node's IP and Nodeport.

if you want to use loadbalancer's IP and port, you can use type=LoadBalaner in service file.

If you want to use node's IP, you need to use type=NodePort in service file.

-- Suresh Vishnoi
Source: StackOverflow