Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure kubectl with cluster information from a .conf file?

I have an admin.conf file containing info about a cluster, so that the following command works fine:

kubectl --kubeconfig ./admin.conf get nodes 

How can I config kubectl to use the cluster, user and authentication from this file as default in one command? I only see separate set-cluster, set-credentials, set-context, use-context etc. I want to get the same output when I simply run:

kubectl get nodes 
like image 308
Assen Kolov Avatar asked Nov 06 '16 08:11

Assen Kolov


People also ask

How do I set configuration file in kubectl?

By default, kubectl looks for a file named config in the $HOME/. kube directory. You can specify other kubeconfig files by setting the KUBECONFIG environment variable or by setting the --kubeconfig flag.

What is kubectl config file?

A kubeconfig file is a file used to configure access to Kubernetes when used in conjunction with the kubectl commandline tool (or other clients).

How does cluster communicate with kubectl?

When kubectl accesses the cluster it uses a stored root certificate and client certificates to access the server. (These are installed in the ~/. kube directory). Since cluster certificates are typically self-signed, it may take special configuration to get your http client to use root certificate.


2 Answers

Here are the official documentation for how to configure kubectl

http://kubernetes.io/docs/user-guide/kubeconfig-file/

You have a few options, specifically to this question, you can just copy your admin.conf to ~/.kube/config

like image 63
Gleeb Avatar answered Oct 03 '22 23:10

Gleeb


The best way I've found was to use an environment variable:

export KUBECONFIG=/path/to/admin.conf 
like image 45
stasdeep Avatar answered Oct 03 '22 22:10

stasdeep