Kubernetes
Namespaces
Partition a cluster into isolated virtual clusters.
By EZ4Code Team
namespaceisolationquota
Code
# Create and switch namespaces
kubectl create namespace staging
kubectl config set-context --current --namespace=staging
# List and inspect
kubectl get namespaces
kubectl get pods -A # all namespaces
kubectl get pods -n staging
# Resource quota in a namespace
apiVersion: v1
kind: ResourceQuota
metadata:
name: staging-quota
namespace: staging
spec:
hard:
requests.cpu: "4"
requests.memory: 8Gi
pods: "20"
# Delete a namespace (removes everything inside)
kubectl delete namespace stagingExplanation
Namespaces provide a scope for names and a way to divide cluster resources between teams or environments. ResourceQuotas limit how much CPU, memory, and object count a namespace can consume. Switching the default namespace with set-context avoids passing -n on every command.
More Kubernetes Snippets
Pod Manifest
Define a standalone Pod with a container, env, and probe.
Deployment & Rollout
Manage a replicated, rolling-updated workload.
Service Types
Expose Pods via ClusterIP, NodePort, and LoadBalancer services.
ConfigMap & Secret
Inject configuration and sensitive data into containers.
Ingress Routing
Route external HTTP traffic to services by host and path.
Labels & Selectors
Tag resources and query them with selectors.