Skip to main content
In this guide, we’ll walk through creating a Kubernetes Secret and deploying application manifests to the development namespace using GitLab CI/CD. You’ll learn how to integrate secret creation into your pipeline and verify a successful deploy.

1. Verify the Development Namespace

First, confirm the development namespace is clean:
No resources found in development namespace.
Always ensure you’re targeting the correct namespace before deploying to avoid unintended changes.

2. Initial CI Job Definition

Here’s a basic k8s_dev_deploy job from .gitlab-ci.yml:
At this stage, deployment will fail because the application requires a mongo-db-creds secret that doesn’t exist yet.

3. Required Manifests

Define the Kubernetes resources for your application. Below are two essential manifest examples:

Ingress

Deployment

The mongo-db-creds secret must include:
  • MONGO_URI
  • MONGO_USERNAME
  • MONGO_PASSWORD

4. Create Secret and Update CI Job

Incorporate secret creation into your pipeline before applying manifests:
Using --dry-run=client -o yaml ensures idempotent secret creation.

5. Pipeline Configuration

Define the overall GitLab pipeline, stages, and variables:
Include a containerization job if needed:
Once pushed, GitLab will visualize the pipeline:
The image shows a GitLab CI/CD pipeline interface for a NodeJS project named "Solar System," displaying completed jobs for containerization and deployment stages.

6. Inspect the Dev-Deploy Logs

Your dev-deploy job logs should look like this:

7. Verify Deployment Locally

Check all resources in development:
Retrieve the Ingress host:
Open the application in your browser (accept the self-signed certificate): http://solar-system-development.139.84.208.48.nip.io
The image shows a digital representation of the solar system with planets orbiting the sun, accompanied by a user interface for exploring the planets.
Search for a planet by number (e.g., 3 for Earth):
The image shows a webpage about the solar system, featuring an illustration of Earth and a description of the planet. There is a search interface for exploring planets.

8. Next Steps

To improve reliability, integrate health checks into your pipeline:
  • GET /live{"status":"live"}
  • GET /ready{"status":"ready"}, HTTP 200
These endpoints can be tested with tools like k6 or Postman CLI.

Watch Video