While using this command for RBAC "kubectl config set-cluster test --server=https://127.0.0.1:52807"
the IP here is from the kind-cluster that I am running after which I use "kubectl config set-context test --cluster=test"
followed by required credentials & switch to the context by "kubectl config use-context test"
and I am in the test context but with the first command I am configuring the config file I got that but m I making a cluster within a cluster what you guys understand please help me clear my doubt what is it actually doing?
CodePudding user response:
kubectl config set-cluster
sets a cluster entry in your kubeconfig
file (usually found in $HOME/.kube/config
). The kubeconfig
file defines how your kubectl
is configured.
The cluster entry defines where kubectl
can find the kubernetes cluster to talk to. You can have multiple clusters defined in your kubeconfig
file.
kubectl config set-context
sets a context element, which is used to combine a cluster, namespace and user into a single element so that kubectl
has everything it needs to communicate with the cluster. You can have multiple contexts, for example one per kubernetes cluster that you're managing.
kubectl config use-context
sets your current context to be used in kubectl
.
So to walk through your commands:
kubectl config set-cluster test --server=https://127.0.0.1:52807
creates a new entry inkubeconfig
under theclusters
section with a cluster calledtest
pointing towardshttps://127.0.0.1:52807
kubectl config set-context test --cluster=test
creates a new context inkubeconfig
calledtest
and tells that context to point to a cluster calledtest
kubectl config use-context test
changes the the current context inkubeconfig
to a context calledtest
(which you just created).
More docs on kubectl config
and kubeconfig
: