Cloud Computing 4 min read

Deploying and Exposing an Nginx Service on Kubernetes with YAML Generation and Scaling

This guide walks through creating an Nginx deployment on Kubernetes, exposing it via a NodePort service, generating the corresponding YAML configuration, performing dynamic scaling tests, and using various kubectl commands to manage resources and namespaces.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Deploying and Exposing an Nginx Service on Kubernetes with YAML Generation and Scaling

1. Deploy an Nginx instance

Run the following command to create a deployment named nginx using the nginx:1.20 image: kubectl create deployment nginx --image=nginx:1.20 Verify the pod is running: kubectl get pod -o wide Example output shows the pod nginx-7fb9867-cjnzj in the Running state.

2. Expose the Nginx service

Expose the deployment on port 80, targeting container port 8080, using a NodePort:

kubectl expose deployment nginx --port=80 --target-port=8080 --type=NodePort

Check the services and pods: kubectl get pod,svc -o wide The service nginx appears with a NodePort (e.g., 80:31527/TCP).

3. Generate YAML for the exposed service

Use a dry‑run to output the service definition in YAML:

kubectl expose deployment nginx --port=80 --target-port=8080 --type=NodePort --dry-run -o yaml

The resulting YAML includes apiVersion, kind, metadata, labels, selector, and the type: NodePort specification.

4. Dynamic scaling test

List the current deployment to observe replica settings:

kubectl get deployment

5. View all namespaces

Show pods across all namespaces:

kubectl get pods --all-namespaces

6. Generate YAML resource files directly

Create a deployment YAML without applying it:

kubectl create deployment nginx --image=nginx:1.20 --dry-run -o yaml

7. Deprecated method for exporting YAML

The older --export flag is no longer supported; the command shown is:

kubectl get deploy nginx-deployment -o yaml --export > my.deploy.yaml

Finally, the article includes recommended reading links to Redis tutorials and a call to like, share, and follow the author.

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.

DeploymentNginxYAMLServicecloudscaling
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

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.