Shard Detail

kce v0.6.1

CLI tool and library to parse KUBECONFIG, and generate new config for specific context.
kubernetes kubectl kubeconfig crystal-lang kubeconfig-context-extractor

Install & Use

Add the following code to your project's shard.yml under:

dependencies to use in production
- OR -
development_dependencies to use in development

  github: anapsix/


GitHub release Docs

KCE (Kubeconfig Context Extractor) extracts sections of KUBECONFIG file based on selected context.

Since context includes cluster, and user name, extracting all relevant sections allows creating fully working KUBECONFIG for selected context.

Same functionality can be achieved with native kubectl command

kubectl --context=${context_name} config view --minify --flatten


Get latest release from Releases page.



Usage: kce [arguments]
    -k PATH, --kubeconfig=PATH       Path to kubeconfig file, defaults to KUBECONFIG env value,
                                     if present, otherwise ~/.kube/config
    -c NAME, --context=NAME          Context to extract config for
    -h, --help                       Show this help
    -v, --version                    Display version


Add kce to shard.yml dependencies

    github: anapsix/


require "kce"

kce ="my-context", "/path/to/kubeconfig")
puts kce.kubeconfig     # => path to selected KUBECONFIG file
puts kce.kubecontext    # => selected kubecontext ("my-context")
puts kce.config         # => "my-context" config as Object (from YAML)
puts kce.config.to_yaml # => "my-context" config as String (from YAML)

config = KCE.config("my-context", "/path/to/kubeconfig")
puts config         # => "my-context" config as Object (from YAML)
puts config.to_yaml # => "my-context" config as String (from YAML)


require "kce/configreader"

# getting config via instance method
reader = # will use `KUBECONFIG` env variable if set
kubeconfig = reader.config     # otherwise `$HOME/.kube/config`
puts kubeconfig                # => original KUBECONFIG as Object (from YAML)
puts kubeconfig.to_yaml        # => original KUBECONFIG as String (from YAML)

# reading from alternative path
reader ="/path/to/kubeconfig")

# getting config via class method
kubeconfig = KCE::ConfigReader.config("/path/to/kubeconfig")


# local build
shards build --release

# build Docker image, and release binaries (results will vary depending on your OS/ARCH)
make all