This directory contains the configuration and manifests to deploy a GitLab Runner in a Kubernetes cluster using native Kubernetes resources like Deployments, ConfigMaps, Services, and RBAC.
gitlab-runner/
├── configmap.yaml # ConfigMap containing the GitLab Runner configuration (config.toml)
├── deployment.yaml # Deployment manifest for GitLab Runner
├── service.yaml # Service for exposing Prometheus metrics
├── rbac.yaml # Role and RoleBinding for GitLab Runner permissions
└── README.md
Prerequisites A Kubernetes cluster with kubectl configured. A valid GitLab instance and registration token. Permissions to create Kubernetes resources in the gitlab-runner namespace. Deployment Steps
If the gitlab-runner namespace doesn’t exist, create it:
kubectl create namespace gitlab-runner
The rbac.yaml file grants the GitLab Runner the necessary permissions to manage jobs and interact with Kubernetes resources:
kubectl apply -f rbac.yaml -n gitlab-runner
The configmap.yaml contains the config.toml configuration for the GitLab Runner:
kubectl apply -f configmap.yaml -n gitlab-runner
Apply the deployment.yaml to create the GitLab Runner pod:
kubectl apply -f deployment.yaml -n gitlab-runner
The service.yaml exposes the Prometheus metrics on port 9252 for monitoring:
kubectl apply -f service.yaml -n gitlab-runner
Monitoring the GitLab Runner Check the Pod Status
kubectl get pods -n gitlab-runner
View Logs for Troubleshooting
kubectl logs <pod-name> -n gitlab-runner
To access Prometheus metrics locally:
kubectl port-forward svc/gitlab-runner-metrics 9252:9252 -n gitlab-runner
Then visit: http://localhost:9252/metrics
To remove all resources related to the GitLab Runner:
kubectl delete -f rbac.yaml -n gitlab-runner
kubectl delete -f configmap.yaml -n gitlab-runner
kubectl delete -f deployment.yaml -n gitlab-runner
kubectl delete -f service.yaml -n gitlab-runner
Liveness and Readiness Probes: Add health checks in the deployment.yaml to monitor the runner's health. GitOps Integration: Use GitOps tools like ArgoCD or Flux for automated deployments. CI/CD Pipeline: Setup GitLab CI/CD to validate and deploy Kubernetes manifests.
Maintainer: dheva Date: February 2025