Role of Kubernetes in a DevOps Pipeline, Stage by Stage

Where Kubernetes fits in a DevOps pipeline: rolling updates, rollout status and undo, Kustomize, GitOps, probes and HPA, with commands and YAML.

Jul 17, 2025 - 16:17
Nov 10, 2026 - 07:55
 0  62
TOPICDevOps BasicsPractical guide
Role of Kubernetes in a DevOps Pipeline, Stage by Stage

Kubernetes sits in the deploy, run and operate stages of a DevOps pipeline. CI tools build and test the image, then Kubernetes takes over: it rolls out the new version with a Deployment, checks health with probes, scales with the Horizontal Pod Autoscaler and rolls back when a release fails. It does not build code or replace your CI server.

This guide walks through each pipeline stage and shows exactly what Kubernetes does there, with the commands and manifests you would use. The facts were checked against the Kubernetes documentation in November 2026. The current minor versions listed on the Kubernetes releases page are 1.37, 1.36 and 1.35, so examples avoid anything newer than those. If you want the architecture behind these objects first, read our guide to Kubernetes architecture components.

Key takeaways

  • Kubernetes is a runtime and control layer. Build, test and image publishing still happen in a CI tool such as Jenkins, GitLab CI or GitHub Actions.
  • A rollout starts when the Pod template of a Deployment changes, for example when the pipeline sets a new image tag.
  • Rolling updates use maxUnavailable and maxSurge, and both default to 25 percent.
  • kubectl rollout status makes a pipeline step fail when a release does not become healthy, and kubectl rollout undo returns to the previous revision.
  • Readiness probes decide when a new Pod receives traffic, so they protect users during every release.
  • Push-based deploys (the pipeline runs kubectl) and pull-based GitOps (an in-cluster controller applies Git) both work. Pick one per environment.

Where Kubernetes fits in the pipeline

A DevOps pipeline moves a change from commit to a running, observed service. Kubernetes touches the later half of that path. The table shows who does what.

Pipeline stageMain toolWhat Kubernetes contributes
Code and commitGitNothing directly. Manifests live in Git next to the code.
Build and unit testJenkins, GitLab CI, GitHub ActionsOptional: CI agents can run as Pods so build capacity scales with the queue.
PackageDocker, container registryNothing. The pipeline pushes an image that Kubernetes pulls later.
Test environmentNamespaces, Helm, KustomizeA throwaway namespace per branch gives isolated integration tests.
Deploykubectl, Helm, Argo CD, FluxDeployments run rolling updates, and Services route traffic to ready Pods.
OperateKubernetes controllersRestarts failed containers, reschedules Pods and scales on load.
Monitor and feedbackPrometheus, Grafana, logging stackExposes Pod, node and workload state that dashboards and alerts read.

Keeping that division clear avoids the most common beginner mistake, which is expecting the cluster to compile code or run unit tests. For the wider tool picture see 14 CI/CD solutions for Kubernetes workloads.

Stage 1: build and test, with Kubernetes as the target

The CI job produces an image and tags it with something traceable, usually the Git commit SHA. Avoid the latest tag in manifests, because a Deployment only rolls out when its Pod template changes, and an unchanged tag name gives Kubernetes nothing to compare.

docker build -t registry.example.com/shop/api:${GIT_SHA} .
docker push registry.example.com/shop/api:${GIT_SHA}

Teams that run many parallel builds sometimes run the CI agents themselves as Pods, so the cluster supplies short-lived build workers. That is an option, not a requirement. The learning path for the image side is covered in our Docker training in Pune.

Stage 2: deploy with a Deployment

A Deployment declares the desired state: which image, how many replicas, and how to replace old Pods with new ones. When you change .spec.template, the Deployment creates a new ReplicaSet and shifts Pods over gradually. Changing only replicas scales the existing ReplicaSet and does not create a new revision.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
  namespace: shop
