TechyPilots Info
TechyPilots.INFO
Home/Tutorials/CI/CD/Kubernetes
CI/CD & Kubernetes Deployment

Kubernetes in CI/CD

Learn how Kubernetes is used in CI/CD pipelines to automate container deployments, application updates, rollouts, scaling, and cloud-native software delivery.

Level: Beginner to Intermediate
Topic: Kubernetes & CI/CD

Kubernetes CI/CD Workflow

Build, Deploy & Verify

Source Code

Build Container

Run Tests

Publish Image

Deploy to Kubernetes

Verify Rollout

Introduction

Why use Kubernetes in CI/CD?

Kubernetes is a platform for managing containerized workloads and supports automation around deployment, scaling, and application operations. CI/CD pipelines can use Kubernetes as the deployment environment for validated application releases.

A typical workflow builds an application, creates a container image, runs automated tests, publishes the image to a registry, and updates Kubernetes resources to release the new version.

Kubernetes uses declarative configuration and controllers that work to move the actual cluster state toward the desired state defined by application resources.

Core Concepts

Understanding Kubernetes in CI/CD

Kubernetes works with containerized application workloads and declarative resources, making it a common deployment target for automated software delivery pipelines.

01

Container Images

A CI/CD pipeline builds and validates container images before Kubernetes uses those images to run application workloads.

Key Topics

  • Image tags
  • Container registries
  • Versioning
  • Immutable artifacts
02

Kubernetes Manifests

Kubernetes resources are typically described using declarative configuration files that define the desired application state.

Key Topics

  • Deployment
  • Service
  • ConfigMap
  • Secret
03

Deployments

A Kubernetes Deployment manages application Pods and supports controlled updates to the desired application version.

Key Topics

  • Rolling updates
  • ReplicaSets
  • Rollouts
  • Rollbacks
04

Automated Delivery

CI/CD pipelines can apply validated Kubernetes configurations to automatically release applications into target environments.

Key Topics

  • Automated deployment
  • Environment promotion
  • Release validation
  • Delivery pipelines

Kubernetes Workflow

Main components

Container Registry

Stores the application images produced by the CI pipeline before they are deployed to Kubernetes.

Pod

The smallest deployable computing unit in Kubernetes, capable of running one or more closely related containers.

Deployment

Manages application workloads and declarative updates for Pods and ReplicaSets.

Service

Provides a stable way to expose and connect to a group of application Pods.

ConfigMap & Secret

Separate application configuration and sensitive values from container images.

CI/CD Platform

Automates building, testing, publishing, deploying, and validating application releases.

Kubernetes Deployment

Define the desired application state

Kubernetes manifests describe the resources required to run an application. A Deployment can define the application image, replicas, labels, and Pod template.

A CI/CD pipeline can update the application image or apply updated configuration, allowing Kubernetes controllers to manage the rollout toward the new desired state.

Example Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: registry.example.com/my-app:1.0.0
          ports:
            - containerPort: 3000

Example Service

apiVersion: v1
kind: Service
metadata:
  name: my-app-service
spec:
  selector:
    app: my-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3000
  type: ClusterIP

Application Networking

Expose application workloads

Kubernetes Services provide a stable abstraction for accessing a group of Pods. CI/CD workflows can deploy both workload and networking resources as part of an application release.

The exact resources required depend on the application architecture, cluster configuration, and how the application is exposed to internal or external users.

Pipeline Workflow

How Kubernetes fits into CI/CD

The pipeline produces a validated application artifact and then uses Kubernetes as the platform where the containerized workload is released and operated.

01

Source

A developer pushes application code and Kubernetes configuration to the source repository.

02

Build

The CI pipeline builds the application and creates a versioned container image.

03

Test

Automated tests validate the application before it moves further through the delivery pipeline.

04

Publish

The validated container image is pushed to a container registry with an appropriate version or immutable tag.

05

Deploy

The CD process updates Kubernetes resources so the cluster can move the workload toward the new desired state.

06

Verify

The pipeline checks rollout status, application health, and other deployment validation signals.

Pipeline Example

Build, publish, deploy, and verify

This simplified example demonstrates the general flow of a CI/CD pipeline that creates a container image, tests it, publishes it, updates a Kubernetes Deployment, and checks the rollout status.

Production pipelines should also consider authentication, access controls, secrets management, validation, environment separation, and deployment strategy requirements.

Example CI/CD Configuration

stages:
  - build
  - test
  - publish
  - deploy
  - verify

build:
  stage: build
  script:
    - docker build -t my-app:$CI_COMMIT_SHA .

test:
  stage: test
  script:
    - docker run --rm my-app:$CI_COMMIT_SHA npm test

publish:
  stage: publish
  script:
    - docker push registry.example.com/my-app:$CI_COMMIT_SHA

deploy:
  stage: deploy
  script:
    - kubectl set image deployment/my-app \
      my-app=registry.example.com/my-app:$CI_COMMIT_SHA

verify:
  stage: verify
  script:
    - kubectl rollout status deployment/my-app

Use Cases

What can Kubernetes automate in CI/CD?

Automated Application Deployment

Deploy validated container images to Kubernetes automatically after successful pipeline stages.

Environment Promotion

Move application versions through development, staging, and production environments using controlled delivery workflows.

Rolling Updates

Update application versions gradually through Kubernetes Deployment rollout mechanisms.

Rollback Workflows

Return to an earlier known application revision when a deployment does not meet validation requirements.

Microservices Delivery

Build and deploy independently versioned containerized services through automated pipelines.

Cloud-Native Applications

Use Kubernetes as the deployment platform for containerized workloads that require scaling and operational automation.

Learning Roadmap

How to learn Kubernetes for CI/CD

Start with Kubernetes fundamentals and gradually connect containerization, automated pipelines, deployment workflows, and operational practices.

Step 1

Learn Kubernetes Fundamentals

Understand clusters, nodes, Pods, Deployments, Services, namespaces, configuration, and container workloads.

Step 2

Containerize an Application

Build a Docker image that packages the application and its required runtime dependencies.

Step 3

Create Kubernetes Manifests

Define the Kubernetes resources required to run and expose the application.

Step 4

Build and Test in CI

Configure automated pipelines to build the application, run tests, and validate the release artifact.

Step 5

Deploy to Kubernetes

Use the delivery workflow to apply updated Kubernetes configuration and release the application.

Step 6

Monitor and Improve

Verify rollouts, observe application behavior, and improve deployment and rollback processes.

Best Practices

Kubernetes CI/CD best practices

Use Versioned Images

Use clear and traceable container image versions so deployments can be associated with a specific application build.

Keep Configuration Declarative

Define Kubernetes resources using version-controlled configuration to make application state changes reviewable and repeatable.

Separate Environments

Use an appropriate strategy for separating development, staging, and production configuration and access.

Verify Rollouts

Check rollout status and relevant health signals before considering an automated deployment successful.

Plan for Rollbacks

Design deployment workflows so teams can respond when a new application version does not meet expected requirements.

Protect Cluster Access

Use appropriate authentication, authorization, least-privilege access, and secure handling of deployment credentials.

Next Step

Start building Kubernetes-powered CI/CD pipelines

Practice building container images, creating Kubernetes manifests, deploying workloads, verifying rollouts, and managing application releases through automated CI/CD workflows.