<p>I have this config file</p>

<pre><code>apiVersion: v1
clusters:
- cluster:
    server: [REDACTED] // IP of my cluster
  name: staging
contexts:
- context:
    cluster: staging
    user: ""
  name: staging-api
current-context: staging-api
kind: Config
preferences: {}
users: []
</code></pre>

<p>I run this command</p>

<pre><code>kubectl config --kubeconfig=kube-config use-context staging-api
</code></pre>

<p>I get this message</p>

<pre><code>Switched to context "staging-api".
</code></pre>

<p>I then run</p>

<pre><code>kubectl get pods
</code></pre>

<p>and I get this message</p>

<pre><code>The connection to the server localhost:8080 was refused - did you specify the right host or port?
</code></pre>

<p>As far as I can tell from the docs </p>

<p><a href="https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/" rel="noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/</a></p>

<p>I'm doing it right. Am I missing something?</p>

praks5432
<p>Yes, Try the following steps to access the kubernetes cluster. This steps assumes that you have your k8s certificates in /etc/kubernetes.</p>

<p>You need to setup the cluster name, Kubeconfig, User and Kube cert file in following variables and then simply run those commands:</p>

<pre><code>CLUSTER_NAME="kubernetes"
KCONFIG=admin.conf
KUSER="kubernetes-admin"
KCERT=admin

cd /etc/kubernetes/

$ kubectl config set-cluster ${CLUSTER_NAME} \
  --certificate-authority=pki/ca.crt \
  --embed-certs=true \
  --server=https://${KUBERNETES_PUBLIC_ADDRESS}:6443 \
  --kubeconfig=${KCONFIG}

$ kubectl config set-credentials kubernetes-admin \
  --client-certificate=admin.crt \
  --client-key=admin.key \
  --embed-certs=true \
  --kubeconfig=/etc/kubernetes/admin.conf

$ kubectl config set-context ${KUSER}@${CLUSTER_NAME} \
  --cluster=${CLUSTER_NAME} \
  --user=${KUSER} \
  --kubeconfig=${KCONFIG}

$ kubectl config use-context ${KUSER}@${CLUSTER_NAME} --kubeconfig=${KCONFIG}
$ kubectl config view --kubeconfig=${KCONFIG}
</code></pre>

<p>After this you will be able to access the cluster. Hope this helps.</p>
