Is there a simple kubectl
command to take a kubeconfig
file (that contains a cluster+context+user) and merge it into the ~/.kube/config file as an additional context?
标签:
kubernetes
相关问题
- Microk8s, MetalLB, ingress-nginx - How to route ex
- How do I change the storage class of existing pers
- Use awslogs with kubernetes 'natively'
- Kubernetes coredns readiness probe failed
- Default certificate on Nginx-ingress
相关文章
- k8s 访问Pod 时好时坏
- Override env values defined in container spec
- How do I create a persistent volume claim with Rea
- How to obtain the enable admission controller list
- Difference between API versions v2beta1 and v2beta
- MountVolume.SetUp failed for volume “nfs” : mount
- How to save content of a configmap to a file with
- GKE does not scale to/from 0 when autoscaling enab
Do this:
You can then pipe that out to a new file if needed.
If you want to merge two config files in a single one
I found this way (not sure if this is the simplest)
Then copy the new config file where you want, also do not forget to
unset KUBECONFIG
the env variableUsing multiple
kubeconfigs
at onceSometimes you have a bunch of small kubeconfig files (e.g. one per cluster) but you want to use them all at once, with tools like
kubectl
or kubectx that work with multiple contexts at once.To do that, you need a “merged” kubeconfig file. In the section "Merging kubeconfig files" below, we explain how you can merge the kubeconfigs into a single file, but you can also merge them in-memory.
By specifying multiple files in
KUBECONFIG
environment variable, you can temporarily stitch kubeconfig files together and use them all inkubectl
.Merging kubeconfig files
Since kubeconfig files are structured YAML files, you can’t just append them to get one big kubeconfig file, but
kubectl
can help you merge these files:Extracting a context from a kubeconfig file
Let’s say you followed the before merging kubeconfig files and have a merged kubeconfig file in
$HOME/.kube/config
. Now you want to extract a cluster’s information to a portable kubeconfig file that only has the parts you need to connect to that cluster.Run:
In this command, we extract data about
context-1
from$HOME/.kube/config
toconfig-context-1
file. The--minify
flag allows us to extract only info about that context, and the--flatten
flag allows us to keep the credentials unredacted.ref article: https://ahmet.im/blog/mastering-kubeconfig/
If you find doing this a lot.. There is now also the 'krew' plugin package manager for kubectl. And there is a plugin for managing your ./kube/config file.
Using the 'konfig' plugin the syntax will be:
kubectl konfig import -s new.yaml
To install krew: https://github.com/kubernetes-sigs/krew