Kubernetes for multiple projects

Working with multiple projects at the same time using docker and kubernetes can get painful. Needing to remember contexts, configurations and the way that you interact with those can start to weigh down a local development process.

Enter kubernetes namespaces

Kubernetes namespaces allow you to separate a context out into multiple namespaces that all act like their own context. This is intended from the documentation to help segregate a kubernetes cluster based on environment (dev, staging, prod etc…) but it is also useful for local contexts.

Check your current context is set to either docker-desktop or minikube (whichever you’re using) and create a new namespace: kubectl create namespace {project-name}. You can then list your config to identify your local context and user details with kubectl config view then from this create a new context that is tied to your local context with namespace separation: kubectl config set-context {project-name} --namespace={project-name} --cluster={local-cluster} --user={local-user}

Finally, you switch to the context the same as you would with your other contexts: kubectl config use-context dev

Leave a Reply

Your email address will not be published. Required fields are marked *