Wednesday, 6 May 2020

Accessing Kubernetes Services

A service is an abstraction that defines a logic set of pods, and an access policy for it.


How to discover services inside and outside the cluster?

For each service insiede a Kubernetes namespace, two environment variables are automatically created and injected into all the containers contained in pod of the same namespace:

<SERVICE_NAME>_SERVICE_HOST for the service ip address
<SERVICE_NAME>_SERVICE_PORT for the service TCP port

Another way to access a service is to use its FQDN, that have the form: <SERVICE_NAME>.NAMESPACE.SVC.CLUSTER.LOCAL



And if we need to access services from an application outside the cluster?

In this case we have two ways:

  • Use a service of type NodePort: in this case, the same port (in a range between 30000 - 32767) is opened on all the nodes of the clusters, and the external application can access the service connecting to the node ip address and that port. Then the connection is proxied to the service.
  • Use an ingress: this is the best way if you want to do an advanced configuration, using TLS terminations, HTTP/HTTPS and layer 7 path based routing.

If you want a complete example with the creation of an Ingress resource, you can refer to our guide: https://pillsfromtheweb.blogspot.com/2020/05/deploy-nodejs-app-on-kuberntes.html

And here, we leave you our note about this post :)


No comments:

Post a Comment