GitHub Actions

Continuous Deployment with GitHub Actions

Understand Deployment Usecase

In this guide, we’ll walk through our CI/CD pipeline stages and demonstrate how to deploy a Dockerized application to Kubernetes clusters. You’ll learn how to:

  • Build and test your code
  • Containerize with Docker
  • Deploy to a development cluster
  • Run integration tests
  • Promote to production after manual approval

Deployment Pipeline Overview

We’ve already completed:

StagePurpose
Unit TestingValidate code logic with npm test
Code CoverageMeasure test coverage using npm run coverage
Docker ContainerizationPackage the app into a Docker image

Next, the pipeline will:

  1. Push the Docker image to a container registry
  2. Deploy to a Kubernetes development environment
  3. Execute integration tests against the dev cluster
  4. Await manual approval
  5. Promote the same deployment to the production environment

Local Development Commands

Before diving into Kubernetes, run these commands locally to verify your application:

StepCommandDescription
Installnpm installInstall project dependencies
Testnpm testExecute unit tests
Coveragenpm run coverageGenerate code coverage report
Build Imagedocker build -t my-app:latest .Create a Docker image
Run Imagedocker run -p 3000:3000 my-app:latestLaunch the container on port 3000
Push Imagedocker push my-app:latestUpload the image to your registry
# Example: Build and run locally
npm install
npm test
npm run coverage
docker build -t my-app:latest .
docker run -p 3000:3000 my-app:latest
docker push my-app:latest

Deploying to Kubernetes

To deploy the Docker image, prepare these Kubernetes manifests:

  • Deployment: Defines Pods and ReplicaSets in k8s/deployment.yaml
  • Service: Exposes Pods internally via k8s/service.yaml
  • Ingress: Routes external HTTP traffic using k8s/ingress.yaml

Apply them in sequence:

kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
kubectl apply -f k8s/ingress.yaml

Integration Testing on Dev

Once the resources are live, validate the deployment:

curl http://dev.my-app.example.com/health

A 200 OK response confirms that the application is operating correctly in the development cluster.

Note

Ensure your Kubernetes context is set to the development cluster:

kubectl config use-context dev-cluster

Manual Approval Gate

Before proceeding to production, implement a manual approval step in your CI/CD workflow. This prevents unintentional releases.

Warning

An administrator must review the integration test results and approve the release.
Skipping this step can lead to unverified changes reaching production.

Production Deployment

After approval, deploy to the production cluster using the same manifests:

  1. Switch to the production context:
    kubectl config use-context prod-cluster
    
  2. Apply the manifests:
    kubectl apply -f k8s/deployment.yaml
    kubectl apply -f k8s/service.yaml
    kubectl apply -f k8s/ingress.yaml
    
  3. Run production integration tests:
    curl http://my-app.example.com/health
    

Optionally, configure post-deployment alerts or monitoring checks to ensure reliability.

Next Steps

In the next lesson, we’ll cover Kubernetes fundamentals in depth and build automated workflow files for our CI/CD pipeline.

Watch Video

Watch video content

Previous
Project Status Meeting 3