CodeBlanks Logo Icon CodeBlanks

Summary - Namespace

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 namespace or YAML; objects are placed with metadata.namespace. ResourceQuota and LimitRange limit resources.
  • -n for one command, -A for all namespaces; set-context --current --namespace changes 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 dev

Practice 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

terminal
# buraya yaz

Sample solution

terminal
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.

Question
kubectl get pods ____
Answer
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

All lessons in Intermediate