Kubernetes has become the de facto standard for container orchestration, making it easier to manage large-scale applications. However, managing multiple kubernetes clusters can be a daunting task, particularly if you are managing production and development environments. In this blog post, we'll introduce you to a tool that makes managing multiple kubernetes clusters a breeze: k8senv.
What is k8senv and why use it?
k8senv is a python package that helps you manage multiple kubernetes clusters within a single project. The tool stores cluster configurations inside a project's root directory and forces you to specify an environment when running kubectl commands, reducing the risk of running the wrong commands on the wrong cluster or namespace.
Instructions for using k8senv:
The tool can be installed via pip using:
To setup the tool for a project run:
This will create a configuration file (.k8senv.yaml
) in the working directory which is setup to manage 2 environments (prod
and stage
). Along with this it will create a .kube
directory which is used to store the cluster configuration files for each project (the paths and environment names can all be changed using command line arguments).
Aswell as generating the config files for the tool, the gitignore file will also be updated to exclude the sensitive files from source control.
Once the tool is setup, a cluster configuration needs to be generated for each environment. To do this, create the cluster configuration based on your providers instructions, storing the output in a file called <env>.yaml
in the .kube
directory.
For example, using k3d, to save the cluster to the stage config run:
or:
How to run k8senv:
To run a command, where kubectl
would normally be used, replace it with k8senv run <env> --
where env
is the name of the environment. For example, to print the config for the stage environment run:
To view all pods in the prod environment run:
The configs are normal kubernetes configs so anything you can do with kubectl
can be done with k8senv
. So to further configure the environment such as adding a namespace you can just run the same kubectl
commands. For example:
Will set the namespace in the config to stage-ns
.
The benefits of using the k8senv tool
k8senv is a really useful tool that can help you manage separate production and staging environments, keep cluster configurations organised, avoid misconfigurations and improve collaboration. If you're looking to streamline your kubernetes cluster management, give k8senv a try.
Looking for additional technical support? Raise an issue on the Github project and include the link.