Engineering7 min read

DevOps Engineer

Designs production CI/CD pipelines, Dockerfiles, Kubernetes manifests, and GitHub Actions workflows - from zero to zero-downtime deployments.

DevOpsCI/CDDockerKubernetesGitHub Actionsinfrastructure

The DevOps Engineer designs CI/CD pipelines, container images, and deployment configurations that ship code reliably. It covers Dockerfile best practices, GitHub Actions workflow design, Kubernetes deployment patterns, secrets management, and the rollout strategies that enable zero-downtime deployments. All patterns are production-tested and account for build cache efficiency, image size, and least-privilege secrets handling.

Dockerfile Best Practices

# Multi-stage build - builder image installs deps; runtime image is minimal
FROM node:22-alpine AS builder
WORKDIR /app

# Copy lockfile and package.json first (layer cache - only re-runs on dep change)
COPY package.json package-lock.json ./
RUN npm ci --production=false

COPY . .
RUN npm run build

# ── Runtime stage ──────────────────────────────────────────────────────
FROM node:22-alpine AS runtime
WORKDIR /app

ENV NODE_ENV=production

# Non-root user - never run as root in production
RUN addgroup -S appgroup && adduser -S appuser -G appgroup

COPY package.json package-lock.json ./
RUN npm ci --production && npm cache clean --force

# Copy build output from builder
COPY --from=builder /app/dist ./dist

USER appuser
EXPOSE 3000

CMD ["node", "dist/server.js"]

GitHub Actions CI/CD Pipeline

name: CI/CD

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: '22', cache: 'npm' }
      - run: npm ci
      - run: npm run lint
      - run: npm test -- --coverage

  build-push:
    needs: test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v4
      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - uses: docker/build-push-action@v5
        with:
          push: true
          tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ github.sha }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

Kubernetes Deployment Pattern

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1          # Spin up 1 extra before killing old pods
      maxUnavailable: 0    # Zero-downtime: never fewer than desired pods
  selector:
    matchLabels: { app: my-app }
  template:
    metadata:
      labels: { app: my-app }
    spec:
      containers:
        - name: my-app
          image: ghcr.io/org/my-app:SHA    # Pin to SHA, not "latest"
          ports: [{ containerPort: 3000 }]
          env:
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef: { name: my-app-secrets, key: database-url }
          resources:
            requests: { cpu: 100m, memory: 128Mi }
            limits:   { cpu: 500m, memory: 512Mi }
          readinessProbe:
            httpGet: { path: /health, port: 3000 }
            initialDelaySeconds: 5
            periodSeconds: 10
          livenessProbe:
            httpGet: { path: /health, port: 3000 }
            initialDelaySeconds: 15
            periodSeconds: 20

Secrets Management

LevelToolUse case
Local dev.env file + dotenvDeveloper machines only - never commit
CI/CDGitHub Actions Secrets (encrypted at rest)Tokens, registry credentials, deploy keys
KubernetesKubernetes Secrets + Sealed Secrets or External Secrets OperatorApp config, DB credentials - sync from Vault/AWS SSM
CloudAWS Secrets Manager / GCP Secret ManagerProduction credentials with rotation, audit log, IAM access control

Zero-Downtime Deployment Checklist

  • Readiness probe passes before pod receives traffic - maxUnavailable: 0 keeps old pods alive until new ones are ready
  • Database migrations run before app deployment - backward-compatible migrations only (add columns, don't drop them until the next release)
  • Feature flags control new code paths - new code ships dark; flag enables it without a redeploy
  • Health endpoint at /health returns 200 for liveness, connection checks for readiness
  • PodDisruptionBudget prevents maintenance evictions from taking down all replicas simultaneously

Explore all agents

Browse the full library of specialized AI agents - Engineering, AI, Content, and Growth.