Published on

Kubernetes: context was not found for specified context

Authors

In Kubernetes if you are pointing to a new config, then run a command using kubectl and get something similar to the below:


> kubectl cluster-info

Error in configuration: context was not found for specified context: default

This is caused by your config file not having a context with the given name that is assigned to current-context. In my case I did not have a default context defined:


apiVersion: v1

clusters:

- cluster:

    certificate-authority-data: abc

    server: https://1.2.3.4:567

  name: yourcluster

contexts:

- context:

    cluster: yourcluster

    user: admin

  name: yourcluster

current-context: default

kind: Config

preferences: {}

users:

- name: admin

  user:

    client-certificate-data: abc

    client-key-data: abc

On line 12 my current-context is set to default but I have no context defined with that name. To fix this I simply changed my current-context to yourcluster as in the below (line 12 again):


apiVersion: v1

clusters:

- cluster:

    certificate-authority-data: abc

    server: https://1.2.3.4:567

  name: yourcluster

contexts:

- context:

    cluster: yourcluster

    user: admin

  name: yourcluster

current-context: yourcluster

kind: Config

preferences: {}

users:

- name: admin

  user:

    client-certificate-data: abc

    client-key-data: abc