Summary - Namespace
- Docker & Kubernetes course
- Intermediate
- Lesson 60/82
- 5 min
Combine create, list and -n to set up resource groups.
Summary: Namespaces
In this group:
- A namespace divides the cluster into logical sections; names are unique within a namespace. Objects like Node and PV are cluster-scoped.
- Ready namespaces:
default,kube-system,kube-public,kube-node-lease. - Creation:
create namespaceor YAML; objects are placed withmetadata.namespace. ResourceQuota and LimitRange limit resources. -nfor one command,-Afor all namespaces;set-context --current --namespacechanges the default.- A namespace doesn't isolate the network; NetworkPolicy is needed. Deleting it deletes what's inside.
kubectl create ns dev
kubectl config set-context --current --namespace=dev
kubectl get all -n devPractice A namespace with a quota
Write a ResourceQuota YAML: name dev-kota, namespace dev; under spec.hard, requests.cpu: "4", requests.memory: 8Gi and pods: "20".
Starter code
# buraya yazSample solution
apiVersion: v1
kind: ResourceQuota
metadata:
name: dev-kota
namespace: dev
spec:
hard:
requests.cpu: "4"
requests.memory: 8Gi
pods: "20"Expected output
resourcequota/dev-kota created $ kubectl describe quota dev-kota -n dev Resource Used Hard -------- ---- ---- pods 3 20 requests.cpu 300m 4 requests.memory 384Mi 8Gi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 With which name does a pod in the dev namespace reach the db service in prod?
- prod/db
- It can't
- db.prod Correct answer
- db
Explanation: The short name only resolves within the same namespace.
2 List the pods in all namespaces.
kubectl get pods ____
kubectl get pods --all-namespaces
Explanation: The short form of --all-namespaces is -A.
3 Match.
| Term | Meaning |
|---|---|
create ns |
Create |
-n |
Select |
-A |
All |
delete ns |
Delete with contents |