GitLab agent for Rancher2

Igor Kravchenko
It_challenge
Published in
3 min readOct 6, 2022

How to add GitLab agent for Kubernetes cluster in Rancher2?

Add new empty .gilab/agents/uniqname/config.yaml file like this:

Commit and push

Connect new agent:

Step 1
Step 2
Success added agent, don’t close

Now you need to add new app in your project in Rancher.

Add new catalog in “Manage Catalogs” in Rancher.

URL for chart is https://charts.gitlab.io/

Launch new app in project

Choose gitlab-agent

Fill “Variable” from agent settings and launch app

image.tag=v15.4.0config.token=n…………Kwconfig.kasAddress=wss://kas.gitlab.com
Add agent with settings from agent

Result:

Add new variable in CI/CD

Settings → CI/CD → Variables

KUBE_CONTEXT = group/project/agentname

Change your Kubernetes deploy in .yaml

.kubic_job: &kubic_job
image:
name: "registry.gitlab.com/gitlab-org/cluster-integration/cluster-applications:v1.6.1"
before_script:
- chmod 400 "$KUBECONFIG" # Workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/327912
- gl-use-kube-context

And example work:

deploy_test:
<<: *kubic_job
stage: test
variables:
KUBE_NAMESPACE: "gitlab-agent"
script:
- kubectl config get-contexts
- kubectl version

Push gitlab config. Finish.

Thank you for reading!

Share and try my player for Apple Music — meows.app

--

--