Code Monkey home page Code Monkey logo

kckn's Introduction

kckn

Description

kckn is a simple tool for managing per-shell Kubernetes contexts via the KUBECONFIG env var. Like vital-software/kc, it "works around the lack of a KUBECONTEXT environment variable."

Features

  • kckn generates kubeconfigs that will even work with tools that don't respect PATH-style (colon-separated) KUBECONFIG values.
  • kckn does not modify your base kubeconfig.
  • Leave definitions for your clusters and users to you to manage yourself in your base kubeconfig.

Usage

  • . kc <cluster or cluster alias> to set clusters;
  • . kn <namespace or namespace alias> to set namespaces; and
  • . kc off to revert changes made by kckn.

You can define aliases to avoid typing the ., e.g. alias kc='. kc'.

Installation

  1. Make sure that the kc and kn scipts are on your PATH.
  2. Make sure that your local copies of these scripts are executable.
  3. Make sure that your base kubeconfig (see configuration below) contains all of the users and contexts that will be used in the contexts generated by kckn.

kc and kn both have bash completion support; to enable completion, source this repo's completion file: source /path/to/kckn/completion.

How it works

At the highest level, kckn generates ephemeral kubeconfigs whose current-cluster value is <one of your clusters>/<some namespace>.

kckn starts by generating a small kubeconfig that defines a context for your cluster/namespace/user combination. Then, kckn uses kubectl to flatten that kubeconfig onto your base kubeconfig. The resulting kubeconfig is written to a temporary file, and the path to that temporary file becomes the value of your KUBECONFIG shell environment variable.

Prompt customization

Several env vars can be used to add kckn information to your shell prompt:

env var description
__KCKN <cluster>/<namespace>
__KCKN_KUBE_CLUSTER <cluster>
__KCKN_KUBE_NAMESPACE <namespace>

Configuration

env var default value description
KCKN_BASE_KUBECONFIG ~/.kube/config path to your base kubeconfig file, which should contain all of the users and contexts that will be used in your cluster-namespace contexts
KCKN_CLUSTER_ALIASES path to the simple file whose lines consist of <cluster alias> <cluster> pairs denoting short-names for cluste to be used with kc
KCKN_NAMESPACE_ALIASES path to the simple file whose lines consist of <namespace alias> <namespace> pairs denoting short-names for namespaces to be used with kn
KCKN_CLUSTER_USERS path to the simple file whose lines consist of <cluster> <user> pairs denoting which user is to be used with which cluster (by default, the user is assumed to be the same as the cluster name)

Differences from kc

  • Works with any tool that supports KUBECONFIG tools without aliasing those tools.

kckn's People

Contributors

pclalv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.