11 Exposing Pods with Services

 

This chapter covers

  • Communication between pods
  • Distributing client connections over a group of pods providing the same service
  • Discovering services in the cluster through DNS and environment variables
  • Exposing services to clients outside the cluster
  • Using readiness probes to add or remove individual pods from services

Instead of running a single pod to provide a particular service, people nowadays typically run several replicas of the pod so that the load can be distributed across multiple cluster nodes. But that means all pod replicas providing the same service should be reachable at a single address so clients can use that single address, rather than having to keep track of and connect directly to individual pod instances. In Kubernetes, you do that with Service objects.

The Kiada suite you’re building in this book consists of three services - the Kiada service, the Quiz service, and the Quote service. So far, these are three isolated services that you interact with individually, but the plan is to connect them, as shown in the following figure.

Figure 11.1 The architecture and operation of the Kiada suite.

The Kiada service will call the other two services and integrate the information they return into the response it sends to the client. Multiple pod replicas will provide each service, so you’ll need to use Service objects to expose them.

11.1 Exposing pods via services

11.1.1 Introducing services

11.1.2 Creating and updating services

11.1.3 Accessing cluster-internal services

11.2 Exposing services externally

11.2.1 Exposing pods through a NodePort service

11.2.2 Exposing a service through an external load balancer

11.2.3 Configuring the external traffic policy for a service

11.3 Managing service endpoints

11.3.1 Introducing the Endpoints object

11.3.2 Introducing the EndpointSlice object

11.3.3 Managing service endpoints manually

11.4 Understanding DNS records for Service objects

11.4.1 Inspecting a service’s A and SRV records in DNS

11.4.2 Using headless services to connect to pods directly

11.4.3 Creating a CNAME alias for an existing service

11.5 Configuring services to route traffic to nearby endpoints

11.5.1 Forwarding traffic only within the same node with internalTrafficPolicy

sitemap