Coder Social home page Coder Social logo

corneliusweig / konfig Goto Github PK

View Code? Open in Web Editor NEW
340.0 6.0 21.0 64 KB

konfig helps to merge, split or import kubeconfig files

License: Apache License 2.0

Shell 93.01% Makefile 6.99%
kubectl-plugins kubectl-plugin config kubeconfig merge kubernetes kubectl

konfig's Introduction

konfig

Latest GitHub release GitHub workflow status Written in Bash

konfig helps to merge, split or import kubeconfig files

Usage

Import a kubeconfig

konfig import --save new-cfg

Imports the config file new-cfg into the default kubeconfig at ~/.kube/config. To show the result without changing your kubeconfig, do

konfig import new-cfg

CAVEAT: due to how shells work, the following will lose your current ~/.kube/config

# WRONG, don't do this!
konfig import new-cfg > ~/.kube/config

Merge several kubeconfig files

konfig merge config1 config2 > merged-config

This variant creates a self-contained kubeconfig where all credentials are stored inline in the kubeconfig. If you want to preserve the structure and keep credentials separate, use --preserve-structure.

Extract a minimal kubeconfig for one or several contexts

This will extract a minimal kubeconfig with a single context minikube:

# extract context minikube from the default kubeconfig
konfig export minikube > minikube.config

# extract context minikube and docker-for-desktop from two input configs
konfig export minikube docker-for-desktop -k ~/.kube/other,~/dockercfg > local

Installation

There are several ways to install konfig. The recommended installation method is via krew.

Via krew

Krew is the kubectl plugin manager. If you have not yet installed krew, get it at https://github.com/kubernetes-sigs/krew. Then installation is as simple as

kubectl krew install konfig

The plugin will be available as kubectl konfig, see doc/USAGE for further details. You could also define an alias as well: alias konfig = 'kubectl konfig'

Manual

When using the binaries for installation, also have a look at USAGE.

OSX & Linux

curl -Lo konfig https://github.com/corneliusweig/konfig/raw/v0.2.6/konfig \
  && chmod +x konfig \
  && sudo mv -i konfig /usr/local/bin

Feel free to change the sudo mv to put konfig in some other location from your $PATH variable.

Windows

If you figure out how to run konfig on Windows, please send a PR with instructions.

konfig's People

Contributors

corneliusweig avatar keisukeyamashita avatar limonkufu avatar mcristina422 avatar rabattkarte avatar rajatjindal avatar stb1337 avatar yujunz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

konfig's Issues

slight delay in webrtc apps like discord

Have a bit of an delay in voice apps like discord, its between 0,2 and 0,5 seconds.
Is there a possibility to reduce this delay, e.g. assign more cpu oder gpu power?

How to install on Windows

Can you elaborate on the download instruction for Windows? I and downloading the konfig and putting it in my path variables as konfig.exe but it does not work
Capture
a
I have also tried to restart my computer but could not get it to work

Not compatible with Windows error

I am installing the plugin via krew and when I try kubectl konfig help I get the following error when running from cmd or powershell

fork/exec C:\Users\<username>\.krew\bin\kubectl-konfig.exe: This version of %1 is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.

I tried gitbash, but same issue happens if I run using kubectl konfig but it works if I run the exe directly.

import command fails when filename contains '-'

STR:

kubectl konfig import ingress-test-config.yaml

error: unrecognized flag "ingress-cluster.yaml"

It probably has something to do with how you get input flags.

-- Very happy that I found this tool! Thanks for creating it!

Actually...
kubectl konfig import -s ingresscluster.yaml
or kubectl konfig import --save ingresscluster.yaml

also fails with:
error: unrecognized flag "-s ingresscluster.yaml"

How to customize agnoster theme

Hey folks, this is just a share of info for those that want to use the agnoster oh my zsh theme. Make a copy of the theme file:
cp ~/.oh-my-zsh/themes/agnoster.zsh-theme ~/.oh-my-zsh/themes/agnoster-custom.zsh-theme

Then open the agnoster-custom.zsh-theme in your favorite code editor and replace the prompt_aws function by:

prompt_aws() {
  [[ -z "$ZSH_KUBECTL_PROMPT" || "$SHOW_AWS_PROMPT" = false ]] && return
  case "$ZSH_KUBECTL_PROMPT" in
    *-prod|*production*) prompt_segment red yellow  "kube: $ZSH_KUBECTL_PROMPT" ;;
    *) prompt_segment green black "kube: $ZSH_KUBECTL_PROMPT" ;;
  esac
}

Or if you want to remove the "/default" like me, it can be done with awk, in that manner:

prompt_aws() {
  [[ -z "$ZSH_KUBECTL_PROMPT" || "$SHOW_AWS_PROMPT" = false ]] && return
  case "$ZSH_KUBECTL_PROMPT" in
    *-prod|*production*) prompt_segment red yellow  "kube: $ZSH_KUBECTL_PROMPT" ;;
    *) prompt_segment green black "kube: $ZSH_KUBECTL_PROMPT" | awk 'BEGIN { ORS=" " }; { print substr( $0, 1, length($0)-8 ) }' ;;
  esac
}

That way, we are hi-jacking its AWS info functionality. Of course, don't forget to change the theme name in your .zshrc from agnoster to agnoster-custom!

ksnip_20211008-151702

Enjoy!

