k - Handle multiple kubernetes environments
k is a kubectl helper to help you dealing with different kubernetes environments.
k is a kubectl
helper to help you dealing with different kubernetes environments.
At car2go we use kubernetes to orchestrate our services. We have different clusters for each of our environments: development, integration and production.
Sometimes it's kinda annoying to quickly switch between these environments. That is where k
kicks in. It helps you to execute kubectl
commands in an specified environment:
# Without k
$ kubectl --kubeconfig /Users/max/.bluemix/plugins/container-service/clusters/moo-dev/moo-dev.yml exec -it mypod-abcdef -- /bin/sh
# With k
$ k dev exec -it mypod-abcdef -- /bin/sh
# With k on steroids
$ k dev e mypod-abcdef -- /bin/sh
Looks a little bit easier right?
Installation
If you have node.js installed, just install k
by running
npm install -g the-k
Done 🙂
Configuration
The configuration is simple. You need to place a .kfile.json
in your home directory.
This JSON file should have two properties: environments
and shorthands
. There is an example file at the end from this article which makes this a little bit clearer.
Environments
Environments are the place where you configure the aliases and matching kubernetes configuration files.
Shorthands
Shorthands are used to make your live even more easier by defining shorthands for existing commands. If you don't want to write get pods
all the time, you can create a gp
shorthand which expands to this two commands.
Example .kfile.json
{
"shorthands": {
"gp": ["get", "pods"],
"gs": ["get", "services"],
"e": ["exec", "-it"]
},
"environments": {
"dev": {
"kubeconfig": "/Users/max/.bluemix/plugins/container-service/clusters/moo-dev/moo-dev.yml"
},
"int": {
"kubeconfig": "/Users/max/.bluemix/plugins/container-service/clusters/moo-int/moo-int.yml"
}
}
}
k is still in development and you might not use it in production environments.