Thursday, 2 October 2025

Deploy a Pod in a Custom Namespace on Kubernetes (nginx:latest)

 Our course you can check :-   Udemy course


Que:- 

The DevOps team is planning to deploy some micro services on Kubernetes platform. The team has already set up a Kubernetes cluster and now they want to set up some namespaces, deployments etc. Based on the current requirements, the team has shared some details as below:

Create a namespace named dev and deploy a POD within it. Name the pod dev-nginx-pod and use the nginx image with the latest tag. Ensure to specify the tag as nginx:latest.


Ans:- 

thor@jumphost ~$ cat namespace.yaml 

---

apiVersion: v1

kind: Namespace

metadata:

  name: dev

---

apiVersion: v1

kind: Pod

metadata:

  name: dev-nginx-pod

  namespace: dev

  labels:

    app: nginx

spec:

  containers:

  - name: nginx-container

    image: nginx:latest

thor@jumphost ~$ 

thor@jumphost ~$ kubectl apply -f namespace.yaml 

namespace/dev created

pod/dev-nginx-pod created

thor@jumphost ~$ kubectl get ns

NAME                 STATUS   AGE

default              Active   19m

dev                  Active   14s

kube-node-lease      Active   19m

kube-public          Active   19m

kube-system          Active   19m

local-path-storage   Active   19m

thor@jumphost ~$ kubectl get pod

No resources found in default namespace.

thor@jumphost ~$ kubectl get pod -n dev

NAME            READY   STATUS    RESTARTS   AGE

dev-nginx-pod   1/1     Running   0          37s

thor@jumphost ~$ 

No comments:

Post a Comment