Deploying a sample Nginx application on your Minikube cluster
Deploying a sample Nginx application on your Minikube cluster and exposing it involves creating a Deployment, creating a Service object, and using port-forwarding to access it directly from your host browser or terminal.
Table of Contents
Step 1: Create the Nginx Deployment
A Kubernetes Deployment manages a replicated set of pods. Run the following command to deploy Nginx using the official image:
kubectl create deployment nginx-app --image=nginx:latest
Verify that the pod is running:
kubectl get pods
Step 2: Expose the Deployment as a Service
To make the Nginx application accessible, create a Service that exposes the deployment internally within the cluster on port 80:
kubectl expose deployment nginx-app --type=ClusterIP --port=80
Verify that the service has been created:
kubectl get services
Step 3: Access via Port Forwarding
Port forwarding allows you to forward traffic from your local machine directly to the Nginx pod or service without needing an Ingress controller or NodePort setup:
kubectl port-forward svc/nginx-app 8080:80
Note: Keep this terminal window open. This command binds port 8080 on your local machine to port 80 on the Nginx service.
Step 4: Test the Application
Open a second terminal window or your web browser and navigate to the forwarded port:
curl http://localhost:8080
You should see the default “Welcome to nginx!” HTML response page.
Summary of Useful Management Commands
Read more here: Source link
