GitLab CI/CD: Architecting, Deploying, and Optimizing Pipelines

Continuous Deployment with GitLab

Understanding Deployment Pipeline

In modern DevOps workflows, a well-structured CI/CD pipeline automates building, testing, and deploying your application. In this guide, we'll extend our existing pipeline—unit testing, code coverage, and Docker containerization—to include deployments to Kubernetes (development and production), integration tests, and a manual approval step.

Pipeline Stages Overview

StageDescription
1. Unit TestingInstall dependencies, execute unit tests, and publish test reports.
2. Code CoverageGenerate and upload coverage metrics.
3. Docker ContainerizationBuild a Docker image, validate locally, and push to a registry.
4. Kubernetes Deployment (Dev) + Integration TestsDeploy manifests to dev cluster, verify via Ingress, and run tests.
5. Manual ApprovalPause the pipeline for stakeholder review before production.
6. Kubernetes Deployment (Prod) + Smoke TestsDeploy to prod cluster and perform smoke tests.

1. Unit Testing

First, install project dependencies and run your unit tests to catch regressions early.

npm install
npm test
# Download and publish test reports for CI dashboards

Note

Ensure your test reports (e.g., JUnit XML) are stored in a known directory so your CI tool can archive them.


2. Code Coverage

Measure code coverage to identify untested parts of the codebase.

npm install
npm run coverage
# Upload coverage report (e.g., Istanbul/nyc) to your coverage service

3. Docker Containerization

Package the application into a Docker image, verify it locally, then push to your registry (Docker Hub, AWS ECR, etc.).

docker build -t your-app:latest .
docker run --rm your-app:latest
docker push your-app:latest

4. Deploy to Kubernetes (Dev) + Integration Tests

Apply your Kubernetes manifests to the development namespace, then validate functionality through the Dev Ingress.

# Deploy to dev namespace
kubectl apply -f k8s/deployment.yaml   --namespace=dev
kubectl apply -f k8s/service.yaml      --namespace=dev
kubectl apply -f k8s/ingress.yaml      --namespace=dev

# Verify Ingress endpoint
kubectl get ingress --namespace=dev
curl https://dev.your-domain.com/healthz

Note

Use environment-specific ConfigMap or Secret manifests to configure your dev environment. Keep secrets encrypted (e.g., Sealed Secrets).


5. Manual Approval

Introduce a manual gate to ensure that a team lead or QA engineer reviews the dev deployment results before promoting to production.

Warning

Skipping this approval can lead to unverified changes hitting production. Always review test logs and integration results.


6. Deploy to Kubernetes (Prod) + Smoke Tests

Upon approval, deploy the identical manifests to your production namespace and execute a quick smoke test.

# Deploy to prod namespace
kubectl apply -f k8s/deployment.yaml   --namespace=prod
kubectl apply -f k8s/service.yaml      --namespace=prod
kubectl apply -f k8s/ingress.yaml      --namespace=prod

# Verify Ingress and run smoke test
kubectl get ingress --namespace=prod
curl https://prod.your-domain.com/healthz

Next Steps

Before writing your CI/CD workflow (e.g., GitHub Actions, GitLab CI, Jenkins Pipeline), ensure all Kubernetes best practices are in place:

  • Namespace isolation for dev and prod
  • Resource requests and limits
  • Liveness and readiness probes
  • Secure handling of secrets

Watch Video

Watch video content

Previous
Project Status Meeting 3