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.
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: TCPApply the manifest with the standard kubectl lifecycle commands:
kubectl create -f nginx.yaml<br/>kubectl apply -f nginx.yaml<br/>kubectl delete -f nginx.yamlSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
