Nextgen Blog
HomeLearnAIQuantumRoboticsSecuritySpaceAbout
Nextgen Blog

By Anubhav โ€” full stack engineer, IIT Mandi CSE. Deep dives into AI, software engineering, and the technologies shaping the next generation of tech.

Navigate

  • Home
  • Learn
  • Blog
  • Archive
  • About

Topics

  • Artificial Intelligence
  • Quantum Computing
  • Robotics
  • Cybersecurity
  • Space Tech

Connect

Built with โค๏ธ & By - Anubhav

ยฉ 2026 Nextgen Blog by Anubhav. All rights reserved.

Privacy PolicyTerms of Service
Phase 05 ยท Production & GitOpsChapter 31 of 33
30.
Phase 05Read time ~15 minDifficulty intermediate

Kubernetes + CI/CD ๐Ÿš€

Warrior, this is where Kubernetes becomes part of a real software delivery system.

In this chapter
  • 01What is CI/CD?
  • 02CI โ€” Continuous Integration
  • 03CD โ€” Continuous Delivery / Deployment
  • 04Without CI/CD
  • 05With CI/CD
  • 06The complete pipeline
  • 07Example Node.js project
  • 08Dockerfile
  • 09Why do we need a container registry?
  • 10Image tagging
  • 11Better image strategy
  • 12GitHub Actions
  • 13CI should fail fast
  • 14Build Docker image in CI
  • 15Push to registry
  • 16Secrets in CI/CD
  • 17Modern cloud authentication
  • 18CI vs CD
  • 19CI
  • 20CD
  • 21Deploying Kubernetes from CI
  • 22Strategy 1 โ€” kubectl set image
  • 23Strategy 2 โ€” Update YAML
  • 24Strategy 3 โ€” Kustomize
  • 25Strategy 4 โ€” Helm
  • 26A complete pipeline
  • 27Deployment verification
  • 28What if deployment fails?
  • 29Rollback
  • 30Kubernetes Deployment as the safety mechanism
  • 31Deployment pipeline with readiness
  • 32Blue-Green deployment
  • 33Canary deployment
  • 34Rolling vs Blue-Green vs Canary
  • 35CI/CD and environments
  • 36Git branch strategy
  • 37Environment-specific configuration
  • 38CI/CD + Helm
  • 39CI/CD + Kustomize
  • 40GitOps
  • 41Traditional CI/CD vs GitOps
  • 42Traditional
  • 43GitOps
  • 44Security in CI/CD
  • 45Dependency security
  • 46Container scanning
  • 47Secret scanning
  • 48Kubernetes manifest scanning
  • 49Don't deploy on every successful test blindly
  • 50Smoke testing
  • 51Production CI/CD architecture
  • 52What happens when deployment fails?
  • 53The relationship between everything you've learned
  • 54A practical GitHub Actions pipeline
  • 55Why Git SHA is useful
  • 56Image immutability
  • 57Interview questions
  • 58Q1. What is CI?
  • 59Q2. What is CD?
  • 60Q3. Why use a container registry?
  • 61Q4. Why avoid latest?
  • 62Q5. How does CI/CD deploy to Kubernetes?
  • 63Q6. How do you verify deployment?
  • 64Q7. What happens if a new version fails readiness?
  • 65Q8. CI/CD vs GitOps?
  • 66Best production flow to remember:
  • 67And the next evolution:
  • 68Next โ†’ Chapter 31 โ€” GitOps + Argo CD ๐Ÿ”„
