Skip to content

    System Design

    Kubernetes Core Objects: Pods, Deployments, Services and Config

    Learn the Kubernetes objects a back-end service needs: Pod, ReplicaSet, Deployment, Service, ConfigMap, Secret and resource limits, and how they fit together.

    By Published 13 min read

    Share

    Standard lessonintermediateBackend System Design

    Before this: Docker and Containers

    What you'll learn: By the end of this lesson you will be able to explain what a Kubernetes cluster is made of, say what a Pod, a ReplicaSet, a Deployment and a Service each do and why you rarely create the first two by hand, read a small manifest for a back-end service, decide what belongs in a ConfigMap, a Secret and a resource request or limit, and predict what a rolling update does to a three-replica service.

    A busy kitchen does not assign one cook to one dish for ever. A manager says "keep three stations open, each with a grill and a cutting board". Stations come and go as cooks change shifts, the manager notices an empty station and fills it, and customers ring one phone number at the pass, never a particular cook's mobile.

    Kubernetes is that manager. You write down the state you want, and a set of controllers keeps working to make the cluster match it. The previous lesson built the image: the sealed package of one service. This lesson is about the objects that run that image on many machines, keep a chosen number of copies alive, give them one stable address and feed them configuration. It covers the objects a back-end engineer touches every week, not cluster operations or security hardening.

    Verified on 2026-12-01 against the Kubernetes documentation pages listed at the end. No cluster was available while writing: every manifest on this page is shown as written, not as run, and no command output appears.

    The core idea

    Kubernetes objects are records of intent. You create an object that describes what you want, and controllers compare it with what exists and keep acting until the two match. The documentation calls an object a "record of intent" and says that once you create it, the system "will constantly work to ensure that the object exists". Almost every object has a spec, which you write and which is the desired state, and a status, which the system fills in and which is the current state.

    A script runs once. A Deployment is a standing instruction: when a Pod vanishes or you change the image tag, a controller notices that reality differs from the spec and acts.

    Three illustrations run through the lesson, each labelled:

    • Minimal example: a Deployment of three copies of one image, with the manifest written out.
    • Realistic example: the ShopStream catalogue service with a Service, a ConfigMap, a Secret and resource settings.
    • Failure example: a memory limit set below what the JVM wants, so Pods restart in a loop.

    The cluster in one picture

    A cluster is a control plane plus worker machines. The documentation says "a Kubernetes cluster consists of a control plane and one or more worker nodes". The pieces you need to know by name:

    • kube-apiserver: "the core component server that exposes the Kubernetes HTTP API". Every object goes through it.
    • etcd: a "consistent and highly-available key value store for all API server data".
    • kube-scheduler: "assigns each Pod to a suitable node".
    • kube-controller-manager: "runs controllers to implement Kubernetes API behavior". Deployment logic is a controller.
    • kubelet: on each node, "ensures that Pods are running, including their containers".
    • Container runtime: "software responsible for running containers", where the Docker lesson's image runs.
    A Kubernetes cluster: control plane and worker nodeskubectl to kube-apiserver (apply); kube-apiserver to etcd (store); kube-scheduler to kube-apiserver (assign node); Controllers to kube-apiserver (watch, act); kubelet to kube-apiserver (report status); kubelet to Pods (start)CONTROL PLANEWORKER NODEkubectl: your manifestkubectlyour manifestkube-apiserverkube-apiserveretcd: stores objectsetcdstores objectskube-scheduler: picks a nodekube-schedulerpicks a nodeControllers: match intentControllersmatch intentkubelet: on each nodekubeleton each nodePods: run containersPodsrun containersapplystoreassign nodewatch, actreport statusstart

    Figure 1. The parts of a cluster. How to read this: you send a manifest to the API server, which stores it. Controllers and the scheduler watch the API server and act; the kubelet on a worker node starts the Pods assigned to it and reports their status back. Nothing talks to Pods directly except through these paths.

    Pod: the unit that runs

    A Pod is, in the documentation's words, "a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers". Its contents are "always co-located and co-scheduled". The most common case is one container per Pod, and the page says you can then "think of a Pod as a wrapper around a single container".

    Two facts shape everything else. Each Pod gets its own IP address, and the containers in one Pod share that address and can reach each other on localhost. And Pods are "relatively ephemeral, disposable entities", so a Pod's address is not a stable name for anything. The page adds that you "rarely create individual Pods directly" and should create them "using workload resources such as Deployment or Job".

    ReplicaSet and Deployment: keeping N copies and changing them safely

    A ReplicaSet's purpose is "to maintain a stable set of replica Pods running at any given time". It finds the Pods it owns with a label selector, and if there are too few it creates more. The documentation recommends a Deployment instead, because it "is a higher-level concept that manages ReplicaSets and provides declarative updates to Pods".

    A Deployment is the object you write for a stateless service (the stateless services lesson explains why that matters). Minimal example: three copies of one image.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: catalogue
      labels:
        app: catalogue
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: catalogue
      template:
        metadata:
          labels:
            app: catalogue
        spec:
          containers:
          - name: catalogue
            image: registry.example.com/shopstream/catalogue:1.4.0
            ports:
            - containerPort: 8080

    Not run. The shape follows the example Deployment in the Kubernetes documentation; the image name is a placeholder. Three parts matter. replicas is the desired count. selector tells the Deployment which Pods are its own, and it must match the labels in the template. The template is a Pod specification that every copy is stamped from.

    Deployment, ReplicaSet and PodsDeployment to ReplicaSet (creates); ReplicaSet to Pods (keeps count)Deployment: catalogueDeploymentcatalogueReplicaSet: owns the PodsReplicaSetowns the PodsPods: 3 copiesPods3 copiescreateskeeps count

    Figure 2. Who owns what. How to read this: you write the Deployment, it creates a ReplicaSet, and the ReplicaSet keeps the right number of Pods. You normally touch only the first box.

    What a rollout does

    The Deployment page states that a rollout "is triggered if and only if the Deployment's Pod template (that is, .spec.template) is changed, for example if the labels or container images of the template are updated. Other updates, such as scaling the Deployment, do not trigger a rollout." A new image tag therefore starts a rollout: a new ReplicaSet is created and scaled up while the old one is scaled down.

    By default the rollout keeps at least 75 percent of the desired Pods up and allows at most 125 percent, because maxUnavailable and maxSurge both default to 25 percent. The page says the maxUnavailable percentage is rounded down and the maxSurge percentage is rounded up. Worked example (arithmetic from those rules): with three replicas, 25 percent of 3 is 0.75, so maxUnavailable rounds down to 0 and maxSurge rounds up to 1. The Deployment may run four Pods at once and may never drop below three available.

    sequenceDiagram accTitle: Rolling update of three replicas with the default settings accDescr: With three replicas, a maximum surge of one and no unavailable Pods allowed, the Deployment adds one new Pod, waits for it, removes one old Pod, and repeats until all three Pods are new. The count of available Pods never drops below three. participant D as Deployment participant Old as Old ReplicaSet (1.4.0) participant New as New ReplicaSet (1.5.0) Note over Old: 3 Pods running D->>New: scale to 1 (surge: 4 Pods total) New-->>D: Pod 1 ready D->>Old: scale to 2 D->>New: scale to 2 New-->>D: Pod 2 ready D->>Old: scale to 1 D->>New: scale to 3 New-->>D: Pod 3 ready D->>Old: scale to 0 Note over New: 3 Pods running

    Figure 3. A rolling update, step by step. How to read this: the order is a simplified picture of the rule, not a log. The point is that a new Pod must be ready before an old one is removed, which is why readiness checks decide whether a rollout is safe.

    "Ready" is decided by the readiness probe, covered in health checks. The Kubernetes probes page says a Pod with containers reporting that they are not ready "does not receive traffic through Kubernetes Services". The probe is how you tell Kubernetes whether the application can serve requests yet, which matters for a JVM that takes a while to start.

    A Deployment keeps old ReplicaSets (10 by default) so that it can go back: kubectl rollout undo deployment/<name> rolls back to the previous revision, and only the Pod template is rolled back. A rollout that cannot progress is reported as failed after progressDeadlineSeconds, which defaults to 600.

    Service: one stable address for changing Pods

    If Pods are disposable and each has its own IP, a caller needs something stable. A Service is "a method for exposing a network application that is running as one or more Pods in your cluster". The set of Pods it targets "is usually determined by a selector", and a controller "continuously scans for Pods that match its selector" and updates the Service's endpoints. A Pod that is replaced simply appears or disappears from the set.

    apiVersion: v1
    kind: Service
    metadata:
      name: catalogue
    spec:
      selector:
        app: catalogue
      ports:
      - protocol: TCP
        port: 80
        targetPort: 8080

    Not run. This follows the documentation's example Service. port is what callers use, and targetPort is the container's port. The default Service type is ClusterIP, which "makes the Service only reachable from within the cluster". NodePort exposes it "on each Node's IP at a static port" (by default in the range 30000 to 32767), LoadBalancer exposes it "using an external load balancer" that you or your cloud provider supplies, and ExternalName maps the Service to a DNS name.

    Inside the cluster, DNS does the lookup. If the cluster has a DNS add-on, Pods can resolve a Service by name: a Pod in the same namespace uses catalogue, and a Pod in another namespace uses catalogue.<namespace>. This is how a ShopStream checkout service can call http://catalogue without knowing any Pod address.

    A Service routes to whichever Pods match its selectorCheckout service to Service (by name); Service to Pod 1 (label match); Service to Pod 2 (label match); Service to Pod 3 (skipped)Checkout service: calls catalogueCheckoutservicecalls catalogueService: catalogueServicecataloguePod 1Pod 1Pod 2Pod 2Pod 3: not readyPod 3not readyby namelabel matchlabel matchskipped

    Figure 4. A Service and its Pods. How to read this: the Service is the stable name and the Pods behind it change. A Pod that reports not ready is left out of the traffic, which is the link between probes and rollouts.

    ConfigMap and Secret: configuration outside the image

    An image should not change between environments, so settings live outside it. A ConfigMap "is an API object used to store non-confidential data in key-value pairs". A container can read it through command arguments, environment variables, or "a file in read-only volume". A Secret "contains a small amount of sensitive data such as a password, a token, or a key", and is used in a Pod through env[].valueFrom.secretKeyRef or a volume.

    Two warnings. A ConfigMap "does not provide secrecy or encryption". And Secrets are "by default, stored unencrypted in the API server's underlying data store (etcd)"; anyone with API or etcd access can read them, and the page recommends enabling encryption at rest, least-privilege RBAC and considering external secret stores. A Secret is better than a ConfigMap for a password, but it is not safe by default. Each is limited to 1 MiB.

    How changes propagate matters for a service. ConfigMaps "consumed as environment variables are not updated automatically and require a pod restart", while a mounted ConfigMap's keys are "eventually updated" by the kubelet. Since only a template change starts a rollout, an environment-variable config change needs a template change or a restart to take effect. An immutable ConfigMap (immutable: true) cannot be edited, only deleted and recreated.

    Resource requests and limits

    Each container can declare a request and a limit. The documentation says the scheduler "uses this information to decide which node to place the Pod on" (the request), while for a limit "the kubelet enforces those limits so that the running container is not allowed to use more of that resource". The two resources behave differently:

    • CPU: limits are enforced by throttling. A container near its limit is slowed, not killed.
    • Memory: limits are enforced "with out of memory (OOM) kills". A container over its limit "may get killed", and because enforcement is reactive it may not be killed the instant it crosses the line.

    CPU is measured in cores: 0.5 or 500m is half a core, and 500m is the same amount of computing power on any machine size. Memory is in bytes with suffixes, and the documentation warns that case matters: 400m of memory is 0.4 byte, while 400Mi is 400 mebibytes.

    Realistic example (ShopStream catalogue service; all numbers illustrative):

            resources:
              requests:
                cpu: 500m
                memory: 512Mi
              limits:
                memory: 768Mi
            env:
            - name: CATALOGUE_DB_URL
              valueFrom:
                configMapKeyRef:
                  name: catalogue-config
                  key: db_url
            - name: CATALOGUE_DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: catalogue-db
                  key: password
            readinessProbe:
              httpGet:
                path: /actuator/health/readiness
                port: 8080
              periodSeconds: 5

    Not run. This sits inside the container entry of the Deployment above: half a core and 512 MiB requested, memory capped at 768 MiB, a URL from a ConfigMap, a password from a Secret, and readiness on Spring Boot's readiness path.

    Build it

    There is no lab for this lesson. Running Kubernetes needs a cluster, and none was available while writing. Every manifest above is marked "Not run": none has been checked against a real API server, and no kubectl output is quoted. To try them, apply the Deployment to any cluster and watch kubectl get pods as you change the image tag.

    Trade-offs

    Choice Gain Cost Wrong when
    Deployment for a stateless service Self-healing, rolling updates, rollback Needs an image, probes and labels done correctly The workload needs stable disk or identity
    Bare Pod Simplest possible object No ReplicaSet keeps a count for it Anything beyond a learning exercise
    Service type ClusterIP Stable internal name, no exposure Not reachable from outside External clients call it directly
    Memory limit Caps damage from a leak OOM kill when set too tight Limit is below the real peak

    In practice: running the catalogue service on Kubernetes

    This is an educational scenario on ShopStream with illustrative numbers.

    This is a realistic scenario, not a case history.

    The situation

    ShopStream's catalogue service serves product pages, with a browsing peak of about 2,300 requests per second (the shared illustrative figure). It currently runs on three hand-managed virtual machines, and each release means logging in to each one. The team wants releases without downtime and automatic replacement of a failed instance.

    Starting architecture

    Catalogue service on three virtual machines, starting architectureLoad balancer to Catalogue VMs (requests); Catalogue VMs to Catalogue database (queries)Load balancerLoad balancerCatalogue VMs: 3, hand-managedCatalogue VMs3, hand-managedCatalogue databaseCataloguedatabaserequestsqueries

    Options considered

    Option Gain Cost Wrong when
    A. Keep VMs, script the release No new platform Replacement of a failed VM stays manual Releases are frequent
    B. Deployment and Service on Kubernetes Rolling updates, self-healing, one declared state A cluster to run or buy, new concepts to learn The team has no capacity to own the platform
    C. B plus autoscaling from day one Capacity follows load More moving parts before the basics are stable The service has no resource requests yet

    The decision

    Option B first. Autoscaling needs trustworthy resource requests, so those are measured on a staging copy before anything scales. The Deployment gets three replicas, a readiness probe, memory and CPU requests, a memory limit and a ConfigMap and Secret for settings. The database password is a Secret with encryption at rest enabled by the platform team.

    Rollout and verification

    Move one low-risk service first. In staging, change the image tag and watch the rollout stay at three available Pods; delete a Pod and confirm it is replaced. Then shift a small share of traffic, compare error rate and latency, and widen in steps. Try kubectl rollout undo once before it is needed.

    The 2 a.m. failure

    The alert says the catalogue Pods are restarting every few minutes. The JVM's heap grows with load, and the container's memory limit is below that peak, so the kernel kills the container.

    sequenceDiagram accTitle: A memory limit kills a container that is growing under load accDescr: Traffic rises and the Java process uses more memory. When the container's memory use crosses its limit under memory pressure, the kernel terminates it and the kubelet restarts it. The Service stops sending traffic to the Pod while it is not ready, and the cycle repeats. participant T as Traffic participant C as Catalogue container participant K as Kernel participant L as kubelet T->>C: load rises C->>C: memory use grows past the limit K-->>C: out-of-memory kill L->>C: restart container Note over C: not ready until it has started again T->>C: load returns, cycle repeats

    First checks: look at the Pod's last state and restart reason, compare the memory limit with the process's observed peak, and see whether all three Pods fail together. Mitigation: raise the limit to a value based on measured peak plus headroom, and set the JVM's heap size explicitly instead of relying on defaults. Follow-up: alert on the ratio of memory use to limit.

    Architect's notes

    • Always write a readiness probe. Rollouts and Services use it to decide who gets traffic.
    • Set requests from measurements. The scheduler places Pods by requests; guesses cause crowded or wasted nodes.
    • Choose CPU limits deliberately. Throttling slows a container instead of killing it, so a tight CPU limit can look like a latency problem.

    Common mistakes

    • Creating bare Pods for a service, with no ReplicaSet to keep the count.
    • Selector and template labels that do not match, so the Deployment does not own its Pods.
    • No readiness probe, which lets a rollout send traffic to a cold JVM.
    • Memory limit below the real peak, producing restart loops.
    • Treating a ConfigMap or Secret as private without checking who can read the API.

    Key takeaways

    • Kubernetes objects are records of intent; controllers keep reality matching the spec.
    • A Pod runs containers; a ReplicaSet keeps a count; a Deployment adds safe updates and rollback. You mostly write Deployments.
    • A rollout starts only when the Pod template changes; with three replicas and default settings it surges by one and never drops below three available.
    • A Service gives a stable name to a changing set of Pods chosen by labels; readiness decides which Pods are in the set.
    • Settings live in ConfigMaps and Secrets, but a Secret is not encrypted by default.
    • CPU limits throttle and memory limits kill, so size memory from measurement.

    Practice exercises

    Exercise 1 (30 min). With four replicas and the default strategy, compute maxUnavailable and maxSurge using the rounding rules above, then write the largest and smallest number of Pods that can exist during a rollout.

    Exercise 2 (1 hour). Write a Deployment and Service for a second ShopStream service of your choice. List which settings belong in a ConfigMap, which in a Secret, and justify a memory request and limit from a peak you estimate and label as illustrative.

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments