Anything you do to Kubernetes twice should be automated. This walks the path from a manual install to a repeatable, pipeline-driven setup.
1. Install it reproducibly
# Spin up a local cluster with kind, then talk to it with kubectl
kind create cluster --name dev
kubectl cluster-info --context kind-dev
kubectl get nodes2. Describe the desired state
A Deployment plus Service with probes and resource limits.
apiVersion: apps/v1
kind: Deployment
metadata: { name: web }
spec:
replicas: 3
selector: { matchLabels: { app: web } }
template:
metadata: { labels: { app: web } }
spec:
containers:
- name: web
image: ghcr.io/acme/web:1.0
ports: [{ containerPort: 3000 }]
resources:
requests: { cpu: 100m, memory: 128Mi }
limits: { cpu: 500m, memory: 256Mi }
readinessProbe:
httpGet: { path: /healthz, port: 3000 }
---
apiVersion: v1
kind: Service
metadata: { name: web }
spec:
selector: { app: web }
ports: [{ port: 80, targetPort: 3000 }]3. Run it from CI
Set the new image and wait for the rollout inside a pipeline.
deploy:
stage: deploy
script:
- kubectl set image deploy/web web=ghcr.io/acme/web:$CI_COMMIT_SHA
- kubectl rollout status deploy/web --timeout=120s
rules:
- if: '$CI_COMMIT_BRANCH == "main"'Want senior help putting Kubernetes to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.