> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Understanding Deployment Pipeline

> This guide explains how to extend a CI/CD pipeline to include Kubernetes deployments, integration tests, and manual approval steps.

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

| Stage                                              | Description                                                         |
| -------------------------------------------------- | ------------------------------------------------------------------- |
| 1. Unit Testing                                    | Install dependencies, execute unit tests, and publish test reports. |
| 2. Code Coverage                                   | Generate and upload coverage metrics.                               |
| 3. Docker Containerization                         | Build a Docker image, validate locally, and push to a registry.     |
| 4. Kubernetes Deployment (Dev) + Integration Tests | Deploy manifests to dev cluster, verify via Ingress, and run tests. |
| 5. Manual Approval                                 | Pause the pipeline for stakeholder review before production.        |
| 6. Kubernetes Deployment (Prod) + Smoke Tests      | Deploy to prod cluster and perform smoke tests.                     |

***

## 1. Unit Testing

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

```bash theme={null}
npm install
npm test
# Download and publish test reports for CI dashboards
```

<Callout icon="lightbulb" color="#1CB2FE">
  Ensure your test reports (e.g., JUnit XML) are stored in a known directory so your CI tool can archive them.
</Callout>

***

## 2. Code Coverage

Measure code coverage to identify untested parts of the codebase.

```bash theme={null}
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.).

```bash theme={null}
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.

```bash theme={null}
# 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
```

<Callout icon="lightbulb" color="#1CB2FE">
  Use environment-specific `ConfigMap` or `Secret` manifests to configure your dev environment. Keep secrets encrypted (e.g., [Sealed Secrets](https://github.com/bitnami-labs/sealed-secrets)).
</Callout>

***

## 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.

<Callout icon="triangle-alert" color="#FF6B6B">
  Skipping this approval can lead to unverified changes hitting production. Always review test logs and integration results.
</Callout>

***

## 6. Deploy to Kubernetes (Prod) + Smoke Tests

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

```bash theme={null}
# 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

***

## Links and References

* [Kubernetes Basics](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/)
* [Docker Official Documentation](https://docs.docker.com/)
* [npm CLI Commands](https://docs.npmjs.com/cli/v7/)
* [Sealed Secrets by Bitnami](https://github.com/bitnami-labs/sealed-secrets/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/gitlab-ci-cd-architecting-deploying-and-optimizing-pipelines/module/df17ec22-8cda-4af7-af44-10f9f061d4a8/lesson/4069c393-95e0-4518-bea7-e7db1b2d2710" />
</CardGroup>
