Skip to content

Instantly share code, notes, and snippets.

@shriomtri
Last active July 16, 2024 14:12
Show Gist options
  • Save shriomtri/13c8433ecf494a88ae8d67ebbef0aa38 to your computer and use it in GitHub Desktop.
Save shriomtri/13c8433ecf494a88ae8d67ebbef0aa38 to your computer and use it in GitHub Desktop.
Working with Kubernetes Namespaces

Working with Kubernetes Namespaces

Introduction

Namespaces are a central component of any Kubernetes infrastructure. This lab will give you the opportunity to work with namespaces in a functioning cluster. You will be able to practice the process of creating, using, and navigating Kubernetes namespaces.

Additional Resources

You are working for BeeBox, a subscription service company that provides weekly shipments of bees to customers. The company is in the process of containerizing their infrastructure and running their software on Kubernetes. As part of this process, the company is working on determining what namespaces it will need in the Kubernetes cluster.

You have been asked to access the cluster and perform some maintenance tasks related to the cluster's namespaces.

  • The dev team would like a namespace they can work in that is separate from namespaces used to run production workloads. Create a new namespace called dev.
  • One of the members of your security team would like to audit the namespaces that currently exist in the cluster. Get a list of the current namespaces and save it to a file located at /home/cloud_user/namespaces.txt on the control plane node.
  • Someone on the team created a pod with the name quark, but they are not sure which namespace it is in. Determine which namespace this pod is in, and save the name of that namespace to a file located at /home/cloud_user/quark-namespace.txt on the control plane node.

Learning Objectives

  1. Create the dev Namespace
    • Log in to the control plane node. Create a namespace in the cluster called dev.
  2. Get a List of the Current Namespaces
    • List all of the current namespaces in the cluster. Save this list to the file /home/cloud_user/namespaces.txt.
  3. Find the quark Pod's Namespace
    • Locate a pod called quark. Determine which namespace the pod is in, and save the name of that namespace to the file /home/cloud_user/quark-namespace.txt.

Solution

Log in to the provided control plane node server using the credentials provided:

ssh cloud_user@<PUBLIC_IP_ADDRESS>

Create the dev Namespace

  1. Create a namespace in the cluster called dev:

    kubectl create namespace dev
    
    

Get a List of the Current Namespaces

  1. List the current namespaces:

    kubectl get namespace
    
    
  2. Save the namespaces list to a file:

    kubectl get namespace > /home/cloud_user/namespaces.txt
    
    
  3. Verify the list saved to the file:

    cat namespaces.txt
    
    

    We should see the list of namespaces.

Find the quark Pod's Namespace

  1. Locate the quark pod:

    kubectl get pods --all-namespaces
    
    
  2. Copy the name of the namespace where the quark pod is located.

  3. Create a file in which to save its name: :

    vi /home/cloud_user/quark-namespace.txt
    
    
  4. Paste in the name of the quark pod's namespace.

  5. Save and exit the file by pressing Escape followed by :wq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment