KodeCloud CKAD Namespaces
Links: 111 KodeCloud Index
Namespaces¶
- We have been deploying resources in the
default
namespace.- The
default
namespace is created by k8s.
- The
- k8s also creates different pods for its internal use.
- To isolate this from the user, k8s creates them at
kube-system
namespace to prevent any kind of accidental deletion.
- To isolate this from the user, k8s creates them at
- k8s also creates a space called
kube-public
where resources that should be available to all the users are created. - Each of the namespaces can have its own set of policies to define who can do what.
- We can also assign a quota of resources to these namespaces.
The resources within the same namespace can refer to each other by just simple names.
If we want to connect to services in other namespace then we have to provide the full address.
We can do this because when a service is created a DNS entry is added to it automatically in the above format.
-
Understanding DNS service name:
-
k get <resources-type> -n <namespace>
-
We can have the
namespace
option under themetadata
section in the definition file of any resource to make sure that resource gets created in that namespace. -
We can create a namespace using the namespace definition file and then applying it.
-
Get all the namespaces of the system:
k get ns
- We can also create a namespace using the command line
k create namespace dev
- Changing the current namespace:
k config set-context $(kubectl config current-context) --namespace=dev
- Since we can have different contexts (if we are managing different clusters) we first find our context (with the command in the middle) and then set its namespace to dev.
- View a resource in all namespaces
k get <resource-type> --all-namespaces
- To limit resources in a namespace we create a
ResourceQuota
. - Sample definition file for a resource quota
Last updated: 2023-05-03