teluzia.Cloud Engineer · Day 114
CHAPTER 17 · KUBERNETES FUNDAMENTALS

Deployments and services

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

A Deployment keeps the desired number of workers available; a Service is the stable reception address that routes to ready matching workers. A Deployment manages updates to Pod templates and replica counts through ReplicaSets. Controllers replace lost Pods to maintain desired state. Pod names are not stable application interfaces. Review selectors and template labels together because they identify which Pods belong to the workload. A Service provides stable discovery and routes toward matching endpoints. Selectors match Pod labels; port is the service-facing port and targetPort is the backend container port. A Service with no ready matching endpoints cannot deliver traffic even if its YAML is valid.

Think of it this way

A Deployment keeps the desired number of workers available; a Service is the stable reception address that routes to ready matching workers.

TOPIC 01 / 03Step by step

Deployments and ReplicaSets

A Deployment manages updates to Pod templates and replica counts through ReplicaSets. Controllers replace lost Pods to maintain desired state. Pod names are not stable application interfaces. Review selectors and template labels together because they identify which Pods belong to the workload. For example, a Deployment requests two nginx replicas; deleting one Pod causes the controller to create another replacement.

WORKED EXAMPLE
A Deployment requests two nginx replicas; deleting one Pod causes the controller to create another replacement.

A Deployment declares three replicas of an application Pod template. Its controller manages a ReplicaSet that maintains the desired count. When one Pod disappears, reconciliation creates a replacement rather than preserve that Pod's name. Updating the template creates a new rollout managed according to the Deployment strategy.

A Deployment coordinates desired workload updates. A ReplicaSet maintains a matching replica count. A Pod template supplies configuration for new Pods. Selector and template labels must agree so ownership is correct. Scaling replica count changes the number of desired Pods, not the capacity of the database or available nodes. Unscheduled replacements can leave the application below its availability objective. Inspect desired, updated, ready, and available counts separately. The controller helps maintain the declared structure, but readiness checks and sufficient capacity determine whether replacements actually serve useful traffic instead of merely exist as accepted objects.

Why this matters

A Deployment requests two nginx replicas; deleting one Pod causes the controller to create another replacement.

A common trap

Do not overlook this operational distinction: Review selectors and template labels together because they identify which Pods belong to the workload.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Deployments and ReplicaSets

A Deployment manages updates to Pod templates and replica counts through ReplicaSets. Controllers replace lost Pods to maintain desired state. Pod names are not stable application interfaces. Review selectors and template labels together because they identify which Pods belong to the workload. For example, a Deployment requests two nginx replicas; deleting one Pod causes the controller to create another replacement.

WORKED EXAMPLE
A Deployment requests two nginx replicas; deleting one Pod causes the controller to create another replacement.

A Deployment declares three replicas of an application Pod template. Its controller manages a ReplicaSet that maintains the desired count. When one Pod disappears, reconciliation creates a replacement rather than preserve that Pod's name. Updating the template creates a new rollout managed according to the Deployment strategy.

A Deployment coordinates desired workload updates. A ReplicaSet maintains a matching replica count. A Pod template supplies configuration for new Pods. Selector and template labels must agree so ownership is correct. Scaling replica count changes the number of desired Pods, not the capacity of the database or available nodes. Unscheduled replacements can leave the application below its availability objective. Inspect desired, updated, ready, and available counts separately. The controller helps maintain the declared structure, but readiness checks and sufficient capacity determine whether replacements actually serve useful traffic instead of merely exist as accepted objects.

Why this matters

A Deployment requests two nginx replicas; deleting one Pod causes the controller to create another replacement.

A common trap

Do not overlook this operational distinction: Review selectors and template labels together because they identify which Pods belong to the workload.

Service selectors and ports

A Service provides stable discovery and routes toward matching endpoints. Selectors match Pod labels; port is the service-facing port and targetPort is the backend container port. A Service with no ready matching endpoints cannot deliver traffic even if its YAML is valid. For example, a Service port 80 targets container port 8080, with selector app: orders matching the Deployment’s Pod labels.

WORKED EXAMPLE
A Service port 80 targets container port 8080, with selector app: orders matching the Deployment’s Pod labels.

A client reaches Service port 80. The Service selects Pods carrying the intended label and forwards through the relevant endpoint mechanism to targetPort 8080. If labels do not match, the Service can exist with no suitable endpoints. If targetPort is wrong, endpoint selection may succeed while the application connection fails.

A selector matches object labels. Service port is the stable client-facing port. Target port identifies the backend listening port. Named ports can improve clarity when configured consistently. Ready endpoint membership is important for ordinary traffic, with specific publish-not-ready and other behavior requiring deliberate understanding. Service creation does not start the application or make it listen on a chosen port. Inspect labels, EndpointSlices, and process listeners in order. Keeping stable discovery separate from replaceable Pod addresses supports rollouts, but it adds another configuration boundary that requires testing rather than assumption.

Why this matters

A Service port 80 targets container port 8080, with selector app: orders matching the Deployment’s Pod labels.

A common trap

Do not overlook this operational distinction: A Service with no ready matching endpoints cannot deliver traffic even if its YAML is valid.

Readiness and service discovery

ClusterIP is normally reachable within the cluster, not automatically from a host browser. DNS helps workloads locate Services. Ready endpoint membership matters for routing, and port-forward is a scoped local inspection tool rather than an external production publishing strategy. For example, kubectl port-forward svc/web 8114:80 exposes a local debugging path while the underlying Service remains ClusterIP.

WORKED EXAMPLE
kubectl port-forward svc/web 8114:80 exposes a local debugging path while the underlying Service remains ClusterIP.

A Pod calls an internal Service by DNS name. Cluster discovery resolves the name, and the client connects to the Service's stable address and port. A host browser outside the cluster usually cannot reach that ClusterIP directly. Port-forward can create a temporary local debugging route, while external publishing needs an appropriate supported entry mechanism.

ClusterIP is an internal Service type. DNS discovery provides names within its configured scope. Port-forward is a client-side debugging connection, not a durable internet exposure policy. Namespace affects simple Service name resolution, so a name that works in one namespace may need qualification elsewhere. Inspect ready endpoints before blaming DNS for every timeout. A forwarded request can bypass portions of the normal production traffic path; it proves useful backend behavior but not necessarily ingress routing or external load-balancer health. Record the exact source and path of each test so its evidence is not overstated.

Why this matters

kubectl port-forward svc/web 8114:80 exposes a local debugging path while the underlying Service remains ClusterIP.

A common trap

Do not overlook this operational distinction: Ready endpoint membership matters for routing, and port-forward is a scoped local inspection tool rather than an external production publishing strategy.

KEEP THESE WITH YOU

Today’s takeaways

Deployments and ReplicaSets: A Deployment manages updates to Pod templates and replica counts through ReplicaSets. Controllers replace lost Pods to maintain desired state. Pod names are not stable application interfaces. Review selectors and template labels together because they identify which Pods belong to the workload.

Service selectors and ports: A Service provides stable discovery and routes toward matching endpoints. Selectors match Pod labels; port is the service-facing port and targetPort is the backend container port. A Service with no ready matching endpoints cannot deliver traffic even if its YAML is valid.

Readiness and service discovery: ClusterIP is normally reachable within the cluster, not automatically from a host browser. DNS helps workloads locate Services. Ready endpoint membership matters for routing, and port-forward is a scoped local inspection tool rather than an external production publishing strategy.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed