Kubernetes

Kubernetes – Cheatsheet of Commands for Namespaces

Kubernetes namespaces represents virtual clusters (logical entity with a unique name) created out of same physical cluster to enable allocation or split of cluster resources to different group of users. Namespaces are, primarily, used for managing cluster resources across dev/test/production environments by attaching different level of authorization controls and policies to different sections of cluster resources. In simpler words, it allows to create a community of users (developers, testers, production ops) in relation to some of the following:

  • Cluster resources available for usage (pods, services, deployments, replication controllers etc)
  • Who could do what with available cluster resources (policies)
  • Number of resources that could be used by the community (quotas)

This post aims to provide a list of commonly used commands  (cheat sheet) to work with namespaces. This list can prove to be very useful when you are starting to work with Kubernetes namespaces.

  • Get the list of namespaces
    kubectl get namespaces
    
  • Show the namespaces with label information
    kubectl get namespaces --show-labels
    
  • Get summary information of a specific namespace
    kubectl get namespaces <name>
    
  • Get detailed information about a namespace
    kubectl describe namespaces <name>
    
  • Create a namespace
    kubectl create -f <yaml/json file consisting of namespace information>
    

    Here is a sample json file for development namespace:

    {
     "kind": "Namespace",
     "apiVersion": "v1",
     "metadata": {
       "name": "development",
       "labels": {
        "name": "development"
       }
     }
    }
    
  • Delete a namespace
    kubectl delete namespaces <name>
    
  • Get the detailed information about cluster
    kubectl config view
    
  • Set a context with a namespace
    kubectl config set-context <context-name> --namespace=<namespace-name> --cluster=<cluster-name> --user=<user-name><span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>
    
  • Choose a request context to work with a specific namespace
    kubectl config use-context <context name>
    
  • Get the current context information
    kubectl config current-context
    

References

Summary

In this post, you scanned through the list of commands in relation to Kubernetes Namespaces. Did you find this article useful? Do you have any questions about this article or Kubernetes namespaces commands? Leave a comment and ask your questions and I shall do my best to address your queries.

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. For latest updates and blogs, follow us on Twitter. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking. Check out my other blog, Revive-n-Thrive.com

Share
Published by
Ajitesh Kumar
Tags: Kubernetes

Recent Posts

How to Learn Effectively: A Holistic Approach

In this fast-changing world, the ability to learn effectively is more valuable than ever. Whether…

2 days ago

How to Choose Right Statistical Tests: Examples

Last updated: 13th May, 2024 Whether you are a researcher, data analyst, or data scientist,…

2 days ago

Data Lakehouses Fundamentals & Examples

Last updated: 12th May, 2024 Data lakehouses are a relatively new concept in the data…

2 days ago

Machine Learning Lifecycle: Data to Deployment Example

Last updated: 12th May 2024 In this blog, we get an overview of the machine…

3 days ago

Autoencoder vs Variational Autoencoder (VAE): Differences, Example

Last updated: 12th May, 2024 In the world of generative AI models, autoencoders (AE) and…

3 days ago

Linear Regression T-test: Formula, Example

Last updated: 7th May, 2024 Linear regression is a popular statistical method used to model…

1 week ago