Kubernetes Namespaces

         Kubernetes supports multiple virtual clusters backed by the same physical cluster. These virtual clusters are called namespaces.

       Namespaces are intended for use in environments with many users spread across multiple teams, or projects 

       Namespaces provide a scope for names. Names of resources need to be unique within a namespace, but not across namespaces. Namespaces can not be nested inside one another and each Kubernetes resource can only be in one namespace.

       Namespaces are a way to divide cluster resources between multiple users.

       It is not necessary to use multiple namespaces just to separate slightly different resources, such as different versions of the same software: use labels to distinguish resources within the same namespace.


Create Namespace

       kubectl create namespace demo1

       kubectl get namespace

       kubectl run nginx-pod --image=nginx --namespace=demo1

       kubectl get pods –namespace demo1

       kubectl delete pod nginx-pod --namespace demo1

KubeConfig file

       Use kubeconfig files to organize information about clusters, users, namespaces, and authentication mechanisms. The kubectl command-line tool uses kubeconfig files to find the information it needs to choose a cluster and communicate with the API server of a cluster.

 KubeContext

       A context element in a kubeconfig file is used to group access parameters under a convenient name. Each context has three parameters: cluster, namespace, and user. By default, the kubectl command-line tool uses parameters from the current context to communicate with the cluster.

 


Assignment

Context and Namespaces


1. Create a dev ns and create a pod called poddev in dev ns

2. Create a prod ns and create a pod called podprod in prod ns

3. View all the pods from default ns

4. Create 2 context devcontext(dev env) and prodcontext(prod env) in config using command

5. Switch to dev env and list all the pods

6. Create a deployment uder dev ns and list all the deployments and pods

7. Switch to prod env and list all the pods

8. Create a deployment under prod ns and list all the deployments and pods

9, Switch back to default ns context

10 delete prodcontext and devContext

Comments

Popular posts from this blog

Terraform

Scrum Master Interview help - Bootcamp

Kubernetes