K8s Gitlab Integration
This page covers integrating GitLab with the Nautilus cluster to automatically deploy from GitLab to Kubernetes via CI/CD jobs.
GitLab agent for Kubernetes (recommended)
The GitLab agent for Kubernetes runs in your namespace and keeps an outgoing connection to GitLab at wss://gitlab.nrp-nautilus.io/-/kubernetes-agent/. CI/CD jobs of the projects you authorize get a kubectl context for your namespace, with no cluster credentials stored in GitLab.
In your project, create the agent configuration file
.gitlab/agents/<agent-name>/config.yamlon the default branch, and list the projects (or groups) whose CI/CD jobs may use the agent:ci_access:projects:- id: <group>/<project># groups:# - id: <group>Go to
Operate -> Kubernetes clusters, clickConnect a cluster, select<agent-name>and clickRegister. GitLab shows the agent token once, and ahelmcommand. Keep the token; from the command, note the version in--set image.tag=....Store the token in a Secret in your namespace, without leaving it in your shell history:
Terminal window read -rs AGENT_TOKEN # paste the token, then press Enterprintf %s "$AGENT_TOKEN" | kubectl -n <your_namespace> create secret generic gitlab-agent-token --from-file=token=/dev/stdinunset AGENT_TOKENInstall the agent with Helm. Don’t run the command GitLab shows as is: by default the chart binds the agent to
cluster-admin, which you can’t create on Nautilus. These settings give it rights in your namespace only:Terminal window helm repo add gitlab https://charts.gitlab.iohelm repo updatehelm upgrade --install <agent-name> gitlab/gitlab-agent \--namespace <your_namespace> \--set image.tag=<version from the GitLab command> \--set config.kasAddress=wss://gitlab.nrp-nautilus.io/-/kubernetes-agent/ \--set config.secretName=gitlab-agent-token \--set rbac.create=false \--set config.operational_container_scanning.enabled=false \--set serviceAccount.name=<agent-name>-gitlab-agent \--set replicas=1 \--set resources.requests.cpu=100m --set resources.requests.memory=128Mi \--set resources.limits.cpu=1 --set resources.limits.memory=256Mikubectl -n <your_namespace> create rolebinding <agent-name>-gitlab-agent \--clusterrole=admin --serviceaccount=<your_namespace>:<agent-name>-gitlab-agentBack in
Operate -> Kubernetes clusters, the agent shows asConnected.Use the agent from
.gitlab-ci.yml. The context name is the path of the project that holds the agent configuration, a colon, and the agent name:deploy:image:name: alpine/k8s:1.34.12entrypoint: [""]script:- kubectl config use-context <group>/<project>:<agent-name>- kubectl -n <your_namespace> get pods
CI/CD jobs act with the agent’s rights in your namespace, so anyone who can run a pipeline in an authorized project can change it. Authorize only projects you trust, and protect the branches that deploy.
Certificate-based integration (deprecated)
GitLab deprecated this method in favor of the agent. It still works on Nautilus for existing and new connections.
In your project, go to
Operate -> Kubernetes clusters, click the dropdown in the top right and selectConnect a cluster (certificate - deprecated)In the namespace create a GitLab service account:
kubectl create sa gitlab -n <your_namespace>Create the rolebinding for the service account:
kubectl create -f - << EOFapiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata:name: gitlabnamespace: <your_namespace>roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: adminsubjects:- kind: ServiceAccountname: gitlabnamespace: <your_namespace>EOFCreate a secret for the service account:
kubectl -n <your_namespace> apply -f - << EOFapiVersion: v1kind: Secretmetadata:name: gitlab-secretannotations:kubernetes.io/service-account.name: gitlabtype: kubernetes.io/service-account-tokenEOFGet the secret and Certificate Authority (CA) for the service account:
kubectl get secret -n your_namespace | grep gitlabkubectl get secret -n your_namespace <gitlab-secret-...> -o yamlecho <the token value> | base64 -d- this will give you the service token field valueecho <the CA value> | base64 -d- CAAPI URL - get from your cluster config file (
https://67.58.53.148:443)Uncheck
GitLab-managed cluster, enter the namespace intoProject namespace prefix (optional, unique)Click
Add kubernetes cluster
Now your cluster config will be available to tools like kubectl and helm to access your namespace. You can use this project as an example of how to automatically deploy a Helm application to your namespace and this one to automatically update the deployment image.

This work was supported in part by National Science Foundation (NSF) awards CNS-1730158, ACI-1540112, ACI-1541349, OAC-1826967, OAC-2112167, CNS-2100237, CNS-2120019.