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
Learn how Kubernetes is used in CI/CD pipelines to automate container deployments, application updates, rollouts, scaling, and cloud-native software delivery.
Kubernetes CI/CD Workflow
Source Code
Build Container
Run Tests
Publish Image
Deploy to Kubernetes
Verify Rollout
Introduction
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
Kubernetes works with containerized application workloads and declarative resources, making it a common deployment target for automated software delivery pipelines.
A CI/CD pipeline builds and validates container images before Kubernetes uses those images to run application workloads.
Key Topics
Kubernetes resources are typically described using declarative configuration files that define the desired application state.
Key Topics
A Kubernetes Deployment manages application Pods and supports controlled updates to the desired application version.
Key Topics
CI/CD pipelines can apply validated Kubernetes configurations to automatically release applications into target environments.
Key Topics
Kubernetes Workflow
Stores the application images produced by the CI pipeline before they are deployed to Kubernetes.
The smallest deployable computing unit in Kubernetes, capable of running one or more closely related containers.
Manages application workloads and declarative updates for Pods and ReplicaSets.
Provides a stable way to expose and connect to a group of application Pods.
Separate application configuration and sensitive values from container images.
Automates building, testing, publishing, deploying, and validating application releases.
Kubernetes Deployment
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: 3000Example Service
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: ClusterIPApplication Networking
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
The pipeline produces a validated application artifact and then uses Kubernetes as the platform where the containerized workload is released and operated.
A developer pushes application code and Kubernetes configuration to the source repository.
The CI pipeline builds the application and creates a versioned container image.
Automated tests validate the application before it moves further through the delivery pipeline.
The validated container image is pushed to a container registry with an appropriate version or immutable tag.
The CD process updates Kubernetes resources so the cluster can move the workload toward the new desired state.
The pipeline checks rollout status, application health, and other deployment validation signals.
Pipeline Example
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-appUse Cases
Deploy validated container images to Kubernetes automatically after successful pipeline stages.
Move application versions through development, staging, and production environments using controlled delivery workflows.
Update application versions gradually through Kubernetes Deployment rollout mechanisms.
Return to an earlier known application revision when a deployment does not meet validation requirements.
Build and deploy independently versioned containerized services through automated pipelines.
Use Kubernetes as the deployment platform for containerized workloads that require scaling and operational automation.
Learning Roadmap
Start with Kubernetes fundamentals and gradually connect containerization, automated pipelines, deployment workflows, and operational practices.
Understand clusters, nodes, Pods, Deployments, Services, namespaces, configuration, and container workloads.
Build a Docker image that packages the application and its required runtime dependencies.
Define the Kubernetes resources required to run and expose the application.
Configure automated pipelines to build the application, run tests, and validate the release artifact.
Use the delivery workflow to apply updated Kubernetes configuration and release the application.
Verify rollouts, observe application behavior, and improve deployment and rollback processes.
Best Practices
Use clear and traceable container image versions so deployments can be associated with a specific application build.
Define Kubernetes resources using version-controlled configuration to make application state changes reviewable and repeatable.
Use an appropriate strategy for separating development, staging, and production configuration and access.
Check rollout status and relevant health signals before considering an automated deployment successful.
Design deployment workflows so teams can respond when a new application version does not meet expected requirements.
Use appropriate authentication, authorization, least-privilege access, and secure handling of deployment credentials.
Continue Learning
Learn how Docker is used to build, test, publish, and deploy containerized applications.
☸️Learn Kubernetes fundamentals, Pods, Deployments, Services, networking, storage, security, and scaling.
🚀Understand Continuous Integration, Continuous Delivery, pipelines, automated testing, and software delivery.
Next Step
Practice building container images, creating Kubernetes manifests, deploying workloads, verifying rollouts, and managing application releases through automated CI/CD workflows.