spec:
  replicas: 4
  selector:
    matchLabels:
      app: api
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: registry.example.com/shop/api:3f9c2ab
          ports:
            - containerPort: 8080
          readinessProbe:
            httpGet:
              path: /healthz
              port: 8080
            periodSeconds: 5
          resources:
            requests:
              cpu: 200m
              memory: 256Mi
            limits:
              memory: 512Mi

Per the Deployment documentation, maxUnavailable is rounded down and maxSurge is rounded up when you use percentages, and both default to 25 percent. With four replicas that means at most one Pod is unavailable and at most one extra Pod is created during the update. The controller also reports a failed rollout after progressDeadlineSeconds, which defaults to 600, and keeps 10 old ReplicaSets by default so you can roll back.

Make the pipeline wait for the result

A deploy step that only runs kubectl apply reports success the moment the API server accepts the manifest, not when the release is healthy. Add a status check so the job fails when the rollout does:

kubectl -n shop diff -f k8s/ || true      # exit code 1 means differences, which is expected
kubectl -n shop apply -f k8s/
kubectl -n shop rollout status deployment/api --timeout=300s

kubectl diff compares the live objects with what apply would change and exits with 0 for no differences, 1 for differences and above 1 for an error, so a pipeline can show the change before it happens. rollout status blocks until the rollout finishes and returns a non-zero exit code if it does not.

Roll back when the check fails

kubectl -n shop rollout history deployment/api
kubectl -n shop rollout undo deployment/api
kubectl -n shop rollout undo deployment/api --to-revision=2

Without --to-revision, undo goes back to the previous revision. Wire it into a failure branch of the job, then page a human. Our guides on safe rollbacks and Kubernetes deployment strategies cover blue-green and canary releases, which a plain rolling update does not give you.

Stage 3: manage environments with Kustomize or Helm

The same application usually runs in dev, staging and production with different replica counts, hostnames and image tags. Two common tools keep one set of manifests:

  • Kustomize is built into kubectl. kubectl kustomize <dir> renders the result and kubectl apply -k <dir> applies it. An overlay directory references a shared base and changes only what differs.
  • Helm packages manifests as charts with values files. helm upgrade --install installs the release if it does not exist and upgrades it if it does.

With Kustomize, the pipeline updates the image tag without editing YAML by hand:

cd k8s/overlays/staging
kustomize edit set image registry.example.com/shop/api=registry.example.com/shop/api:${GIT_SHA}
kubectl apply -k .

The Kustomize reference describes the images transformer with name, newName, newTag and digest fields, and kustomize edit set image writes them for you. Note that kustomize edit is a command of the standalone kustomize binary, not of kubectl kustomize. See Helm best practices for chart structure.

Stage 4: choose push or pull delivery

ModelHow it worksTrade-off
PushThe CI job holds cluster credentials and runs kubectl or helm.Simple to start. The CI system becomes a high-value credential holder.
Pull (GitOps)A controller inside the cluster, such as Argo CD or Flux, watches a Git repository and applies it.Git is the audit trail and drift is corrected. Needs an extra component and a repo layout.

In the pull model the pipeline only builds the image and commits the new tag to the config repository. Read what GitOps is and compare tools in 8 GitOps tools for Kubernetes.

Stage 5: operate with probes and autoscaling

Probes protect every rollout

The kubelet runs liveness, readiness and startup probes. A failing liveness probe makes the kubelet restart the container. A failing readiness probe removes the Pod from Service endpoints without restarting it. During a rolling update, new Pods that are not ready do not take traffic, so users keep hitting the old version until the new one passes its check. In the Kubernetes liveness probe example, any HTTP status from 200 to 399 counts as success. See liveness and readiness probes for patterns.

Autoscaling follows load

The Horizontal Pod Autoscaler adjusts the replica count of a Deployment. Its control loop runs every 15 seconds by default (the --horizontal-pod-autoscaler-sync-period flag of kube-controller-manager). CPU utilization is measured as a percentage of the container's request, so Pods without a CPU request give the autoscaler nothing to act on. Resource metrics normally come from the Metrics Server add-on, which you install separately.

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api
  namespace: shop
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  minReplicas: 4
  maxReplicas: 12
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 60

