Setup Kubernetes Namespaces and PODs

Abishek KafleAbishek Kafle
1 min read

Table of contents

Tasks

  • Create a namespace named dev.

  • Deploy a pod named dev-nginx-pod in the dev namespace.

  • Use the nginx image with the latest tag for the pod.

  • Ensure to specify the image tag as nginx:latest.

Steps

  1. First create the namespace named dev.

     kubectl create namespace dev
    

  2. Manifest with yaml file:

     apiversion: v1
     kind: Namespace
     metadata:
       name: dev
    

    But I prefer using EOF

     cat <<EOF > namespace-dev.yaml
     apiVersion: v1
     kind: Namespace
     metadata:
       name: dev
     EOF
    

  3. Create namespace now:

     kubectl create -f namespace-dev.yaml --save-config
    

  4. Create pods now, nginx-pod.yaml

     apiVersion: v1
     kind: Pod
     metadata:
       name: dev-nginx-pod
       namespace: dev
     spec:
       containers:
       - name: nginx
         image: nginx:latest
    

  5. Apply the YAML manifest file.

     kubectl apply -f nginx-pod.yaml
    
  6. Now List Namespaces

     kubectl get namespaces
    

  7. List Pods in a Namespace

     kubectl get pods -n dev
    

    #k8s #kubernetes #pods #namespace #happylearning :)

0
Subscribe to my newsletter

Read articles from Abishek Kafle directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abishek Kafle
Abishek Kafle

Infosec Poet and CAP-certified DevOps/SecOps Engineer, passionate about security, creativity, and continuous learning.