staging namespace and updating your pipeline to leverage the Agent’s built-in KUBECONFIG context.
- A configured GitLab Kubernetes Agent with
ci_accessenabled inconfig.yaml - Defined CI/CD variables:
DEV_KUBE_CONFIG,NAMESPACE,MONGO_*,DOCKER_USERNAME - The
stagingnamespace created on your cluster
1. Verify the Staging Namespace Is Empty
Confirm there are no existing resources instaging:

2. Review the Current Development Deploy Job
Our.gitlab-ci.yml defines a k8s_dev_deploy job that uses a self-managed KUBECONFIG. It builds the image, injects secrets, and applies manifests:
3. Connect the GitLab Kubernetes Agent
Inconfig.yaml, enable CI access so each job automatically receives the Agent’s kubeconfig:
$KUBECONFIG is populated by the Agent in every CI job.

4. Minimal Deploy Example
A concise example usingbitnami/kubectl to switch context:
5. Add the Staging Deploy Job
Copy thek8s_dev_deploy job, rename it to k8s_stage_deploy, and update it to use the Agent’s $KUBECONFIG. Remove custom kubeconfig logic. Add when: manual so it only runs on demand.
Ensure you have added
stage-deploy to the top-level stages list and set NAMESPACE: staging.6. Add Integration Tests for Staging
Verify your/live and /ready health endpoints:
7. Pipeline Visualization
Your CI pipeline now spans four stages (test, containerization, dev-deploy, stage-deploy) and includes manual promotion:
8. Manual Promotion in GitLab
Thek8s_stage_deploy job is set to manual:

9. Trigger the Manual Job
Navigate to CI/CD → Pipelines, then click the ▶️ icon next tok8s_stage_deploy. You can override variables before starting:

k8s_stage_deploy completes, k8s_stage_integration_testing will run automatically.
10. Inspect the Deployment Logs
Important log snippets include:staging.
11. Review CI/CD Environment Variables
In Settings → CI/CD, scope variables to your environments (e.g.,staging):

12. Validate Deployment in GitLab UI
The Environments dashboard now reflects your successful staging deploy:


13. Confirm Locally via kubectl
Finally, verify in your terminal:By leveraging the GitLab Kubernetes Agent, you’ve simplified authentication, enforced manual approvals for staging, and successfully deployed your application to the staging namespace.