Details are in how the Horizontal Pod Autoscaler maintains performance.

Stage 6: monitor and feed back into the pipeline

Kubernetes does not ship dashboards or alerts, but it exposes state that other tools read. Prometheus typically scrapes the cluster, Grafana draws the dashboards and an alerting tool pages the on-call engineer. The useful loop is to compare error rate and latency before and after each deploy, then promote or roll back. Start with Prometheus and Grafana together and the 10 alerts in monitoring alerts every DevOps team should configure.

Benefits and costs

BenefitHow it shows up in the pipelineCost to plan for
Repeatable deploysThe same manifests promote through every environment.Someone must own manifest quality and review.
Safer releasesRolling updates, probes and rollback limit blast radius.Probes and resource requests must be written well.
Elastic capacityHPA adds replicas under load.Needs metrics, requests and enough node capacity.
Self-healingFailed containers restart and Pods reschedule.Crash loops can hide behind restarts, so alert on restart counts.
Consistent platformOne API across clouds and on-premises.Upgrades every few months and operational skill.

Kubernetes is also not always the right answer. A small team with one or two services may ship faster on a managed container service. Our guide to things to know before learning Kubernetes helps you decide when it pays off.

Common pipeline mistakes

  • Deploying the latest tag, which makes rollbacks and audits unreliable.
  • Skipping rollout status, so a broken release shows as a green job.
  • Leaving out CPU and memory requests, which breaks autoscaling and scheduling.
  • Giving the CI runner cluster-admin rights. Use a namespaced service account with only the verbs it needs, as covered in RBAC in Kubernetes.
  • Running without a readiness probe, so traffic reaches Pods that are still starting.
  • Editing live objects with kubectl edit while a GitOps controller is active, which creates drift the controller will undo.

More examples of what goes wrong are in 10 real mistakes to avoid in Kubernetes deployment.

Learn it hands-on

Practise by building the pipeline above end to end: image build, a staging namespace, rollout status, rollback and an HPA. Our CKA training in Pune covers these objects in the classroom at Kharadi and live online across India.

Frequently asked questions

What is the role of Kubernetes in a DevOps pipeline?

Kubernetes runs and manages the containers that the pipeline produces. It performs rolling updates, checks Pod health, scales replicas and supports rollbacks. Building, testing and publishing the image remain the job of CI tools.

Is Kubernetes a CI/CD tool?

No. Kubernetes has no built-in pipeline engine. You pair it with a CI system such as Jenkins, GitLab CI or GitHub Actions, and optionally a GitOps controller such as Argo CD or Flux for delivery.

How does a Kubernetes rolling update work?

When the Pod template changes, the Deployment creates a new ReplicaSet and gradually scales it up while scaling the old one down. The limits come from maxSurge and maxUnavailable, which both default to 25 percent.

How do I roll back a failed deployment in Kubernetes?

Run kubectl rollout undo deployment/name to return to the previous revision, or add --to-revision to pick a specific one. kubectl rollout history lists the available revisions.

Should the pipeline run kubectl, or should I use GitOps?

Both work. Running kubectl from CI is simpler to start with. GitOps keeps Git as the source of truth and corrects drift, but adds a controller to operate. Many teams start with push and move to pull as the number of clusters grows.

Why do pipelines need readiness probes?

A readiness probe keeps new Pods out of Service endpoints until they can answer requests. Without it, a rolling update can send traffic to a Pod that has started but is not yet ready.

Do I need Helm or Kustomize?

You need some way to vary manifests per environment. Kustomize is built into kubectl and works well for overlays. Helm adds packaging, versioned releases and templating. Many teams use both.

Official references

Interested in learning more?Get a callback from our training advisors.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.