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:
Stage | Purpose |
---|---|
Unit Testing | Validate code logic with npm test |
Code Coverage | Measure test coverage using npm run coverage |
Docker Containerization | Package the app into a Docker image |
Next, the pipeline will:
- Push the Docker image to a container registry
- Deploy to a Kubernetes development environment
- Execute integration tests against the dev cluster
- Await manual approval
- Promote the same deployment to the production environment
Local Development Commands
Before diving into Kubernetes, run these commands locally to verify your application:
Step | Command | Description |
---|---|---|
Install | npm install | Install project dependencies |
Test | npm test | Execute unit tests |
Coverage | npm run coverage | Generate code coverage report |
Build Image | docker build -t my-app:latest . | Create a Docker image |
Run Image | docker run -p 3000:3000 my-app:latest | Launch the container on port 3000 |
Push Image | docker push my-app:latest | Upload 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:
- Switch to the production context:
kubectl config use-context prod-cluster
- Apply the manifests:
kubectl apply -f k8s/deployment.yaml kubectl apply -f k8s/service.yaml kubectl apply -f k8s/ingress.yaml
- 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.
Links and References
Watch Video
Watch video content