12
votes

I am trying to deploy my application into Rancher managed kubernetes cluster RKE. I have created pipeline in gitlab using auto devops. But when the helm chart is trying to deploy I get this error. Error: Kubernetes cluster unreachable: Get "http://localhost:8080/version?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused

Below is my deploy script:

deploy:
  stage: deploy
  image: cdrx/rancher-gitlab-deploy
  only:
    - master
  script:
    - apk --no-cache add curl
    - curl -L https://get.helm.sh/helm-v3.3.0-rc.1-linux-amd64.tar.gz > helm.tar.gz
    - tar -zxvf helm.tar.gz
    - mv linux-amd64/helm /usr/local/bin/helm
    - helm install mychart ./mychart

Could someone help me in resolving this issue

2
what is the api url you gave in Gitlab autodevops setup ?Tarun Khosla
sounds like it doesn't know how to connect to your RKE clusterRico
Hello, have you managed to solve your issue with the help of Rico's comment?Dawid Kruk
I already configured the integration with RKE cluster by adding the api url,token of the cluster in gitlab project settings..not sure what else has to be configured.still getting same errormerla
The issue is fixed after explicitly adding environment variable to deploy script. Thanks for the helpmerla

2 Answers

14
votes

I've bumped into the same issue when installing rancher on K3s, setting KUBECONFIG helped.

export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
3
votes

This anwser solved the issue for me. If you're not running on microk8s, like me, omit the prefix

[microk8s] kubectl config view --raw > ~/.kube/config