This is an example about how to use dirk. dirk stands for direnv kubeconfig and makes it easy to connect to multiple kubernetes clusters depending on the current working directory. In this tutorial we will use py-dirk - the Python implementation of dirk.
The following requirements are considered to be given:
- *nix
- direnv
- Python3
- minikube
- kubectl
Get the code - e.g. like this:
git clone https://github.com/deepshore/how-to-use-dirk
Enter the project folder and create a venv like this:
cd how-to-use-dirk
python3 -m venv venv
Activate it:
source venv/bin/activate
Install py-dirk using pip:
pip install py-dirk
Init dirk in the dev and prod folder like this:
dirk init dev
dirk init prod
Change directory to dev and create a minikube cluster with profile name dev:
cd dev && minikube start -p dev
minikube will add the configurations for connecting to the dev cluster to the dev/kubeconfig file.
Repeat the step above for prod:
cd ../prod && minikube start -p prod
There should currently be at least two minikube clusters running - dev and prod:
minikube profile list
Make sure that you are talking to the prod cluster by considering the name of the node:
kubectl get nodes
If you change to the dev directory, kubectl is now connected to the dev cluster:
cd ../dev && kubectl get nodes
You can bind the existing dev/kubeconfig to the another-dev folder like this:
dirk init another-dev -c dev/kubeconfig
Stop all of the minikube clusters like this:
minikube stop --all
Delete the dev and the prod cluster like this:
minikube delete -p dev
minikube delete -p prod
Note that .envrc and kubeconfig should generally not be added to a repository.