,

CI/CD with GitHub Actions & Kubernetes: The Ultimate Guide (2025)

Posted by

πŸš€ 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.


Leave a Reply

Your email address will not be published. Required fields are marked *

0
Would love your thoughts, please comment.x
()
x