liveBook · Manning

Chapter 11: Exposing pods with services

What you will learn in chapter 11 of Kubernetes in Action, Second Edition

The chapter introduces Services as a single address for replicated pods and explains the network model that lets pods communicate directly.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces Services as a single address for replicated pods and explains the network model that lets pods communicate directly.

Key terms: Service objects, pod replicas, pod network, flat address space, SNAT, DNAT

11.1 Exposing pods via services

This section explains why changing pod IP addresses and multiple replicas make direct pod addressing impractical, and why Services are used to expose pods.

Key terms: pods are ephemeral, pod IP address, pod replicas, load balancer, port forwarding, Kubernetes Service, clients outside the cluster

11.1.1 Introducing services

This section explains how Services provide stable access to changing pods and how label selectors determine which pods back a Service.

Key terms: Service, stable IP address, backing pods, load balancer, Pod labels, label selector, app=quote, stable, canary

11.1.2 Creating and updating services

This section shows how to create, inspect, and update Services for pods, including their selectors, ports, and IP-family settings.

Key terms: ClusterIP, Service, cluster IP address, Service manifest, label selector, port, targetPort, kubectl apply, kubectl expose, kubectl get services -o wide

11.1.3 Accessing cluster-internal services

This section shows how pods reach ClusterIP services, how services distribute connections, and how pods discover service addresses.

Key terms: ClusterIP, kubectl exec, QUIZ_URL, QUOTE_URL, load balancer, sessionAffinity, None, ClientIP, timeoutSeconds, cluster DNS

11.2 Exposing services externally

The section explains why ClusterIP alone cannot expose the Kiada service outside the cluster and compares four ways to make a service externally reachable.

Key terms: ClusterIP, Kiada service, spec.externalIPs, Service object, NodePort, node port, LoadBalancer, cluster IP, Ingress object, ingress controller

11.2.1 Exposing pods through a NodePort service

This section explains how a NodePort service exposes selected pods through a port on every cluster node and how to find and test those access points.

Key terms: NodePort service, node port, cluster IP, selector, NodePort, kubectl get nodes -o wide, INTERNAL-IP, EXTERNAL-IP, Client IP, node

11.2.2 Exposing a service through an external load balancer

This section explains how a LoadBalancer service exposes an application through an external load balancer, how to create one, and what to expect while it is provisioned.

Key terms: LoadBalancer service, NodePort, node port, healthy nodes, type: LoadBalancer, kubectl apply, internal cluster IP, EXTERNAL-IP, <pending>, node ports

11.2.3 Configuring the external traffic policy for a service

This section explains the tradeoffs between Cluster and Local external traffic policies for NodePort and LoadBalancer services.

Key terms: Cluster, network hop, source IP, externalTrafficPolicy, Local, healthCheckNodePort, endpoints

11.3 Managing service endpoints

This section introduces the idea that service endpoints need not be pods.

Key terms: services, endpoints, IP address

11.3.1 Introducing the Endpoints object

This section explains where a Service’s endpoint addresses are stored, how to inspect them, and how Kubernetes keeps them up to date.

Key terms: Service object, Endpoints object, kubectl describe, addresses array, endpoint subset, ports, label selector, endpoint

11.3.2 Introducing the EndpointSlice object

This section explains why Kubernetes uses EndpointSlice objects and how to find and inspect the slices associated with a Service.

Key terms: Endpoints object, EndpointSlice object, endpoints, endpoint subsets, EndpointSlice, ports, kubectl get endpointslices, kubernetes.io/service-name, kubectl describe, endpoint addresses

11.3.3 Managing service endpoints manually

This section explains how to configure a Service’s endpoints by hand and switch between manual and selector-managed endpoints without changing the Service’s address.

Key terms: Service, label selector, Endpoints object, EndpointSlice, cluster IP, cluster DNS, selector, cluster IP address

11.4 Understanding DNS records for Service objects

Introduces the DNS records Kubernetes creates for Services and a temporary pod for inspecting them.

Key terms: cluster DNS, A record, AAAA record, SRV record, internal cluster IP address, one-off pod, giantswarm/tiny-tools, host, nslookup, dig

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

Shows how to inspect a Service’s DNS A and SRV records to find its cluster IP and advertised ports.

Key terms: A record, nslookup, cluster IP, LoadBalancer, SRV record, named ports, Service object

11.4.2 Using headless services to connect to pods directly

This section explains how headless Services expose endpoint IP addresses through DNS so clients can connect directly to pods rather than through a Service cluster IP.

Key terms: headless service, clusterIP, None, A record, label selector, AAAA record, FQDN, pod IP, cluster IP, A/AAAA record

11.4.3 Creating a CNAME alias for an existing service

This section explains how an ExternalName Service creates a DNS alias for another service and how pods use that alias.

Key terms: CNAME record, ExternalName, Endpoints, EndpointSlice, cluster IP, time-api.<namespace>.svc.cluster.local

11.5 Configuring services to route traffic to nearby endpoints

This section explains two reasons a service might route traffic to nearby endpoints: reducing cross-zone or cross-region costs and reaching endpoints that work only in the caller’s node-local context.

Key terms: availability zones, regions, services, pods, service endpoints, same node, node-local endpoints

11.5.1 Forwarding traffic only within the same node with internalTrafficPolicy

This section shows how a Service can restrict internal traffic to endpoints on the client pod’s node and how to observe that behavior.

Key terms: internalTrafficPolicy, Local, node-local service endpoints, quote-local, -o wide, curl, kiada pods, quote pods

11.5.2 Topology-aware hints

This section explains how topology-aware hints steer Service traffic toward endpoints in suitable zones, how Kubernetes assigns those hints, and how nodes use them.

Key terms: topology-aware traffic routing, zone, kubernetes.io/zone, service.kubernetes.io/topology-aware-hints, Auto, EndpointSlice, forZones, EndpointSlice controller, cluster IP, topology-aware hints

11.6 Managing the inclusion of a pod in service endpoints

This section explains why a pod whose labels match a Service should not necessarily receive traffic as soon as it appears.

Key terms: service, endpoint, label selector, ready

11.6.1 Introducing readiness probes

This section explains how readiness probes determine whether a pod receives service traffic, how applications can signal readiness, and how probe execution is configured.

Key terms: Kubelet, readiness probe, liveness probe, endpoint, label selector, exec probe, httpGet probe, tcpSocket probe, exit code, response code

11.6.2 Adding a readiness probe to a pod

This section uses a file-based readiness probe to show how a pod becomes ready or unready and how that changes its inclusion in a Service.

Key terms: readiness probe, ls /var/ready, success, ready, READY column, Endpoints, EndpointSlice, notReadyAddresses, ready condition, active endpoint

11.6.3 Implementing real-world readiness probes

This section explains how to make readiness probes reflect an application's ability to serve requests without letting transient dependency failures unnecessarily remove pods from service.

Key terms: readiness probe, service endpoint, GET /, Quote pod, /quote, quote-writer, dedicated readiness endpoint, /healthz/ready, Quiz pod, MongoDB

11.7 Summary

The section recaps how Services provide stable access to pods, how clients find them and endpoints are chosen, and how traffic routing can account for locality and readiness.

Where this is used later

Concepts explained in this chapter

← Chapter 10: Persisting data with PersistentVolumes Chapter 12: Using Ingress to route traffic to services →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.