In this chapter (68 sections)
01What is CI/CD?02CI โ€” Continuous Integration03CD โ€” Continuous Delivery / Deployment04Without CI/CD05With CI/CD06The complete pipeline07Example Node.js project08Dockerfile09Why do we need a container registry?10Image tagging11Better image strategy12GitHub Actions13CI should fail fast14Build Docker image in CI15Push to registry16Secrets in CI/CD17Modern cloud authentication18CI vs CD19CI20CD21Deploying Kubernetes from CI22Strategy 1 โ€” kubectl set image23Strategy 2 โ€” Update YAML24Strategy 3 โ€” Kustomize25Strategy 4 โ€” Helm26A complete pipeline27Deployment verification28What if deployment fails?29Rollback30Kubernetes Deployment as the safety mechanism31Deployment pipeline with readiness32Blue-Green deployment33Canary deployment34Rolling vs Blue-Green vs Canary35CI/CD and environments36Git branch strategy37Environment-specific configuration38CI/CD + Helm39CI/CD + Kustomize40GitOps41Traditional CI/CD vs GitOps42Traditional43GitOps44Security in CI/CD45Dependency security46Container scanning47Secret scanning48Kubernetes manifest scanning49Don't deploy on every successful test blindly50Smoke testing51Production CI/CD architecture52What happens when deployment fails?53The relationship between everything you've learned54A practical GitHub Actions pipeline55Why Git SHA is useful56Image immutability57Interview questions58Q1. What is CI?59Q2. What is CD?60Q3. Why use a container registry?61Q4. Why avoid latest?62Q5. How does CI/CD deploy to Kubernetes?63Q6. How do you verify deployment?64Q7. What happens if a new version fails readiness?65Q8. CI/CD vs GitOps?66Best production flow to remember:67And the next evolution:68Next โ†’ Chapter 31 โ€” GitOps + Argo CD ๐Ÿ”„

Until now, you've mostly learned:

Developer
   โ†“
Docker
   โ†“
Kubernetes
   โ†“
Application

Now we'll build:

Developer
   โ†“
Git
   โ†“
CI/CD
   โ†“
Docker Image
   โ†“
Container Registry
   โ†“
Kubernetes
   โ†“
Production

1. What is CI/CD?#

CI/CD stands for:

CI โ€” Continuous Integration#

Whenever developers push code:

Git Push
   โ†“
Build
   โ†“
Test
   โ†“
Quality checks

The goal is to catch problems early.


CD โ€” Continuous Delivery / Deployment#

After CI succeeds:

Build Image
   โ†“
Push Image
   โ†“
Deploy
   โ†“
Kubernetes

Depending on the organization, "CD" can mean:

  • Continuous Delivery โ€” production-ready changes are prepared, but deployment may require approval.
  • Continuous Deployment โ€” successful changes are automatically deployed.

2. Without CI/CD#

Imagine manually deploying:

Developer
   โ†“
docker build
   โ†“
docker push
   โ†“
kubectl set image
   โ†“
kubectl rollout status

This becomes painful.

Every deployment requires manual work.

And humans make mistakes.


3. With CI/CD#

Instead:

Developer
    โ”‚
    โ”‚ git push
    โ†“
GitHub
    โ”‚
    โ†“
CI/CD Pipeline
    โ”‚
    โ”œโ”€โ”€ Test
    โ”œโ”€โ”€ Build
    โ”œโ”€โ”€ Security Scan
    โ”œโ”€โ”€ Docker Build
    โ”œโ”€โ”€ Push Image
    โ””โ”€โ”€ Deploy
            โ”‚
            โ†“
        Kubernetes

You push code.

The pipeline handles the repetitive work.


4. The complete pipeline#

For your Node.js application:

                 Developer
                     โ”‚
                  git push
                     โ”‚
                     โ†“
                  GitHub
                     โ”‚
                     โ†“
              GitHub Actions
                     โ”‚
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ†“          โ†“          โ†“
        Test       Lint       Build
          โ”‚          โ”‚          โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ†“
                Docker Build
                     โ”‚
                     โ†“
              Container Registry
                     โ”‚
                     โ†“
                Kubernetes
                     โ”‚
                 Deployment
                     โ”‚
                     โ†“
                Rolling Update
                     โ”‚
                     โ†“
                  Pods

5. Example Node.js project#

Suppose:

node-api/
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ server.js
โ”‚
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ package-lock.json
โ”œโ”€โ”€ Dockerfile
โ””โ”€โ”€ k8s/
    โ”œโ”€โ”€ deployment.yaml
    โ””โ”€โ”€ service.yaml

Application:

const express = require("express");
 
const app = express();
 
