π CI/CD with GitHub Actions & Kubernetes: The Ultimate Guide (2025)
In modern software delivery, speed and stability are no longer trade-offs β theyβre requirements.
You want to ship code quickly, catch bugs early, and deploy updates automatically β without touching production manually.
Thatβs where CI/CD (Continuous Integration & Continuous Deployment) and tools like GitHub Actions and Kubernetes come in.
This blog walks you through how to set up a full CI/CD pipeline using GitHub Actions and Kubernetes, from zero to advanced use cases.

π§ What is CI/CD?
Term | Meaning |
---|---|
CI (Continuous Integration) | Automatically testing and integrating code every time itβs pushed to the repo |
CD (Continuous Deployment/Delivery) | Automatically deploying code to a test or production environment after passing tests |
GitHub Actions helps you automate this entire flow.
Kubernetes is where your app lives and scales.
π§ Tools Youβll Use
Tool | Purpose |
---|---|
GitHub Actions | Automate build, test, and deploy |
Docker | Package your app |
Kubernetes | Run your app in containers |
kubectl | Interact with your cluster |
Helm (optional) | Package and deploy apps on Kubernetes |
Secrets | Store Kubernetes tokens, Docker credentials securely in GitHub |
πͺ Step-by-Step Setup
πΉ Step 1: Write Your Application
Create a simple app in Node.js, Python, or any language. For example, a basic web app that responds to /health
.
πΉ Step 2: Create a Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY . .
RUN npm install
CMD ["npm", "start"]
Build locally:
docker build -t myapp:latest .
πΉ Step 3: Set Up a Kubernetes Cluster
Options:
- Minikube (local)
- Kind (Kubernetes-in-Docker)
- Cloud-managed: GKE (Google), EKS (AWS), AKS (Azure)
Ensure you can run:
kubectl get nodes
πΉ Step 4: Push Image to a Container Registry
Use DockerHub, GitHub Container Registry, or any private registry.
docker tag myapp ghcr.io/<username>/myapp:latest
docker push ghcr.io/<username>/myapp:latest
πΉ Step 5: Create Kubernetes YAML Files
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 2
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: ghcr.io/<username>/myapp:latest
ports:
- containerPort: 3000
service.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
type: LoadBalancer
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 3000
πΉ Step 6: Create a GitHub Actions Workflow
File: .github/workflows/deploy.yaml
name: CI/CD to Kubernetes
on:
push:
branches: [main]
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and push Docker image
run: |
docker build -t ghcr.io/${{ github.repository }}/myapp:latest .
docker push ghcr.io/${{ github.repository }}/myapp:latest
- name: Set up Kubeconfig
run: |
echo "${{ secrets.KUBECONFIG_DATA }}" | base64 -d > $HOME/.kube/config
- name: Deploy to Kubernetes
run: |
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
π Store your
KUBECONFIG_DATA
(base64 of your kubeconfig file) andGITHUB_TOKEN
in GitHub Secrets.
π‘οΈ Advanced CI/CD Features
β 1. Helm Integration
Replace raw YAML with a Helm chart:
- name: Deploy with Helm
run: helm upgrade --install myapp ./helm-chart --set image.tag=latest
β 2. Environment-Specific Deployments
Use matrix strategies or conditional logic to deploy to:
dev
on every pushprod
on every tag
β 3. Blue/Green or Canary Deployments
Use Argo Rollouts or Helm hooks for gradual updates.
β 4. Rollback on Failure
Use kubectl rollout undo
or integrate with monitoring tools like Prometheus to trigger alerts and automation.
π Monitoring & Observability (Optional but Important)
Set up:
- Prometheus for metrics
- Grafana for dashboards
- Loki for logs
β Final Workflow Summary
1. Code pushed to GitHub (main branch)
2. GitHub Actions triggers
3. Docker image built & pushed
4. Kubernetes deployment updated
5. App is live within seconds π
π§ Benefits of Using GitHub Actions + Kubernetes
Benefit | Why It Matters |
---|---|
π Fully Automated | No more manual deployment |
β Built-in Testing | Catch issues before production |
β±οΈ Faster Releases | Continuous shipping possible |
π Secure | Secrets managed with GitHub |
π§© Extensible | Add monitoring, tests, rollbacks easily |
π Final Thoughts
Combining GitHub Actions with Kubernetes gives you a powerful, modern CI/CD pipeline β one thatβs fast, secure, and scalable.
Start small: build β test β deploy
Then grow: add Helm, monitoring, GitOps, and rollback strategies.
In 2025, CI/CD isn’t optional β it’s your competitive edge.
Leave a Reply