kubectl does not work with multiple clusters config

10/22/2018

I have ~/.kube/config with following content:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: REDACTED
    server: https://REDACTED.yl4.us-east-1.eks.amazonaws.com
  name: kubernetes-jenkins
- cluster:
    certificate-authority-data: REDACTED
    server: https://REDACTED.sk1.us-east-1.eks.amazonaws.com
  name: kuberntes-dev
contexts:
- context:
    cluster: kubernetes-dev
    user: aws-dev
  name: aws-dev
- context:
    cluster: kubernetes-jenkins
    user: aws-jenkins
  name: aws-jenkins
current-context: aws-dev
kind: Config
preferences: {}
users:
- name: aws-dev
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - token
      - -i
      - EKS_DEV_CLUSTER
      command: heptio-authenticator-aws
      env: null
- name: aws-jenkins
  user:
     exec:
       apiVersion: client.authentication.k8s.io/v1alpha1
       args:
       - token
       - -i
       - EKS_JENKINS_CLUSTER
       command: heptio-authenticator-aws
       env: null

But when I'm trying to kubectl cluster-info I get:

Kubernetes master is running at http://localhost:8080

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
The connection to the server localhost:8080 was refused - did you specify the right host or port?

As far as I understand something wrong in my kubeconfig, but I don't see what exactly. Also I tried to find any related issues, but with no luck.

Could you suggest me something?

Thanks.

-- Aleksandr Stasko
kubectl
kubernetes

2 Answers

10/22/2018

You need to choose the context that you'd like to use. More informantion on how use multiple clusters with multiple users here.

Essentially, you can view your current context (for the current cluster configured)

$ kubectl config current-context

To view, all the clusters configured:

$ kubectl config get-clusters

And to choose your cluster:

$ kubectl config use-context <cluster-name>

There are options to set different users per cluster in case you have them defined in your ~/kube/config file.

-- Rico
Source: StackOverflow

10/22/2018

Your cluster name has a typo in it (name: kuberntes-dev) compared with the reference in the context (cluster: kubernetes-dev)

-- Jordan Liggitt
Source: StackOverflow