app.get("/", (req, res) => {
  res.json({
    message: "Hello Kubernetes"
  });
});
 
app.get("/health", (req, res) => {
  res.json({
    status: "ok"
  });
});
 
app.listen(3000, "0.0.0.0", () => {
  console.log("Server running on port 3000");
});

6. Dockerfile#

FROM node:22-alpine
 
WORKDIR /app
 
COPY package*.json ./
 
RUN npm ci --omit=dev
 
COPY . .
 
EXPOSE 3000
 
CMD ["node", "src/server.js"]

Now:

Source code
    โ†“
Dockerfile
    โ†“
Docker image

7. Why do we need a container registry?#

Your CI server builds:

node-api:1.0.0

But Kubernetes needs to retrieve that image.

So:

CI
 โ†“
Docker Image
 โ†“
Container Registry
 โ†“
Kubernetes

Examples:

AWS      โ†’ ECR
Google   โ†’ Artifact Registry
Azure    โ†’ ACR
GitHub   โ†’ GHCR
Docker   โ†’ Docker Hub

8. Image tagging#

Never rely on:

latest

for production deployments.

Instead use:

node-api:1.0.0
node-api:1.0.1
node-api:1.1.0

or a Git commit SHA:

node-api:a84f92c

Even better, production systems can deploy immutable image digests:

node-api@sha256:...

Why?

Suppose:

node-api:latest

today means:

Version 1

Tomorrow someone pushes another image:

node-api:latest

Now the same tag points somewhere else.

That makes debugging and rollback harder.


9. Better image strategy#

Use:

Git commit
      โ†“
Docker image
      โ†“
Tag with commit SHA

For example:

node-api:8f31ac2

Then Kubernetes knows exactly which build you're running.

A common pattern is to use both:

node-api:1.5.0
node-api:8f31ac2

and deploy by immutable digest where appropriate.


10. GitHub Actions#

Let's use GitHub Actions as our CI/CD example.

Create:

.github/
โ””โ”€โ”€ workflows/
    โ””โ”€โ”€ deploy.yml

A basic CI workflow:

name: Node API CI
 
on:
  push:
    branches:
      - main
 
jobs:
  test:
    runs-on: ubuntu-latest
 
    steps:
      - name: Checkout
        uses: actions/checkout@v4
 
      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
 
      - name: Install dependencies
        run: npm ci
 
      - name: Run tests
        run: npm test

Now:

git push
   โ†“
GitHub
   โ†“
GitHub Actions
   โ†“
npm ci
   โ†“
npm test

11. CI should fail fast#

Suppose the test fails:

npm test
   โ†“
FAIL

Then:

Docker build โŒ
Deployment โŒ

You don't want broken code reaching production.

So:

Test
 โ†“
FAIL
 โ†“
STOP

This is fundamental CI behavior.


12. Build Docker image in CI#

Add:

- name: Build Docker image
  run: |
    docker build \
      -t node-api:${{ github.sha }} .

Now:

Git commit SHA
      โ†“
Docker tag

For example:

node-api:8e7f32a...

13. Push to registry#

Suppose you're using GHCR.

The general architecture becomes:

GitHub Actions
      โ†“
Docker Build
      โ†“
GHCR
      โ†“
Kubernetes

The workflow needs credentials/permissions to push.

Never write credentials directly into:

run: docker login ... --password mypassword

Use GitHub Actions secrets or supported workload identity/OIDC approaches.


14. Secrets in CI/CD#

Common secrets:

AWS credentials
Registry credentials
Kubernetes credentials
API keys
Database credentials

Do not put them in:

Git repository
Dockerfile
source code

Use:

GitHub Actions Secrets
OIDC / workload identity
Cloud secret managers

15. Modern cloud authentication#

A particularly important production pattern is:

GitHub Actions
       โ†“
OIDC
       โ†“
Cloud IAM
       โ†“
AWS / GCP / Azure

Instead of storing long-lived cloud access keys in GitHub.

For AWS, GitHub Actions can use OIDC to assume an IAM role.

Conceptually:

GitHub
   โ†“
