Rancher 2.x with Gitlab

Hi everyone,

Im getting some trouble with integration of gitlab and rancher.
Im trying to integrate gitlab k8’s feature, but im getting error when i try to deploy.

All components had been installed correctly (helm, ingress, certmanager…etc) but when i try to run the pipeline and deploy i get the error.
The namespace was created in rancher with that config.

I need help to understand this problem.

Thanks
Diogo Marcelo

Hello Diego,

You are following the AutoDevOps template from Gitlab.

You have to know that you need to put all the necessary variables available for your jobs to succeed like an kubernetes integration per project.

Or you can tweak it a bit to fit your need in a smallest way.

Recently i managed to have an image update on a deployement using another docker image with Rancher_url et Rancher_token (for example) in order to first log into the rancher than to run my kubectl command.
I used this link from Stackoverflow as reference than i build two new function on the gitlab-ci.yml file named rancher_connect and rancher_update.

function rancher_connect() { if [[ "$RANCHER_API_TOKEN" && "$RANCHER_SERVER_URL" && "$RANCHER_SERVER_CONTEXT" ]]; then echo "Logging to Rancher with CI credentials..." rancher login "$RANCHER_SERVER_URL" -t "$RANCHER_API_TOKEN" --context "$RANCHER_SERVER_CONTEXT" echo "" else echo "Error during login - check that you have variables set on the project level" fi }

function rancher_update() {
rancher kubectl YOUR STUFF HERE (from a file or full command line)
sleep 15
rancher kubectl YOUR STUFF HERE (from a file or full command line)
}


update_ressources:
stage: deploy
image: diemscott/rancher-cli-k8s:v2.0.2
allow_failure: true
script:
- rancher_connect
- rancher_update
only:
- branches


Remember that it’s only working for my use case you might need to adapt it to yours.

I hope it was helpful and wish you an good week-end.

Zwordi

Hi, that solutions doesn’t work for me, i pass project id in context, like “c-42fm9:p-gdr2q”, if i don’t pass context fail with a message showing me the list of projects…anyone can help me please.

My use case is using this inside a .gitlab-ci.yml, like this:

  • rancher login $SERVER --token $TOKEN --context $CONTEXT
    • rancher kubectl apply -f k8s/secret-container-registry.yml
    • rancher kubectl apply -f k8s/ms-deployment.yml

Thanks a lot