简体   繁体   中英

How to configure kubectl in kubernetes cluster

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.

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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM