In this guide, we’ll explore sharing a Kubernetes cluster using namespaces. This method allows multiple teams or projects to use the same cluster while keeping resources isolated.
This article complements my video tutorial, so make sure to watch that for a visual walkthrough.
What Are Namespaces in Kubernetes?
Namespaces in Kubernetes divide cluster resources between multiple users. They are a great way to organize your cluster and manage resources efficiently.
Benefits of Using Namespaces
- Resource Isolation: Each namespace has its resources, ensuring that one project doesn’t interfere with another.
- Access Control: You can set permissions for different namespaces, giving teams only the necessary access.
- Simplified Management: It is easier to manage large clusters by segmenting them into smaller, manageable parts.
Creating and Managing Namespaces
Follow these steps to create and manage namespaces in your Kubernetes cluster.
Prerequisites
Before we begin, ensure you have a Kubernetes cluster set up if you don’t, check out our Guide to Deploy Kubernetes and Install Kind on MacOS.
Step-by-Step Commands
- Git clone the project – GIT PROJECT
git clone git@github.com:thiagousa/youtube.git
cd 19
- Create a Kind Cluster
1-create-cluster:
kind create cluster --name namespace --config kind/kind-config.yaml
- List Existing Namespaces
2-list-ns:
kubectl get ns
- Create a Development Namespace
3-create-ns-dev:
kubectl create ns dev
- Create a Production Namespace
4-create-ns-prod:
kubectl create ns prod
- Create a Pod in the Development Namespace
5-create-pod-dev:
kubectl run dev-pod --image=nginx --namespace=dev
- Create a Pod in the Production Namespace
6-create-pod-prod:
kubectl run prod-pod --image=nginx --namespace=prod
- List Pods in the Development Namespace
7-list-pod-dev:
kubectl get pods -n dev
- List Pods in the Production Namespace
8-list-pod-prod:
kubectl get pods -n prod
- Delete the Kind Cluster
9-delete-all:
kind delete cluster --name namespace
Internal Links
For more detailed steps and additional resources, check out these related posts:
- How to Install Docker on Ubuntu
- Application Monitoring with Docker
- Guide to Deploy Kubernetes
- Install Kind on MacOS
External Resources
For an in-depth understanding of Kubernetes namespaces, refer to the official Kubernetes Documentation.
Conclusion
Sharing a Kubernetes cluster with namespaces is a powerful way to manage resources and isolate projects. Following the steps outlined in this guide, you can set up and manage namespaces efficiently, ensuring your cluster remains organized and secure. Remember to watch the accompanying video tutorial for a complete walkthrough.
