Skip to content

deepshore/how-to-use-dirk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

how-to-use-dirk

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.

Requirements

The following requirements are considered to be given:

  • *nix
  • direnv
  • Python3
  • minikube
  • kubectl

Use dirk

Get the code

Get the code - e.g. like this:

git clone https://github.com/deepshore/how-to-use-dirk

Create and activate a virtual environment

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

Install py-dirk using pip:

pip install py-dirk

Init dirk in dev and prod

Init dirk in the dev and prod folder like this:

dirk init dev 
dirk init prod

Bind minikube clusters to project folders

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

Check if it is working

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

Init directory using an existing kubeconfig

You can bind the existing dev/kubeconfig to the another-dev folder like this:

dirk init another-dev -c dev/kubeconfig

Clean up

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

Additional remarks

Note that .envrc and kubeconfig should generally not be added to a repository.

About

This is an example about how to use dirk

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published