OIDC identity
   โ†“
AWS IAM Role
   โ†“
ECR / EKS

This reduces long-lived credential exposure.


16. CI vs CD#

Separate the concepts.

CI#

Checkout
 โ†“
Install
 โ†“
Lint
 โ†“
Test
 โ†“
Build

CD#

Build image
 โ†“
Push registry
 โ†“
Update Kubernetes
 โ†“
Rollout
 โ†“
Verify

Combined:

CI
 โ†“
CD

17. Deploying Kubernetes from CI#

There are several strategies.

Strategy 1 โ€” kubectl set image#

For example:

kubectl set image deployment/node-api \
  node-api=registry.example.com/node-api:${GITHUB_SHA}

Then:

kubectl rollout status deployment/node-api

This is simple.


18. Strategy 2 โ€” Update YAML#

Your Deployment contains:

image: registry.example.com/node-api:1.0.0

CI changes it to:

image: registry.example.com/node-api:1.1.0

Then:

kubectl apply -f deployment.yaml

19. Strategy 3 โ€” Kustomize#

Since you've just learned Kustomize, this is a natural fit.

Production:

images:
  - name: registry.example.com/node-api
    newTag: "8f31ac2"

CI updates the image tag.

Then:

kubectl apply -k k8s/overlays/production

Architecture:

Git
 โ†“
CI
 โ†“
Build image
 โ†“
Registry
 โ†“
Update Kustomize image
 โ†“
kubectl apply -k
 โ†“
Kubernetes

20. Strategy 4 โ€” Helm#

You can also update:

image:
  repository: registry.example.com/node-api
  tag: "1.5.0"

Then:

helm upgrade node-api ./chart

So:

Kustomize

and:

Helm

both integrate naturally with CI/CD.


21. A complete pipeline#

Let's design one:

Developer
    โ”‚
    โ†“
git push
    โ”‚
    โ†“
GitHub
    โ”‚
    โ†“
GitHub Actions
    โ”‚
    โ”œโ”€โ”€ Checkout
    โ”œโ”€โ”€ npm ci
    โ”œโ”€โ”€ Lint
    โ”œโ”€โ”€ Unit tests
    โ”œโ”€โ”€ Security scan
    โ”œโ”€โ”€ Docker build
    โ””โ”€โ”€ Docker push
             โ”‚
             โ†“
       Container Registry
             โ”‚
             โ†“
       Update Kustomize
             โ”‚
             โ†“
       kubectl apply -k
             โ”‚
             โ†“
          Kubernetes
             โ”‚
             โ†“
       Rolling Deployment
             โ”‚
             โ†“
       Readiness probes
             โ”‚
             โ†“
           Success

22. Deployment verification#

Don't stop after:

kubectl apply

You need to verify.

Use:

kubectl rollout status deployment/node-api

If successful:

deployment "node-api" successfully rolled out

Then:

kubectl get pods

Then:

kubectl get svc

Then check application health.


23. What if deployment fails?#

Suppose the new image has a bug.

You might get:

CrashLoopBackOff

or:

Readiness probe failed

The pipeline should detect rollout failure.

For example:

kubectl rollout status deployment/node-api --timeout=5m

If it fails:

Deployment โŒ

Then you can rollback.


24. Rollback#

You've already learned:

kubectl rollout undo deployment/node-api

So:

v1
 โ†“
v2
 โ†“
v2 broken
 โ†“
rollback
 โ†“
v1

A CI/CD system should make this process controlled and observable.


25. Kubernetes Deployment as the safety mechanism#

Suppose you deploy:

v2

with:

readinessProbe:
  httpGet:
    path: /health
    port: 3000

If new Pods aren't ready:

v2 Pod
   โ†“
Readiness FAIL
   โ†“
Not ready
   โ†“
Service doesn't route normal traffic to it

This is why Chapter 14 and Chapter 24 were important.

CI/CD and Kubernetes features work together.


26. Deployment pipeline with readiness#

New image
   โ†“
Deployment
   โ†“
New Pod
   โ†“
Startup
   โ†“
