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:
<!-- begin snippet: js hide: false console: true babel: false --><!-- language: lang-html -->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
<!-- end snippet -->Could someone help me in resolving this issue
I've bumped into the same issue when installing rancher on K3s, setting KUBECONFIG helped.
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
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
Some good answers here specifying how to fix the problem. Here's a passage from the excellent O'Reilly book "Learning Helm" that gives insight into why this is error is happening:
"Working with Kubernetes Clusters Helm interacts directly with the Kubernetes API server. For that reason, Helm needs to be able to connect to a Kubernetes cluster. Helm attempts to do this automatically by reading the same configuration files used by kubectl (the main Kubernetes command-line client).
Helm will try to find this information by reading the environment variable $KUBECONFIG. If that is not set, it will look in the same default locations that kubectl looks in (for example, $HOME/.kube/config on UNIX, Linux, and macOS).
You can also override these settings with environment variables (HELM_KUBECONTEXT) and command-line flags (--kube-context). You can see a list of environment variables and flags by running helm help. The Helm maintainers recommend using kubectl to manage your Kubernetes credentials and letting Helm merely autodetect these settings. If you have not yet installed kubectl, the best place to start is with the official Kubernetes installation documentation."
-Learning Helm by Matt Butcher, Matt Farina, and Josh Dolitsky (O’Reilly). Copyright 2021 Matt Butcher, Innovating Tomorrow, and Blood Orange, 978-1-492-08365-8.
Update helm
helm repo update
Check
kubectl get all