Clurgo logo
  • Clurgo
  • Blog
  • Why exposing Services in Kubernetes (k8s)

Why exposing Services in Kubernetes (k8s)

1/15/2020 

Share

Service

You can consider Service object as your load balancer. In fact it creates a invariable virtual IP (service type None is an exception), then based on that IP, DNS record (Core DNS component in cluster) is created. By default load balancing is done in random manner.

We can distinguish the following service types:

  • ClusterIp – Most commonly used. The service is reachable only inside kubernetes cluster.
  • NodePort – Exposes the service on each node on static port
  • Load Balancer – Exposes service using cloud provider load balancer (Additional costs will be added). This is the way, how the external calls can be handled, but the cheaper and more handy way is to use Ingress Controller (described in next section)
  • ExternalName – return CNAME record

Sometimes there is no need to load balancing your service. In that case you can create headless service by setting .spec.ClusterIP to None. Additional hop will not be introduced. The most common usage of the last is along with Statefulsets, when you need to deal with each replica separately.

Ingress Controller

It’s an abstract component that should be responsible for handling external call to your application. The most commonly used implementation is NGINX Ingress Controller.
It acts as a reverse proxy in our infrastructure, mapping incoming request to kubernetes services. All configurations are done by appropriate annotations in object definition (yaml configuration).
This is also the place where ssl termination should take place (be aware that Nginix Ingress Controller pass through option is disabled by default). Mutual SSL can be achieved as well.
To sum up:

  • Use Cluster Ip whenever possible
  • Use headless services when there is no load balancing needed
  • Use Ingress Controller to expose your services to the public
  • Terminate your ssl on Ingress Controller
Clurgo logo

Subscribe to our newsletter

© 2014 - 2024 All rights reserved.