Namespace - Sandeep-K-Khandelwal/CKAD GitHub Wiki
- Namespaces are used to isolate resources in the Kubernetes cluster
- Kubernetes create a
default
namespace as part of the cluster setup
- Kubernetes create resources in the current namespace if not specified
- Kubernetes resources can be created in another namespace by using
--namespace=<namespace_name>
option in the command line
- A new namespace can be created using the following command -
kubectl create namespace <namespace_name>
- The YML to create the namespace is as follows -
apiVersion: v1
kind: Namespace
metadata:
name: dev
- We can switch the namespace using the following command -
kubectl config set-context $(kubectl config current-context) --namespace=<namespace_name>
- Use
--all-namespaces
to get the information from all namespaces
- The DNS to access the service from another namespace -
db-service.marketing.svc.cluster.local
. Here db-service
is the service name, marketing
is the namespace name, svc
is the subdomain for the services and cluster.local
is the default cluster