Understanding Namespaces: Hotel Sections
Namespaces are like hotel sections. Production section. Development section. Testing section. That's namespaces.
🎯 The Big Picture​
Think of namespaces like hotel sections. Production section (production namespace). Development section (dev namespace). Testing section (test namespace). Each section isolated. That's namespaces.
Namespaces provide virtual clusters. Resource isolation. Organization. Access control. Essential for multi-tenant clusters.
The Hotel Sections Analogy​
Think of namespaces like hotel sections:
Namespace: Hotel section
- Production section
- Development section
- Testing section
- Isolated
Resources: Section resources
- Rooms in section
- Services in section
- Isolated from other sections
Access control: Section access
- Who can access section
- RBAC per section
- Isolated
Once you see it this way, namespaces make perfect sense.
What is a Namespace?​
Namespace definition:
- Virtual cluster
- Resource isolation
- Organization
- Access control
Think of it as: Hotel section. Isolated. Organized.
Why Namespaces?​
Problems without namespaces:
- All resources together
- No isolation
- Hard to organize
- Access control issues
Solutions with namespaces:
- Resource isolation
- Organization
- Access control
- Multi-tenant
Real example: I once had all resources in default. Hard to manage. No isolation. With namespaces, organized. Isolated. Never going back.
Namespaces aren't optional for production. They're essential.
Default Namespaces​
Built-in namespaces:
default:
- Default namespace
- User resources
- If not specified
kube-system:
- System components
- Kubernetes system
- Don't modify
kube-public:
- Public resources
- Cluster info
- Readable by all
kube-node-lease:
- Node heartbeats
- System managed
- Don't modify
Think of it as: Built-in sections. Default. System. Public. Lease.
Creating Namespaces​
Create namespace:
kubectl create namespace production
Or YAML:
apiVersion: v1
kind: Namespace
metadata:
name: production
labels:
env: production
What this does:
- Creates namespace
- Isolated environment
- Resource organization
Think of it as: Create section. Isolated. Organized.
Using Namespaces​
Specify namespace:
In commands:
kubectl get pods -n production
kubectl apply -f pod.yaml -n production
In YAML:
apiVersion: v1
kind: Pod
metadata:
name: app
namespace: production
spec:
containers:
- name: app
image: app:1.0
Set context:
kubectl config set-context --current --namespace=production
Think of it as: Work in section. Specify section. Or set default.
Real-World Example: Complete Namespace Setup​
Step 1: Create namespaces:
kubectl create namespace production
kubectl create namespace development
kubectl create namespace testing
Step 2: Create resources:
# production/app.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
namespace: production
spec:
replicas: 5
template:
spec:
containers:
- name: app
image: app:1.0.0
Step 3: Verify isolation:
kubectl get pods -n production
kubectl get pods -n development
# Different pods, isolated
That's complete namespace setup. Isolated. Organized.
My Take: Namespace Strategy​
Here's what I do:
Organization:
- By environment (production, dev, test)
- By team (team-a, team-b)
- By application (app-a, app-b)
Isolation:
- Separate environments
- RBAC per namespace
- Resource quotas
The key: Organize by environment or team. Isolate. Use RBAC. Essential.
Memory Tip: The Hotel Sections Analogy​
Namespaces = Hotel sections
Namespace: Section Resources: Section resources Isolation: Separate sections
Once you see it this way, namespaces make perfect sense.
Common Mistakes​
- Not using namespaces: Everything in default
- Too many namespaces: Over-complicated
- No RBAC: Access control issues
- Not organizing: Hard to manage
- Namespace confusion: Wrong namespace
Key Takeaways​
- Namespaces provide isolation - Virtual clusters
- Organize resources - By environment or team
- Use RBAC - Access control per namespace
- Default namespace exists - For user resources
- Essential for production - Multi-tenant clusters
What's Next?​
Now that you understand namespaces, let's learn about Resource Quotas. Next: Resource Quotas.
Remember: Namespaces are like hotel sections. Isolated. Organized. Use for environments or teams. Essential for production. Multi-tenant clusters.