From point A to point B
Point A: you know the cluster network, and you know that a Service gives a group of pods a stable address. Point B: by the end of this chapter you'll master the Service types, and you'll understand why applications get split into microservices and what problem a service mesh like Istio solves.
This topic is part of the Container Orchestration domain (28% of the KCNA exam), which explicitly mentions the service mesh.
Service types in depth
In chapter 2 you saw what a Service is for. Now it's time to see how its three main types are built, because each one builds on the one before:
- ClusterIP (the default type): a virtual IP that only exists inside the cluster. It's for internal communication, for example from a frontend to its API.
- NodePort: on top of the ClusterIP, it opens the same port on every node, in the 30000-32767 range. You can reach it from outside with
node-IP:port. - LoadBalancer: on top of the NodePort, it asks the cloud provider for a load balancer with a public IP that spreads traffic across the nodes. It needs a provider that supports it, or a solution like MetalLB on your own servers.
Each Service type wraps the one before it. Diagram: The House of Routing.
The YAML has three ports that are easy to mix up:
apiVersion: v1
kind: Service
metadata:
name: web
spec:
type: NodePort
selector:
app: web
ports:
- port: 80 # the Service's own port (ClusterIP:80)
targetPort: 8080 # the port the container listens on
nodePort: 30080 # the port opened on every node (30000-32767)
| Field | Where it lives | Required |
|---|---|---|
port | On the Service itself | Yes |
targetPort | On the container | No: if it's missing, it takes the same value as port |
nodePort | On every node | No: if it's missing, Kubernetes picks a free one from the range |
The Service finds its pods with the selector, and Kubernetes stores the list of those pods' IPs in EndpointSlice objects, which update on their own as pods come and go.
kubectl expose deployment web --type=NodePort --port=80 --target-port=8080
kubectl get svc web
kubectl get endpointslices -l kubernetes.io/service-name=web
curl http://<node-ip>:30080
ExternalName and headless Services
There are two lesser-known variants that can also show up on the exam:
ExternalName doesn't point to pods, but to a DNS name outside the cluster. Pods call db, and the cluster DNS answers with db.example.com. It's useful, for example, for a managed cloud database that you might one day move into the cluster without touching your applications.
apiVersion: v1
kind: Service
metadata:
name: db
spec:
type: ExternalName
externalName: db.example.com # pods call "db", DNS answers with this name
A headless Service (clusterIP: None) has no virtual IP and no load balancing. Its DNS name returns each pod's IP directly. Distributed databases and StatefulSets use it, because each replica has its own identity and the client needs to talk to a specific one.
apiVersion: v1
kind: Service
metadata:
name: cassandra
spec:
clusterIP: None # headless: DNS returns the IP of every pod
selector:
app: cassandra
ports:
- port: 9042
From monolith to microservices
A monolithic application holds everything in a single process: users, catalog, payments and orders, with a shared database. It's simple at first, but over the years it tends to become what's called a big ball of mud: everything depends on everything, any change means redeploying the whole application, and a failure in one part can bring it all down.
With microservices, each function is a small service with its own data, deployed, scaled and failing on its own. Kubernetes fits this model very well: each microservice is a Deployment with its Service.
The monolith deploys everything together; microservices deploy separately. Diagram: The House of Routing.
The price is that calls that used to be internal now travel over the network. And the network fails, is slow and can be snooped on. Every team ends up coding the same things: retries, timeouts, encryption, metrics and traces. That's where sidecars and the service mesh come in.
The sidecar pattern
A sidecar is an extra container that lives in the same pod as the main container and adds a supporting function: a proxy, log shipping or metrics collection. Since they share the pod's network and can share volumes, the sidecar helps without the application having to change.
The sidecar shares the network and a volume with the application. Diagram: The House of Routing.
Since Kubernetes 1.33, sidecars are native: you declare them in initContainers with restartPolicy: Always. That way they start before the application, keep running while it lives and stop after it.
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
initContainers:
- name: log-shipper # native sidecar (Kubernetes 1.33+)
image: fluent/fluent-bit:3.1
restartPolicy: Always # starts first and keeps running
volumeMounts:
- name: logs
mountPath: /var/log/app
containers:
- name: app # the main container
image: nginx:1.27-alpine
volumeMounts:
- name: logs
mountPath: /var/log/nginx
volumes:
- name: logs
emptyDir: {}
Envoy
Envoy is a high-performance proxy created at Lyft and now a CNCF graduated project. It's the most common sidecar in service meshes because it handles, outside the application, everything that isn't business logic:
- Load balancing, retries, timeouts and circuit breaking (cutting off traffic to a service that's failing).
- TLS and mutual TLS encryption between services.
- Metrics, logs and traces for every request.
- Dynamic configuration: a control plane reprograms it on the fly, without a restart.
The key idea is separation of concerns: the code takes care of the business, and the proxy takes care of communication.
What a service mesh is
When you have many microservices and each one has a proxy next to it that handles communication, you have a service mesh. It has two parts:
- Data plane: the proxies, one next to each service. All the real traffic goes through them.
- Control plane: the brain. It doesn't touch the traffic; it configures the proxies, tells them where each service is and hands out the certificates.
| Responsibility | What the mesh does |
|---|---|
| Security | Encrypts traffic between services with mutual TLS and controls who can call whom |
| Traffic management | Retries, timeouts, canary deployments and A/B testing |
| Observability | Metrics, logs and traces for every call, without touching the code |
| Resilience | Circuit breaking and fault injection to test how the system reacts |
Istio
Istio is a free, open source service mesh and a CNCF graduated project. It uses Envoy as its proxy.
At first, its control plane had three separate services: Pilot for service discovery and traffic configuration, Citadel to generate certificates and Galley to validate configuration. Since version 1.5, the three were merged into a single component: istiod.
istiod configures the Envoy proxies, and the proxies encrypt traffic between services. Diagram: The House of Routing.
In the data plane, each pod gets an Envoy sidecar and a small agent (pilot-agent) that starts it and hands it the certificates. Istio also offers ambient mode, stable since version 1.24, which drops the sidecars: one proxy per node (ztunnel) handles encryption, and layer 7 proxies (waypoints) are only added where they're needed.
Istio in practice
You install Istio with its istioctl tool or with Helm. Then you just label a namespace so Istio injects the sidecar into every new pod. The Bookinfo sample application ships with Istio and is the classic way to try it:
istioctl install --set profile=default -y
kubectl get pods -n istio-system # istiod and the ingress gateway
kubectl label namespace default istio-injection=enabled
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl get pods # READY 2/2: app + Envoy sidecar
istioctl analyze # checks the mesh configuration
Look at the READY column: each pod shows 2/2, the application and its Envoy. With everything running, a few lines of YAML are enough to require mutual TLS across the whole mesh:
apiVersion: security.istio.io/v1
kind: PeerAuthentication
metadata:
name: default
namespace: istio-system # applies to the whole mesh
spec:
mtls:
mode: STRICT # only encrypted, authenticated traffic
Or for a canary deployment, sending 10% of the traffic to the new version of a service:
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
name: reviews
spec:
host: reviews
subsets:
- name: v1
labels: { version: v1 }
- name: v2
labels: { version: v2 }
---
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: reviews
spec:
hosts: ["reviews"]
http:
- route:
- destination: { host: reviews, subset: v1 }
weight: 90
- destination: { host: reviews, subset: v2 }
weight: 10 # 10% of the traffic tries the new version
KCNA-style challenge
Answer before you open the solution. Getting it wrong here is the cheapest way to learn.
1. What is the default Service type?
ClusterIP. It's only reachable from inside the cluster.
2. A NodePort Service doesn't set targetPort. Which container port does it send traffic to?
The same value as port. If targetPort isn't set, it takes the value of port.
3. Which Service returns each pod's IP in DNS instead of a virtual IP?
A headless Service, with clusterIP: None.
4. In a service mesh, where does traffic between services flow?
Through the data plane, that is, through the proxies. The control plane only configures them.
5. Which Istio component brings together Pilot, Citadel and Galley?
istiod, since version 1.5.
Key takeaways
- ClusterIP is internal; NodePort opens a port on every node; LoadBalancer asks the cloud provider for a load balancer.
- port belongs to the Service, targetPort to the container and nodePort to each node.
- ExternalName points to an outside name; a headless Service returns the pods' IPs.
- Microservices deploy and scale separately, but they turn internal calls into network calls.
- A sidecar is a supporting container in the same pod; since version 1.33 they're native.
- A service mesh has a data plane (the proxies, such as Envoy) and a control plane that configures them.
- Istio uses Envoy, its control plane is istiod, and it also offers an ambient mode without sidecars.
In the next chapter you move on to storage: volumes, PersistentVolumes, PersistentVolumeClaims and StorageClasses.
Official resources
- Servicekubernetes.io
- EndpointSliceskubernetes.io
- Sidecar Containerskubernetes.io
- Envoy Proxyenvoyproxy.io
- What is Istio?istio.io
- Istio Architectureistio.io
- Istio: Getting Startedistio.io
- Istio Ambient Modeistio.io
- Linkerdlinkerd.io
- Kubernetes and Cloud Native Associate (KCNA)cncf.io
Source and credits. Chapter written from Jesús Espinoza's study notes on KodeKloud's KCNA course (January to April 2026). Text drafted with AI assistance; original diagrams by The House of Routing. Technical details and YAML examples were checked against the official Kubernetes, Envoy, Istio and CNCF documentation.