Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Kubernetes cluster unreachable: Get "http://localhost:8080/version?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused

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

like image 875
merla Avatar asked Jul 24 '20 04:07

merla


3 Answers

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

export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
like image 141
VasekCh Avatar answered Oct 20 '22 08:10

VasekCh


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
like image 17
donbunkito Avatar answered Oct 20 '22 10:10

donbunkito


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.

like image 1
Keith Lyons Avatar answered Oct 20 '22 10:10

Keith Lyons