Cloud Native 2 min read

Two Methods to Deploy an Nginx Pod in Kubernetes

This article demonstrates two approaches for creating an Nginx pod in Kubernetes: using direct kubectl commands to pull the image and run a pod, and defining a pod manifest YAML file with specifications, followed by kubectl create/apply/delete commands.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Two Methods to Deploy an Nginx Pod in Kubernetes

This guide shows two common ways to launch an Nginx container as a pod in a Kubernetes cluster.

Method 1 – Imperative commands: Pull the latest Nginx image and start a pod directly with

docker pull nginx:latest<br/>kubectl run --image=nginx:latest nginx-test-app --port=80

. After the pod is created you can inspect it with commands such as

kubectl get pod<br/>kubectl exec podname <command><br/>kubectl describe pod podname<br/>kubectl logs podname

.

Method 2 – Declarative YAML manifest: Create a nginx.yaml file that describes the pod:

apiVersion: v1<br/>kind: Pod<br/>metadata:<br/>  namespace: default<br/>  name: newnginx<br/>spec:<br/>  containers:<br/>  - image: nginx:latest<br/>    imagePullPolicy: IfNotPresent<br/>    name: nginx-test-app<br/>    ports:<br/>    - containerPort: 80<br/>      protocol: TCP

Apply the manifest with the standard kubectl lifecycle commands:

kubectl create -f nginx.yaml<br/>kubectl apply -f nginx.yaml<br/>kubectl delete -f nginx.yaml
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeKubernetesNGINXYAMLPodkubectl
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.