Kubernetes Namespace

by Anish

Posted on Wednesday February 6, 2019

Referefce

Introduction

A Kubernetes namespace provides a mechanism to scope resources in a cluster.

Namespaces provide a unique scope for:

  • Named resources to avoid basic naming collisions.

  • Delegated management authority to trusted users.

  • The ability to limit community resource consumption.

Most objects in the system are scoped by namespace, but some are excepted and have no namespace, including nodes and users.

Viewing namespace

The following command can be used to get a list of all namespaces:

root@kube-master:# kubectl get namespaces
NAME  STATUS  AGE
default Active  13d
kube-public Active  13d
kube-system Active  13d

Kubernetes starts with three initial namespaces:

  • default The default namespace for objects with no other namespace
  • kube-system The namespace for objects created by the Kubernetes system
  • kube-public This namespace is created automatically and is readable by all users (including those not authenticated).

View the pods running on kube-system namespace

root@kube-master:# kubectl get pods -n kube-system
NAME                                  READY     STATUS    RESTARTS   AGE
coredns-78fcdf6894-rbfq8              1/1       Running   0          13d
coredns-78fcdf6894-ttbqz              1/1       Running   0          13d
etcd-kube-master                      1/1       Running   0          13d
kube-apiserver-kube-master            1/1       Running   0          13d
kube-controller-manager-kube-master   1/1       Running   0          13d
kube-flannel-ds-hzz8t                 1/1       Running   0          13d
kube-flannel-ds-vsr2h                 1/1       Running   0          13d
kube-proxy-5vmws                      1/1       Running   0          13d
kube-proxy-7zm5v                      1/1       Running   0          13d
kube-scheduler-kube-master            1/1       Running   0          13d
tiller-deploy-85744d9bfb-qj9p4        1/1       Running   0          13d

Creating Namespace

A namespace allows a community of users to organize and manage their content in isolation from other communities. Users must be given access to projects by administrators, or if allowed to create projects, automatically have access to their own projects.

The YAML definition of creating the namespace with

kind:Namespace

{
    "kind": "Namespace",
    "apiVersion": "v1",
    "metadata": {
        "name": "prod",
        "labels": {
            "name": "prod"
        }
    }
}

The following command will create for namespace which will be used for devops purpose namely DEV,PROD,QA,STAG under which the resources would be managed accordingly.

root@kube-master:# kubectl create -f https://raw.githubusercontent.com/anishnath/kubernetes/master/devops-namespace.yaml
namespace/dev created
namespace/prod created
namespace/qa created
namespace/stag created

Viewing namespace with labels

root@kube-master:# kubectl get namespaces --show-labels
NAME          STATUS    AGE       LABELS
default       Active    13d       <none>
dev           Active    58s       name=dev
kube-public   Active    13d       <none>
kube-system   Active    13d       <none>
prod          Active    58s       name=prod
qa            Active    58s       name=qa
stag          Active    58s       name=stag
  • A Kubernetes namespace provides the scope for Pods, Services, and Deployments in the cluster.
  • Users interacting with one namespace do not see the content in another namespace.

Launch a busy box pods in qa namespace

root@kube-master:# kubectl create -f https://raw.githubusercontent.com/anishnath/kubernetes/master/busybox.yaml -n qa
pod/busybox created
root@kube-master:# kubectl get pods -n qa 
NAME      READY     STATUS    RESTARTS   AGE
busybox   1/1       Running   0          12s

Launch a busy box pods in dev namespace

root@kube-master:# kubectl create -f https://raw.githubusercontent.com/anishnath/kubernetes/master/busybox.yaml -n dev
pod/busybox created
root@kube-master:# kubectl get pods -n dev
NAME      READY     STATUS    RESTARTS   AGE
busybox   1/1       Running   0          8s

Deleting the Namespace

root@kube-master:# kubectl delete namespace dev
namespace "dev" deleted

Warning: When a namespace is deleted, it will delete all the associated k8 resource along with.


Thanku for reading !!! Give a Share for Support


Your Support Matters!

Instead of directly asking for donations, I'm thrilled to offer you all nine of my books for just $9 on leanpub By grabbing this bundle you not only help cover my coffee, beer, and Amazon bills but also play a crucial role in advancing and refining this project. Your contribution is indispensable, and I'm genuinely grateful for your involvement in this journey!

Any private key value that you enter or we generate is not stored on this site, this tool is provided via an HTTPS URL to ensure that private keys cannot be stolen, for extra security run this software on your network, no cloud dependency




python Cryptography Topics
Topics
For Coffee/ Beer/ Amazon Bill and further development of the project Support by Purchasing, The Modern Cryptography CookBook for Just $9 Coupon Price

Kubernetes for DevOps

Hello Dockerfile

Cryptography for Python Developers

Cryptography for JavaScript Developers

Go lang ryptography for Developers

Here