Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current context is not set Kubectl

Tags:

kubectl

Get the following output with Config view. Notice no "Current Context"

root@Bootstrap [ /etc ]# kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://192.168.10.50:6443
  name: tanzu-m01
contexts:
- context:
    cluster: tanzu-m01
    user: tanzu-m01-admin
  name: tanzu-m01-admin@tanzu-m01
current-context: ""
kind: Config
preferences: {}
users:
- name: tanzu-m01-admin
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
- name: tkgm-mgmt01-admin
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED

Using kubectl set-context >> shows context modified

root@Bootstrap [ /etc ]# kubectl config set-context tanzu-m01-admin@tanzu-m01
Context "tanzu-m01-admin@tanzu-m01" modified.

However on "kubectl config current-context" shows current-context not set

root@Bootstrap [ /etc ]# kubectl config current-context
error: current-context is not set

What am i missing ?

like image 273
Puneet Arora Avatar asked Jul 22 '26 00:07

Puneet Arora


1 Answers

The correct command is:

kubectl config use-context ${CONTEXT}

You can confirm this with:

kubectl config --help

set-context     Set a context entry in kubeconfig
use-context     Set the current-context in a kubeconfig file

kubectl config set-context set properties of the specified context:

kubectl config set-context ${CONTEXT} \
--cluster=${CLUSTER} \
--user=user_${USER} \
--namespace=${NAMESPACE}
like image 90
DazWilkin Avatar answered Jul 28 '26 15:07

DazWilkin