Startup probe
   โ†“
Readiness probe
   โ†“
Ready
   โ†“
Service traffic

If readiness fails:

New Pod
   โ†“
NotReady
   โ†“
Traffic not sent normally

27. Blue-Green deployment#

Another deployment strategy.

Suppose:

Blue = v1
Green = v2

You run both:

              Service
                 โ”‚
                 โ†“
               Blue
                v1

Deploy green:

       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Service
       โ”‚
       โ”œโ”€โ”€ Blue v1
       โ”‚
       โ””โ”€โ”€ Green v2

Test green.

Then switch Service traffic:

              Service
                 โ”‚
                 โ†“
              Green
                v2

Blue remains available for rollback.


28. Canary deployment#

Instead of sending everyone to v2:

100% โ†’ v1

you might gradually shift traffic:

95% โ†’ v1
5%  โ†’ v2

then:

90% โ†’ v1
10% โ†’ v2

then:

50% โ†’ v1
50% โ†’ v2

then:

0% โ†’ v1
100% โ†’ v2

This reduces deployment risk when implemented with suitable traffic-routing tooling.


29. Rolling vs Blue-Green vs Canary#

Strategy Idea
Rolling Gradually replace old Pods
Blue-Green Run two environments and switch traffic
Canary Gradually shift traffic
Recreate Stop old before starting new

Simple mental model:

Rolling
v1 โ†’ v1/v2 โ†’ v2
Blue-Green
v1 + v2 โ†’ switch
Canary
v1 100% โ†’ 95/5 โ†’ 90/10 โ†’ 100% v2

30. CI/CD and environments#

You shouldn't necessarily deploy every branch directly to production.

A common structure:

feature branch
      โ†“
Pull Request
      โ†“
CI
      โ†“
Tests
      โ†“
merge main
      โ†“
staging
      โ†“
approval
      โ†“
production

Example:

Development
     โ†“
Staging
     โ†“
Production

31. Git branch strategy#

A simple model:

