Kubernetes - Services

  • We’ve spun up pods and connected to them individually, but that’s frankly not super useful if we want to distribute real traffic across those pods. That’s where services come in.

  • Services provide a stable endpoint for pods. They are an abstraction used to provide a stable endpoint and load balance traffic across a group of Pods. By “stable endpoint”, I just mean that the service will always be available at a given URL, even if the pod is destroyed and recreated.

Service Type

  • There are four types of services in Kubernetes:

    • ClusterIP
    • NodePort
    • LoadBalancer
    • ExternalName
  • ClusterIP: Exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable from within the cluster. This is the default ServiceType.

  • NodePort: Exposes the service on each Node’s IP at a static port (the NodePort). A ClusterIP service, to which the NodePort service will route, is automatically created. You’ll be able to contact the NodePort service, from outside the cluster, by requesting NodeIP:NodePort.

  • LoadBalancer: Exposes the service externally using a cloud provider’s load balancer. NodePort and ClusterIP services, to which the external load balancer will route, are automatically created.

  • ExternalName: Maps the service to the contents of the externalName field (e.g. foo.bar.example.com), by returning a CNAME record with its value. No proxying of any kind is set up.

Ingress

  • Ingress is an API object that manages external access to services in a cluster, typically HTTP. Ingress may provide load balancing, SSL termination and name-based virtual hosting.
  • Ingress is not a service type, but it acts as the entry point for your cluster. It lets you consolidate your routing rules into a single resource, rather than having to manage each service’s route individually.
  • Ingress is a layer 7 (HTTP) load balancer, whereas services are layer 4 (TCP/UDP) load balancers.
  • Ingress is a collection of rules that allow inbound connections to reach the cluster services. It can be configured to give services externally-reachable URLs, load balance traffic, terminate SSL, offer name-based virtual hosting, and more.

Note

  • Host multiple services on the same IP address
  • Host multiple services on the same port (path-based routing)
  • Terminate SSL
  • Integrate directly with external DNS and load balancers