GitLab CI/CD: Architecting, Deploying, and Optimizing Pipelines

Auto DevOps

Configuring AutoDevOps

Automate the CI/CD pipeline for your Node.js Solar System application with GitLab Auto DevOps. Since this repository contains only source code—no Dockerfile, Kubernetes manifests, or .gitlab-ci.yml—Auto DevOps will detect, build, test, and deploy your app end to end.

1. Importing the Project

  1. In GitLab, click + New projectImport projectRepo by URL.
  2. Paste your repository URL.
  3. Under Select namespace, pick demos. Set Project name to solar-system-auto-devops, choose Public, then click Create project.

The image shows a GitLab interface for importing a project, with fields for the repository URL, project name, and visibility settings. The project name is set to "Auto Dev Ops Project."

After import, you'll see your project without a Dockerfile, Kubernetes manifests, or .gitlab-ci.yml.

The image shows a GitLab interface for importing a new project, with fields for project name, URL, and visibility settings. The "Create project" button is highlighted.

The image shows a GitLab project interface for "Solar System AutoDevOps," displaying a list of files and their last commit details. The sidebar includes options for managing, planning, and deploying the project.

2. Reviewing Auto DevOps Documentation

GitLab’s Auto DevOps docs cover its features, stages, and integration points.

The image shows a GitLab documentation page about Auto DevOps, detailing its features and integration for software delivery processes. It includes a sidebar with navigation options and a section on Auto DevOps features.

2.1 Requirements

To build and test, no Kubernetes is needed. For automated deployment you must have:

  • Kubernetes cluster (v1.12+)
  • Wildcard DNS (e.g., nip.io)
  • GitLab Agent or cluster integration

The image shows a GitLab documentation page detailing the requirements for Auto DevOps, including steps for deployment preparation and options for deployment environments like Kubernetes and Amazon ECS.

2.2 Deployment Strategies

Auto DevOps supports:

StrategyDescription
Continuous Deployment to ProductionDeploy every successful pipeline to production
Continuous Deployment with CanaryGradual traffic shift for safer rollouts
Manual PromotionRequires explicit approval before production release

We’ll use Continuous Deployment to Production.

The image shows a GitLab documentation page detailing the "Auto DevOps deployment strategy," including different deployment strategies, their setup, and methodology. The sidebar contains navigation links for various related topics.

3. Enabling Auto DevOps

  1. Go to Settings > CI/CD > Auto DevOps.
  2. Toggle Enable Auto DevOps on.

You'll choose the deployment strategy after configuring your cluster.

4. Connecting a Kubernetes Cluster

  1. Navigate to Operate > Kubernetes clusters.
  2. Click Connect clusterCreate GitLab Agent.
  3. Name it auto-devops-agent and click Register.

The image shows a GitLab interface where a user is attempting to connect a Kubernetes cluster by selecting or creating an agent. A dropdown menu is visible with the option to create a new agent named "auto."

  1. Install the agent via Helm:
helm repo add gitlab https://charts.gitlab.io
helm repo update

helm upgrade --install auto-devops-agent gitlab/gitlab-agent \
  --namespace gitlab-agent-auto-devops-agent \
  --create-namespace \
  --set image.tag=v16.9.0-rc2 \
  --set config.token=glagent-rthdvds1zyCnME14AM8tdE5HVzy7iZJ9Avr~Bg_epySyxtbw \
  --set config.kasAddress=wss://kas.gitlab.com
  1. Confirm the namespace and pods:
kubectl get namespaces | grep gitlab-agent-auto-devops-agent
kubectl get pods -n gitlab-agent-auto-devops-agent

Once connected, your cluster appears in GitLab.

The image shows a GitLab interface displaying a connected Kubernetes cluster with details such as connection status, last contact, version, agent ID, and configuration. There's also a banner about Google Cloud Platform credits.

5. Configuring the Agent

Add the configuration at .gitlab/agents/auto-devops-agent/config.yaml:

user_access:
  access_as:
    agent: {}
  projects:
    - id: demos-group/solar-system-auto-devops

ci_access:
  projects:
    - id: demos-group/solar-system-auto-devops

Commit to main. GitLab will apply these permissions automatically.

6. Defining Environments

We’ll target two namespaces: staging and production.

  1. Staging
    • Go to Environments > New environment.
    • Name: staging
    • Kubernetes agent: auto-devops-agent
    • Namespace: All namespaces
    • Click Save.

The image shows a GitLab interface where a user is creating a new environment and selecting a namespace from a dropdown menu.

  1. Production

    • Create the namespace:
    kubectl create namespace production
    
    • In Environments > New environment:
      • Name: production
      • Agent: auto-devops-agent
      • Namespace: production
    • Click Save.

The image shows a GitLab interface for creating a new environment, with fields for name, external URL, GitLab agent, and Kubernetes namespace. There is a warning about authorization issues with accessing certain resources.

After setup, the Kubernetes overview lists your workloads:

The image shows a GitLab interface displaying a Kubernetes environment overview with a list of services, including details like name, namespace, type, cluster IP, and ports.

7. Setting CI/CD Variables

Retrieve your Ingress load balancer IP:

kubectl -n ingress-nginx get svc ingress-nginx-controller \
  -o json | jq -r '.status.loadBalancer.ingress[0].ip'

In Settings > CI/CD > Variables, add:

VariableValueEnvironment
KUBE_INGRESS_BASE_DOMAIN<LOAD_BALANCER_IP>.nip.ioall
KUBE_CONTEXTdemos-group/solar-system-auto-devops:auto-devops-agentall
KUBE_NAMESPACEstagingstaging
KUBE_NAMESPACEproductionproduction
PRODUCTION_REPLICAS10production

The image shows a GitLab CI/CD settings page with a list of variables, their values, environments, and actions. The sidebar includes navigation options like Settings, Deploy, and Monitor.

Tip

Variable names are case-sensitive. Double-check the values before running your pipeline.

Refer to the Auto DevOps CI/CD variables documentation for more options.

The image shows a GitLab documentation page about Auto DevOps deployment strategies, detailing different deployment methods and their setups. It includes a sidebar with navigation options and a table comparing deployment strategies.

8. Selecting Deployment Strategy

Back in Settings > CI/CD > Auto DevOps, choose Continuous Deployment to Production and click Save. A new pipeline will start automatically.

The image shows a GitLab CI/CD settings page for Auto DevOps, with options for deployment strategies and a notification about a new pipeline creation.

Go to CI/CD > Pipelines to track progress:

The image shows a GitLab pipeline interface with stages for build, test, production, and performance, displaying job dependencies and statuses.

Best Practice

Test feature branches before merging into main to avoid production issues.


Watch Video

Watch video content

Previous
What is Auto DevOps