feature/*
    โ†“
Pull Request
    โ†“
main
    โ†“
Staging
    โ†“
Production

Or some teams use:

main
 โ†“
Production
 
feature/*
 โ†“
Preview environments

There isn't one universally correct branching model.

The important thing is that the deployment process is predictable.


32. Environment-specific configuration#

Never do:

if production:
    hardcoded password

Instead:

Kubernetes ConfigMap
Kubernetes Secret
External Secret Manager

For example:

Development
 โ†“
values-dev.yaml
 
Staging
 โ†“
values-staging.yaml
 
Production
 โ†“
values-prod.yaml

Or Kustomize:

base
 โ†“
dev overlay
staging overlay
production overlay

33. CI/CD + Helm#

Suppose:

helm/
โ””โ”€โ”€ node-api/
    โ”œโ”€โ”€ Chart.yaml
    โ”œโ”€โ”€ values.yaml
    โ””โ”€โ”€ templates/

CI builds:

node-api:1.5.0

Then:

helm upgrade --install node-api ./node-api \
  --set image.tag=1.5.0

Then:

kubectl rollout status deployment/node-api

Architecture:

CI
 โ†“
Docker
 โ†“
Registry
 โ†“
Helm
 โ†“
Kubernetes

34. CI/CD + Kustomize#

Alternatively:

CI
 โ†“
Docker
 โ†“
Registry
 โ†“
Kustomize
 โ†“
kubectl apply -k

Example:

images:
  - name: registry.example.com/node-api
    newTag: "1.5.0"

Then:

kubectl apply -k k8s/overlays/production

35. GitOps#

Now we reach a very important concept.

Traditional CI/CD:

CI
 โ†“
kubectl
 โ†“
Kubernetes

GitOps changes the model.

Git
 โ†“
Desired state
 โ†“
GitOps controller
 โ†“
Kubernetes

We'll study this deeply in Chapter 31 with Argo CD.

For now:

Git becomes the source of truth for the desired Kubernetes state.


36. Traditional CI/CD vs GitOps#

Traditional#

GitHub Actions
      โ”‚
      โ†“
kubectl apply
      โ”‚
      โ†“
Kubernetes

GitOps#

Git
 โ”‚
 โ”‚ desired state
 โ†“
Argo CD
 โ”‚
 โ”‚ reconcile
 โ†“
Kubernetes

This connects directly to Kubernetes' fundamental desired state + reconciliation model from Chapter 1.


37. Security in CI/CD#

A production pipeline should consider:

Dependency security#

npm audit

or specialized scanners.

Container scanning#

Scan:

Docker image

for vulnerabilities.

Secret scanning#

Detect accidentally committed:

API keys
passwords
tokens
private keys

Kubernetes manifest scanning#

Check for:

privileged: true
runAsRoot
excessive permissions

Tools vary by organization.


38. Don't deploy on every successful test blindly#

Imagine:

Developer pushes code
      โ†“
Tests pass
      โ†“
Production

This may be fine for some teams, but not all systems.

For critical production environments, you may require:

Tests
 โ†“
Security
 โ†“
Staging
 โ†“
Smoke tests
 โ†“
Approval
 โ†“
Production

39. Smoke testing#

After deployment:

Deployment
   โ†“
Health check
   โ†“
GET /
   โ†“
GET /health
   โ†“
Verify response

Example:

curl https://api.example.com/health

Expected:

{
  "status": "ok"
}

If it fails:

Deployment verification โŒ

40. Production CI/CD architecture#

A strong production pipeline can look like:

                         Git
                          โ”‚
                          โ†“
                    Pull Request
                          โ”‚
                          โ†“
                   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                   โ”‚ CI Pipeline โ”‚
                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ”‚
             โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
             โ†“            โ†“            โ†“
           Lint          Test       Security
             โ”‚            โ”‚            โ”‚
             โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ†“
                    Docker Build
                          โ†“
                  Container Scan
                          โ†“
                     Registry
                          โ†“
                       Staging
                          โ†“
                    Smoke Tests
                          โ†“
                    Approval
                          โ†“
                    Production
                          โ†“
                    Kubernetes
                          โ†“
                 Rolling/Canary
                          โ†“
                    Monitoring

41. What happens when deployment fails?#

Let's trace it.

New image
   โ†“
Deployment
   โ†“
Pod starts
   โ†“
Readiness probe
   โ†“
FAIL

Kubernetes:

Pod = NotReady

CI:

rollout status
      โ†“
timeout/failure

Pipeline:

Deployment failed

Then:

Rollback
   โ†“
Previous ReplicaSet
   โ†“
Healthy Pods

Monitoring should also alert the team.


42. The relationship between everything you've learned#

This is the most important architecture in the entire course so far:

                    Git
                     โ”‚
                     โ†“
                    CI
                     โ”‚
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ†“                     โ†“
       Testing                Docker
                                โ”‚
                                โ†“
                         Container Registry
                                โ”‚
                                โ†“
                           Kubernetes
                                โ”‚
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ†“             โ†“
                    Deployment       Service
                         โ”‚             โ”‚
                         โ†“             โ†“
                       Pods โ†โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ†“       โ†“        โ†“
                HPA    Probes   NetworkPolicy
                 โ”‚
                 โ†“
          Node Autoscaling
                 โ”‚
                 โ†“
               Nodes

Then:

Monitoring
    โ†“
Prometheus/Grafana
    โ†“
Alerts

and:

Logging
    โ†“
Centralized logs

43. A practical GitHub Actions pipeline#

Here's a simplified example.

name: Node API CI/CD
 
on:
  push:
    branches:
      - main
 
jobs:
 
  test:
    runs-on: ubuntu-latest
 
    steps:
      - name: Checkout
        uses: actions/checkout@v4
 
      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
 
      - name: Install
        run: npm ci
 
      - name: Test
        run: npm test
 
  build:
    needs: test
    runs-on: ubuntu-latest
 
    steps:
      - name: Checkout
        uses: actions/checkout@v4
 
      - name: Build Docker image
        run: |
          docker build \
            -t node-api:${{ github.sha }} .

Notice:

needs: test

This means:

test
 โ†“
success
 โ†“
build

If tests fail:

test โŒ
 โ†“
build doesn't run

44. Why Git SHA is useful#

Suppose production currently runs:

node-api:a81f2d1

Then new deployment:

node-api:b73ac92

If something breaks:

Which version?

Answer:

b73ac92

You can trace it back to Git.

This gives:

Git commit
    โ†•
Docker image
    โ†•
Kubernetes deployment

That's extremely valuable for debugging.


45. Image immutability#

Better:

node-api@sha256:abc123...

than relying only on:

node-api:latest

because the digest identifies the exact image content.

Production systems often use immutable image references or otherwise enforce immutable versioning.


46. Interview questions#

Q1. What is CI?#

Continuous Integration automatically builds and tests code changes so integration problems are detected early.

Q2. What is CD?#

Continuous Delivery/Deployment automates or streamlines delivery of validated changes to environments such as staging or production.

Q3. Why use a container registry?#

Kubernetes needs a reliable location from which nodes can pull container images.

Q4. Why avoid latest?#

Because it is mutable and makes deployments, auditing, reproducibility and rollback harder.

Q5. How does CI/CD deploy to Kubernetes?#

Typical flow:

Git
 โ†“
CI
 โ†“
Test
 โ†“
Docker build
 โ†“
Registry
 โ†“
Update manifest/Helm/Kustomize
 โ†“
kubectl/Argo CD
 โ†“
Kubernetes

Q6. How do you verify deployment?#

kubectl rollout status deployment/node-api

plus:

kubectl get pods
kubectl logs
health/smoke tests
monitoring

Q7. What happens if a new version fails readiness?#

The new Pod is not considered ready and normally won't receive regular Service traffic; the rollout can stall or fail depending on Deployment configuration.

Q8. CI/CD vs GitOps?#

Traditional:

CI โ†’ kubectl โ†’ Kubernetes

GitOps:

Git โ†’ GitOps controller โ†’ Kubernetes

๐Ÿง  Chapter 30 Cheat Sheet#

CI
 โ†“
Build + Test + Security
 
CD
 โ†“
Deliver/Deploy
 
Docker
 โ†“
Build image
 
Registry
 โ†“
Store image
 
Kubernetes
 โ†“
Run image
 
Deployment
 โ†“
Rolling update
 
Readiness
 โ†“
Safe traffic
 
Rollout status
 โ†“
Deployment verification
 
Rollback
 โ†“
Previous version

Best production flow to remember:#

Developer
   โ†“
Git Push
   โ†“
CI
   โ”œโ”€โ”€ Test
   โ”œโ”€โ”€ Lint
   โ”œโ”€โ”€ Security
   โ””โ”€โ”€ Build
          โ†“
      Docker Image
          โ†“
      Registry
          โ†“
       Deploy
          โ†“
     Kubernetes
          โ†“
   Readiness Probes
          โ†“
     Smoke Tests
          โ†“
      Production

And the next evolution:#

Traditional CI/CD
 
Git โ†’ CI โ†’ kubectl โ†’ Kubernetes
 
GitOps
 
Git โ†’ Argo CD โ†’ Kubernetes

Next โ†’ Chapter 31 โ€” GitOps + Argo CD ๐Ÿ”„#

This is one of the most important production Kubernetes concepts.

We'll learn:

  • What GitOps actually means
  • Why kubectl apply can become problematic at scale
  • Argo CD architecture
  • Desired state vs actual state
  • Reconciliation
  • Applications
  • Projects
  • Sync
  • Auto-sync
  • Self-healing
  • Drift detection
  • Rollback
  • Git repository structure
  • Helm + Argo CD
  • Kustomize + Argo CD
  • Multi-environment deployment
  • Complete GitOps architecture for your Next.js + Node.js + Redis + PostgreSQL system.

Finished this chapter?

Mark it as complete to track your mastery.

Previous ChapterChapter 29 โ€” Kubernetes on GCP & Azure โ˜๏ธNext ChapterChapter 31 โ€” GitOps + Argo CD ๐Ÿ”„
PrevNext