Deployment Pipeline & DevOps
This skill covers the path to production. It ensures that code is automatically tested, built, containerized, and deployed reliably using modern DevOps practices.
When to Use
- Setting up CI/CD workflows (GitHub Actions, GitLab CI)
- Dockerizing an application for production
- Deploying to Kubernetes (Helm, Manifests)
- Configuring Infrastructure as Code (Terraform)
- Planning a deployment strategy (Blue/Green, Canary)
- Implementing GitOps with ArgoCD
- Troubleshooting build or deployment failures
1. CI/CD Principles
Pipeline Architecture
graph LR
Code[Code Commit] --> Build[Build & Lint]
Build --> Test[Test & Scan]
Test --> Artifact[Build Artifact]
Artifact --> DeployStg[Deploy Staging]
DeployStg --> DeployProd[Deploy Production]
Workflow Triggers
- Pull Request: Run fast checks (Lint, Unit Tests, Type Check).
- Push to Main: Run heavier checks (Integration Tests, Build, Deploy to Staging).
- Release/Tag: Deploy to Production.
Pipeline Stages
- Lint & Static Analysis:
eslint, prettier, tsc. Fail fast.
- Test: Unit tests (
vitest/jest) and Integration tests.
- Security Scan:
npm audit, trivy (container scan).
- Build:
npm run build or docker build (Multi-stage).
- Deploy: Update K8s manifest, upload to S3, or trigger serverless deploy.
Templates:
- GitHub Actions Workflow
- GitLab CI Pipeline
2. Containerization (Docker)
Dockerfile Best Practices
- Multi-Stage Builds: Separate build tools from runtime image.
- Base Images: Use
alpine or slim variants (e.g., node:20-alpine).
- Security: Run as non-root user (
USER node).
- Layers: Order instructions from least to most frequent change.
Templates:
- Node.js Dockerfile
- Python Dockerfile
3. Kubernetes & Orchestration
Essential Manifests
- Deployment: Defines replicas, rolling update strategy, and container spec.
- Service: Internal load balancer for pod discovery.
- Ingress: External access rule (HTTP/HTTPS).
- ConfigMap/Secret: Configuration injection (env vars).
Security Context
Always apply least privilege at the pod level:
securityContext:
runAsNonRoot: true
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
Resource Management
Always set requests and limits to ensure stability:
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "512Mi"
Templates:
- K8s Deployment
- Helm Values
4. Infrastructure as Code (IaC)
Use Terraform for reproducible infrastructure.
- State Management: Remote state (S3 + DynamoDB locking).
- Modules: Reusable components (VPC, EKS, RDS).
- Separation: Separate environments (dev, staging, prod) via workspaces or directory structure.
5. Deployment Strategies
| Strategy |
Description |
Pros |
Cons |
| Rolling |
Replace instances one by one |
Zero downtime, cheap |
Version mix during window |
| Blue/Green |
Stand up parallel env, switch router |
Instant rollback, safe |
Double resource cost |
| Canary |
Route % of traffic to new version |
Test in prod safe-ish |
Complex routing needed |
See Rollback Procedures for recovery protocols.
6. GitOps (ArgoCD)
- Single Source of Truth: Git repository contains all K8s manifests.
- Automated Sync: ArgoCD detects drift between Git and Cluster.
- Self-Healing: Automatically reverts manual changes to the cluster.
7. Security in Pipeline
- Secrets: Use GitHub Secrets/Vault. Never commit
.env or keys.
- Image Scanning: Scan for CVEs before pushing registry.
- Least Privilege: CI tokens should have minimal scopes.
Implementation Checklist
Pre-Deployment
Deployment
Post-Deployment
Common Rationalizations
| Rationalization |
Reality |
| "I'll add the health check later" |
If the deploy succeeds but the app is broken, you won't know until users complain. Add it before deploy. |
| "Staging is overkill for this change" |
The changes that skip staging are the ones that break production. |
| "I'll set up rollback if we need it" |
You need rollback when you're panicking. Set it up when you're calm. |
| "The secrets are fine in the env file for now" |
.env files get committed. Use secrets management from the start. |
| "I don't need resource limits for a small app" |
Without limits, a memory leak takes down the node. Limits are cheap insurance. |
See Troubleshooting Guide for common issues.
1---2name: deployment-pipeline3description: Use when setting up CI/CD workflows (GitHub Actions, GitLab CI), Dockerizing applications, deploying to Kubernetes, configuring Infrastructure as Code (Terraform), or planning deployment strategies (Blue/Green, Canary). Covers containerization, GitOps, and pipeline security.4---56# Deployment Pipeline & DevOps78This skill covers the **path to production**. It ensures that code is automatically tested, built, containerized, and deployed reliably using modern DevOps practices.910## When to Use1112- Setting up CI/CD workflows (GitHub Actions, GitLab CI)13- Dockerizing an application for production14- Deploying to Kubernetes (Helm, Manifests)15- Configuring Infrastructure as Code (Terraform)16- Planning a deployment strategy (Blue/Green, Canary)17- Implementing GitOps with ArgoCD18- Troubleshooting build or deployment failures1920## 1. CI/CD Principles2122### Pipeline Architecture2324```mermaid25graph LR26 Code[Code Commit] --> Build[Build & Lint]27 Build --> Test[Test & Scan]28 Test --> Artifact[Build Artifact]29 Artifact --> DeployStg[Deploy Staging]30 DeployStg --> DeployProd[Deploy Production]31```3233### Workflow Triggers3435- **Pull Request**: Run fast checks (Lint, Unit Tests, Type Check).36- **Push to Main**: Run heavier checks (Integration Tests, Build, Deploy to Staging).37- **Release/Tag**: Deploy to Production.3839### Pipeline Stages40411. **Lint & Static Analysis**: `eslint`, `prettier`, `tsc`. Fail fast.422. **Test**: Unit tests (`vitest/jest`) and Integration tests.433. **Security Scan**: `npm audit`, `trivy` (container scan).444. **Build**: `npm run build` or `docker build` (Multi-stage).455. **Deploy**: Update K8s manifest, upload to S3, or trigger serverless deploy.4647> **Templates**:48>49> - [GitHub Actions Workflow](templates/github-actions-ci.yml)50> - [GitLab CI Pipeline](templates/gitlab-ci.yml)5152## 2. Containerization (Docker)5354### Dockerfile Best Practices5556- **Multi-Stage Builds**: Separate build tools from runtime image.57- **Base Images**: Use `alpine` or `slim` variants (e.g., `node:20-alpine`).58- **Security**: Run as non-root user (`USER node`).59- **Layers**: Order instructions from least to most frequent change.6061> **Templates**:62>63> - [Node.js Dockerfile](templates/Dockerfile.node)64> - [Python Dockerfile](templates/Dockerfile.python)6566## 3. Kubernetes & Orchestration6768### Essential Manifests6970- **Deployment**: Defines replicas, rolling update strategy, and container spec.71- **Service**: Internal load balancer for pod discovery.72- **Ingress**: External access rule (HTTP/HTTPS).73- **ConfigMap/Secret**: Configuration injection (env vars).7475### Security Context7677Always apply least privilege at the pod level:7879```yaml80securityContext:81 runAsNonRoot: true82 readOnlyRootFilesystem: true83 allowPrivilegeEscalation: false84```8586### Resource Management8788Always set requests and limits to ensure stability:8990```yaml91resources:92 requests:93 cpu: "100m"94 memory: "128Mi"95 limits:96 cpu: "500m"97 memory: "512Mi"98```99100> **Templates**:101>102> - [K8s Deployment](templates/k8s-deployment.yaml)103> - [Helm Values](templates/helm-values.yaml)104105## 4. Infrastructure as Code (IaC)106107Use Terraform for reproducible infrastructure.108109- **State Management**: Remote state (S3 + DynamoDB locking).110- **Modules**: Reusable components (VPC, EKS, RDS).111- **Separation**: Separate environments (dev, staging, prod) via workspaces or directory structure.112113## 5. Deployment Strategies114115| Strategy | Description | Pros | Cons |116| :------------- | :----------------------------------- | :--------------------- | :------------------------ |117| **Rolling** | Replace instances one by one | Zero downtime, cheap | Version mix during window |118| **Blue/Green** | Stand up parallel env, switch router | Instant rollback, safe | Double resource cost |119| **Canary** | Route % of traffic to new version | Test in prod safe-ish | Complex routing needed |120121> See [Rollback Procedures](rollback-procedures.md) for recovery protocols.122123## 6. GitOps (ArgoCD)124125- **Single Source of Truth**: Git repository contains all K8s manifests.126- **Automated Sync**: ArgoCD detects drift between Git and Cluster.127- **Self-Healing**: Automatically reverts manual changes to the cluster.128129## 7. Security in Pipeline130131- **Secrets**: Use GitHub Secrets/Vault. Never commit `.env` or keys.132- **Image Scanning**: Scan for CVEs before pushing registry.133- **Least Privilege**: CI tokens should have minimal scopes.134135## Implementation Checklist136137### Pre-Deployment138139- [ ] **Linter & Tests** pass on PR?140- [ ] **Security Scan** (trivy/dependabot) is clean?141- [ ] **Secrets** injected securely (Vault/K8s Secrets)?142- [ ] **Dockerfile** uses multi-stage & non-root user?143144### Deployment145146- [ ] **Env Vars** validated on startup?147- [ ] **Readiness/Liveness Probes** configured?148- [ ] **Resource Limits** defined?149150### Post-Deployment151152- [ ] **Health Checks** return 200 OK?153- [ ] **Logs** show no critical startup errors?154- [ ] **Alerts** configured for high error rates?155156## Common Rationalizations157158| Rationalization | Reality |159|---|---|160| "I'll add the health check later" | If the deploy succeeds but the app is broken, you won't know until users complain. Add it before deploy. |161| "Staging is overkill for this change" | The changes that skip staging are the ones that break production. |162| "I'll set up rollback if we need it" | You need rollback when you're panicking. Set it up when you're calm. |163| "The secrets are fine in the env file for now" | `.env` files get committed. Use secrets management from the start. |164| "I don't need resource limits for a small app" | Without limits, a memory leak takes down the node. Limits are cheap insurance. |165166> See [Troubleshooting Guide](troubleshooting.md) for common issues.