๐Ÿš€ 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?

TermMeaning
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

ToolPurpose
GitHub ActionsAutomate build, test, and deploy
DockerPackage your app
KubernetesRun your app in containers
kubectlInteract with your cluster
Helm (optional)Package and deploy apps on Kubernetes
SecretsStore 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) and GITHUB_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 push
  • prod 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

BenefitWhy It Matters
๐Ÿ”„ Fully AutomatedNo more manual deployment
โœ… Built-in TestingCatch issues before production
โฑ๏ธ Faster ReleasesContinuous shipping possible
๐Ÿ” SecureSecrets managed with GitHub
๐Ÿงฉ ExtensibleAdd 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.


Category: 
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments