5

I'm using rke to generate a Kubernetes cluster in a private cloud. It produces a kube_config_cluster.yml file. Is there a way to add this config to my $HOME/.kube/config file?

Without having the .kube/config set, when using kubectl, I have to pass the argument:

kubectl --kubeconfig kube_config_cluster.yml <command> 

Or set the KUBECONFIG environment variable.

export KUBECONFIG=kube_config_cluster.yml 
1
  • Look at the subcommands under kubectl config- they let you manipulate and switch between clusters and contexts (cluster + namespace + auth). Commented Mar 9, 2018 at 23:59

3 Answers 3

8

kubectl config merge command is not yet available. But you can achieve a config merge by running:

Command format:

KUBECONFIG=config1:config2 kubectl config view --flatten 

Example:

Merge a config to ~/.kube/config and write back to ~/.kube/config-new.yaml.

Do not pipe directly to the config file! Otherwise, it will delete all your old content!

KUBECONFIG=~/.kube/config:/path/to/another/config.yml kubectl config view --flatten > ~/.kube/config-new.yaml 

cp ~/.kube/config-new.yaml ~/.kube/config

Sign up to request clarification or add additional context in comments.

2 Comments

This will make ~/.kube/config unusable. Write to different file and then mv to config
UGH, I wish I read your comment before I tried this. It deleted my whole file
2

If kubectl can read that as a valid config file, you can just use that as your kubeconfig. So cp kube_config_cluster.yaml $HOME/.kube/config should work fine. From there it'll read that config file by default and you won't have to specify it.

Comments

-1

I generally use the below commands to see and change context, not too cluttered and easy to fire

  kubectl config current-context #show the current context in use kubectl config use-context context-name-you-want-to-use 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.