Kubectl --context commands

Hi Team, i am using one of the kodekloud question to create service account and CR /CRB in specific cluster so they asked me to go to specific cluster , after moved to the cluster why we need to use the --context command in all the service account creation command and CR/CRB creation command, can you please clear my doubt.

kubectl config use-context cluster1 – i moved to some cluster and current context is cluster 1 now
kubectl --context cluster1 create serviceaccount deploy-cka20-arch — this is the answer they gave me in exam window , my doubt why we need to use the --context even we already moved to specify cluster

Once you’ve used kubectl config use-context cluster1, all of your commands will go to the apiserver at cluster1. So in that case, you don’t need to specify the --context in your commands – they will apply to the context cluster1.

1 Like

Exactly you are right , I also think the same and tried to create the SA/CR/CRB with out the --context command give in answer page, all created , but its failed when we are cross checking that’s why I have a doubt is it environment issue or something I am missing.