Plugin installed with krew gets a permission denied error to write to /dev/stdout

#37
The above issue is similar to mine, except instead of installing with snap, I'm installing with krew.

brice@brice-virtual-machine:~/Desktop$ kubectl konfig import -s kubeconfig-us-east-1kubectl
error: write /dev/stdout: permission denied

However, running kubectl konfig does not produce this issue. Since kubectl konfig version does not seem to be a command, i cannot provide that detail, however my environment is ubuntu with the following kubectl version output:

Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-16T02:43:21Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}

Here's the debug output

+ TMPFILES=()
+ declare -a TMPFILES
+ trap cleanup EXIT
+ main import -s kubeconfig-us-east-1kubectl krew
+ hash kubectl
+ KUBECTL=kubectl
+ [[ 4 -eq 0 ]]
+ case "$1" in
+ import_ctx -s kubeconfig-us-east-1kubectl krew
+ tmpcfgs=()
+ declare -a tmpcfgs
+ local tmpcfg
+ local tmpinputcfg=
+ local out=
+ local arg=
++ mktemp konfig_XXXXXX
+ tmpcfg=konfig_rj3LF8
+ TMPFILES+=("$tmpcfg")
+ tmpcfgs+=("$tmpcfg")
+ for OPT in "$@"
+ case $OPT in
+ out=/home/brice/.kube/config
+ shift
+ for OPT in "$@"
+ case $OPT in
+ for OPT in "$@"
+ case $OPT in
+ kubectl config view --raw
error: write /dev/stdout: permission denied
+ cleanup
+ [[ 1 -gt 0 ]]
+ rm -- konfig_rj3LF8```

New subcommand activate

The subcommand should open an inactive menu (eg fzf) where one can select the currently active kubeconfig files. The effect should be to export the KUBECONFIG=cfg1:cfg2 variable in the current shell. When given a flag (--save/-s) the setting should be persisted in a shell_profile file.

File content should not be expanded during import

kubectl konfig import --save ~/.kube/foo.config seems expanding the content of file which is not expected.

# foo.config
users:
- name: vault-user
  user:
    client-certificate: client.crt
    client-key: client

is imported as

users:
- name: vault-user
  user:
    client-certificate: <content of client.crt>
    client-key: <content of client>

This is not expected since the certs generated by vault are temporary. It would be better to import it as is (the filename).

Solve merge conflicts on duplicate data

When merging two contexts which reference the same user name (though different users) the resulting kubecfg drops one of those users and the corresponding context can not authenticate.

Suggestion: Detect duplicate user names (i.e. same name but different data) and rename them on import (e.g. to $context-$user).

Change semantics of "split"

Currently, "split" is an alias for "export". However, the connotation of split is more that the two outcomes have disjoint contexts instead of one being a subset of the other.

Maybe split should really do a split, so that the split out context is no longer contained in the input kubeconfig file.

TODO: work out how this should behave with multiple input kubeconfigs when KUBECONFIG=cfg1:cfg2....

Importing a config from a file without permission causes loss of ~/.kube/config content

Hello everyone,

I was trying to import the kubeconfig from /etc/rancher/k3s/k3s.yaml to my ~/.kube/config.

Unfortunately /etc/rancher/k3s/k3s.yaml was in 600 so I could not read it. Konfig edited my ~/.kube/config and had empty it.

My KUBECONFIG is now empty and I lost my access to clusters I had.

โžœ kubectl konfig import -s /etc/rancher/k3s/k3s.yaml
error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied 

Is that a miss-usage from me ?
Regards.

Use github tarball for krew installations

Krew tests need a plugin with a small tarball, like konfig. However, the krew install currently uses the manually created tarballs for installation, which is bad because the krew tests will skew the download statistics for konfig. This does not happen when using the github tarball.

Therefore: switch the krew installation method to the standard tarball and make sure that the help text is updated accordingly.

Bonus: keep unnecessary files out of the tarball (does GH support that?)

Error importing kubeconfig files with "--" in its name

I tried to import an kubeconfig file "kubeconfig--xxx-xxx--xxx-x.yaml" but encountered the following error:

konfig import "kubeconfig--xxx-xxx--xxx-x.yaml"                                                                                                                                                             
error: unrecognized flag "kubeconfig--xxx-xxx--xxx-x.yaml"

Add a completion script

This should support the various options and understand the positional context.

Where applicable, it should also suggest context names from the kubeconfig files.

Goal: at the very least support bash and zsh

Add a "delete" subcommand

This subcommand should delete the given context(s) from the kubeconfig and print the result to stdout. Maybe also support a --save flag to update ~/.kube/config in-place.

error when importing new file

I just installed the plugin but kubectl konfig import --save new-config.yaml command gives the following error:

error: open /Users/emre.savci/.minikube/client.crt: no such file or directory

I am on macOS

Macos Monterey support (12.5.1 21G83)

Does not save the config, gives an error.

kubectl konfig import --save ~/.kube/192.168.0.100.conf
mktemp: mkstemp failed on konfig_yuisHv: Read-only file system

Feature Request - Add option to remove configs too

Thanks for the handy plugin. Please enable the option to delete/remove configs too

In other words, something similar to the below commands

kubectl config delete-cluster my-cluster
kubectl config delete-context my-cluster-context
kubectl config unset users.my-cluster-admin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.