You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Namespaces allow to split-up resources into different groups.
Resource names should be unique in a namespace
We can use namespaces to create multiple environments like dev, staging and production etc
Kubernetes will always list the resources from default namespace unless we provide exclusively from which namespace we need information from.
Step-02: Namespaces Imperative - Create dev Namespace
Step-02-01: Create Namespace
# List Namespaces
kubectl get ns
# Craete Namespace
kubectl create namespace <namespace-name>
kubectl create namespace dev
# List Namespaces
kubectl get ns
Step-02-02: Deploy All k8s Objects
# Deploy All k8s Objects
kubectl apply -f 01-kube-manifests-imperative/ -n dev
# List Namespaces
kubectl get ns
# List Deployments from dev Namespace
kubectl get deploy -n dev
# List Pods from dev Namespace
kubectl get pods -n dev
# List Services from dev Namespace
kubectl get svc -n dev
# List all objects from dev Namespaces
kubectl get all -n dev
# Access Application
http://<LB-Service-External-IP>/
Step-03-02: Update Namespace in Deployment and Service YAML Manifest
We are going to update the namespace: qa in metadata section of Deployment and Service
# Deployment YAML ManifestapiVersion: apps/v1kind: Deployment metadata:
name: myapp1-deploymentnamespace: qaspec:
# Service YAML ManifestapiVersion: v1kind: Service metadata:
name: myapp1-lb-servicenamespace: qaspec:
Step-03-03: Deploy Kubernetes Manifests
# Deploy Kubernetes Manifests
kubectl apply -f 02-kube-manifests-declarative
# List Namespaces
kubectl get ns
# List Deployments from qa Namespace
kubectl get deploy -n qa
# List Pods from qa Namespace
kubectl get pods -n qa
# List Services from qa Namespace
kubectl get svc -n qa
# List all objects from qa Namespaces
kubectl get all -n qa
# Access Application
http://<LB-Service-External-IP>/
Step-04: Clean-Up Resources
If we delete Namespace, all resources associated with namespace will get deleted.
# Delete dev Namespace
kubectl delete ns dev
# List Namespaces
kubectl get ns
Observation:
1. dev namespace should not be present
# Verify Pods from dev Namespace
kubectl get pods -n dev
Observation: We should not find any pods because namespace itself doesnt exists# Delete qa Namespace Resources (only)
kubectl delete-f 02-kube-manifests-declarative
# List Namespaces
kubectl get ns
# Delete qa Namespace
kubectl delete ns qa
# List Namespaces
kubectl get ns