GitLab CI to Kubernetes: End-to-End Deploy Pipeline
Design a complete CI/CD pipeline from GitLab merge request to Kubernetes production with security gates and GitOps handoff.
Shipping to Kubernetes from GitLab CI is straightforward once you separate build automation from deployment reconciliation. This is the pipeline pattern I use for microservices teams.
Pipeline Overview
Separation of concerns
CI builds and scans artifacts. GitOps (ArgoCD) deploys them. Never run kubectl apply directly from CI in production.
GitLab CI Stages
stages:
- validate
- test
- security
- build
- publish
- deploy
variables:
IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
build:
stage: build
script:
- docker build -t $IMAGE .
- docker push $IMAGE
update-gitops:
stage: deploy
script:
- yq -i '.image.tag = strenv(CI_COMMIT_SHA)' environments/staging/values.yaml
- git commit -am "deploy: $CI_COMMIT_SHA to staging"
- git push
only:
- mainPromotion Flow
Key Practices
- Immutable tags — deploy by digest or commit SHA, never
latest - Environment branches — staging auto, production manual or tagged release
- Rollback — revert Git commit; ArgoCD reconciles automatically
- Secrets — External Secrets Operator, not CI variables in manifests
Conclusion
A clean GitLab → Registry → GitOps → Kubernetes flow gives you auditability, fast rollbacks, and a single source of truth in Git.
Related Articles
Trunk-Based Development with Modern CI/CD
Ship faster with short-lived branches, feature flags, and continuous integration on the main trunk.
Docker Multi-Stage Builds in CI/CD Pipelines
Shrink images, speed up pipelines, and improve security with multi-stage Dockerfiles in GitLab CI.
Vercel + GitLab: CI/CD for Next.js Portfolios
Combine GitLab for source control and optional CI checks with Vercel for zero-config Next.js deployment.