kce.cr v0.6.1

Extract relevant sections of KUBECONFIG based on target context name into full fledged config
  • v0.6.1 - June 10, 2021
  • v0.6.0 - January 19, 2021
  • v0.5.0 - January 17, 2021
  • v0.4.1 - January 25, 2020
  • v0.4.0 - August 14, 2019


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/kce.cr


require "kce"

kce = KCE.new("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 = KCE::ConfigReader.new # 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 = KCE::ConfigReader.new("/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

Generate and Publish Docs

make sure to tag and push changes and tags before generating docs

# assuming latest tag is 0.6.1
ghshard docs:publish
ghshard docs:redirect 0.6 0.6.1
ghshard docs:redirect latest 0.6.1
github statistic
  • 0
  • 1
  • 0
  • 0
  • 8 days ago
  • June 15, 2019

MIT License

Synced at

Sat, 19 Jun 2021 04:14:50 GMT