How to configure kubectl in kubernetes cluster

12/12/2018

I have provisioned a kuberenetes cluster using this saltstack repo:

https://github.com/valentin2105/Kubernetes-Saltstack

Now, I am not able to configure my kubectl CLI to access the cluster. Is there a way to reset the credentials? Is there a way to get configure properly the .kube/config with the right context, user, credentials and cluster name retrieving the info from the servers?

I am new to kubernetes, so maybe I am missing something here.

-- bvcelari
kubectl
kubernetes

1 Answer

12/12/2018

To be able to set your cluster you can do as follow:

kubectl config set-cluster k8s-cluster --server=${CLUSTER} [--insecure-skip-tls-verify=true] 
  • --server=${CLUSTER} where ${CLUSTER} is your cluster adress
  • --insecure-skip-tls-verify=true is used if you are using http over https

Then you need to set your context ( depending on your kubernetes configuration

kubectl config set-context k8s-context --cluster=k8s-cluster --namespace=${NS}
  • --namespace=${NS} to specify the default namespace ( which skips the -n while typing kubectl commands for that namespace )

If you are using a RBAC, you might need to specify your user and pass your connection token or your login password:

For this advanced usage you can see the docs https://kubernetes.io/docs/reference/kubectl/cheatsheet/#kubectl-context-and-configuration

Now and finally to use your context you only have to:

kubectl config use-context ${USER}
-- hkhelil
Source: StackOverflow