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


kce:
  github: anapsix/kce.cr

Readme

KCE.cr

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

Install

Get latest release from Releases page.

Usage

CLI

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

Library

Add kce to shard.yml dependencies

dependencies:
  kce:
    github: anapsix/kce.cr

KCE

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)

KCE::ConfigReader

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")

Build

# local build
shards build --release

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