Giter Site home page Giter Site logo

apoth's Introduction

Apoth - a kubeconfig management utility

(Apoth is Greek for storage bin - aka container)

Background

When using Kubernetes where you have access to multiple clusters and need to quickly move between them, each cluster has a unique context and method of accessing the cluster. The official documentation steers users toward two possible solutions:

  • Combining multiple contexts and clusters in the same configuration file instead of keeping each cluster configuration separate. This seems counter to containerization.
  • Using the KUBECONFIG environment variable to chain together multiple files (much as PATH does)

For now, the east way to keep the config files separate is to use the environment variable KUBECONFIG to point to the desired config file, or a chain of files. This is not super friendly. Aside from editing users configuration scripts, the only easy way to modify session environmental variables is to assign to expressions, which is a little clunky.

My proposal for handling multiple config files is to look for a directory ~/.kube/config.d and if found, treat all of the files in that directory as independent config files. This would operate identically to the chaining of files in the KUBECONFIG environmental variable together, but allow an easy mechanism for "installation" to copy or link files into the users ~/.kube/config.d directory for semi-permanent persistence.

How it works

This project is mainly just an exercise at writing a useful Go program that will:

  • Make sure the KUBECONFIG env var is not being used to select a specific config file chain (Needs further research to determine if simultaneous env var path chain and config file can coexist. The documentation suggests the ~/.kube/config file is only used if the env var is not set) https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/
  • Locate multiple config files (~/.kube/config.d)
    • Split out a multi-context file into individual files (maybe - still TBD)
    • Look for multiple contexts in each file and present each context as a separate entry in the menu
  • Present the list of contexts to the user in a simple menu
  • Let the user select one of the configurations (contexts)
  • Rewrite the ~/.kube/config file from the selected context

Future Intentions

If it works out well, I may consider trying to submit this to the K8s group for inclusion into kubectl. Keeping that in mind, I will attempt to keep everything sympatico with how kubectl currently handles configuration files so that it will be a trivial task to rip out the pertinent code later. At first glance, it would seem to be simple enough just to include the config.d discovered files as if they were appended to the KUBECONFIG environment variable.

Research into Existing kubectl Functionality

As mentioned, the documentation steers users to either creating combo configs, or using the environment variable KUBECONFIG to chain together multiple files. Looking at the source code does not contradict this. Furthermore, from the code or testing:

  • If --kubeconfig is specified on the command line, that single file is used and no other locations are checked.
  • If the $KUBECONFIG is set, the ~.kube/config file is not checked.
  • If the $KUBECONFIG is set to directories instead of files, it will panic.
  • A deprecated ~.kube/.kubeconfig file is checked and migrated if found.
  • When use-context is used, the very first config file in the $KUBECONFIG chain is the one altered to hold the current-context attribute. It could easily be setting a context defined in a different file.
  • When attributes are set for an entity already defined in a particular config file, the attributes are correctly placed on the attribute in the original file (not use-context).
  • When entities are added (set-cluster) they are always stored in the first file in the chain.
  • Manual edits to the config files (like setting the current-context) are properly respected on subsequent calls to kubectl.

apoth's People

Contributors

jimbledsoe avatar

Watchers

James Cloos 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.