Deploy Nginx Web Server on Kubernetes Cluster
Some of the Nautilus team developers are developing a static website and they want to deploy it on Kubernetes cluster. They want it to be highly available and scalable. Therefore, based on the requirements, the DevOps team has decided to create a deployment for it with multiple replicas. Below you can find more details about it:
-
Create a deployment using nginx image with latest tag only and remember to mention the tag i.e nginx:latest. Name it as nginx-deployment. The container should be named as nginx-container, also make sure replica counts are 3.
-
Create a NodePort type service named nginx-service. The nodePort should be 30011.
Steps
- Create a
k3s-deployment.yml using this YAML file
-
Run the following command to create deployment and service:
kubectl apply -f k3s-deployment.yml
-
Verify results:
kubectl get deployment.apps
kubectl get pods
kubectl get svc
Good to Know?
Kubernetes Services
- Purpose: Stable network endpoint for pods
- Service Discovery: Find and connect to services
- Load Balancing: Distribute traffic across pod replicas
- Abstraction: Decouple clients from pod implementation
Service Types
- ClusterIP: Internal cluster communication (default)
- NodePort: Expose service on each node’s IP
- LoadBalancer: Cloud provider load balancer
- ExternalName: DNS CNAME record for external services
High Availability
- Multiple Replicas: Run multiple pod instances
- Health Checks: Automatic failure detection and recovery
- Rolling Updates: Zero-downtime deployments
- Pod Distribution: Spread pods across nodes
NodePort Services
- Port Range: 30000-32767 (default range)
- External Access: Access service from outside cluster
- Node IP: Service accessible on all node IPs
- Firewall: Ensure nodePort is open in firewall