Deploying Nginx Web Server on Kubernetes Cluster
The task of deploying a static website for the Nautilus team's developers on a Kubernetes cluster has been successfully completed. The deployment meets the key requirements of high availability and scalability by utilizing a multi-replica setup with a NodePort service.
The solution was implemented by creating two essential Kubernetes objects: a Deployment and a Service, using YAML configuration files for precise control over the resource specifications.
Kubernetes YAML Files and Apply Commands
The following YAML files and commands were used to define and create the deployment and service, ensuring all requirements were met, including the specific container name and NodePort.
nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx-app
template:
metadata:
labels:
app: nginx-app
spec:
containers:
- name: nginx-container
image: nginx:latest
ports:
- containerPort: 80
nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: nginx-app
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30011
The following commands were executed to apply the YAML files:
kubectl apply -f nginx-deployment.yaml
kubectl apply -f nginx-service.yaml
Confirmation Commands and Outputs
The following kubectl
commands were used to verify that the deployment and service were created and configured correctly.
Describe Deployment
kubectl describe deployment nginx-deployment
Output:
Name: nginx-deployment
Namespace: default
CreationTimestamp: Sun, 28 Sep 2025 06:22:06 +0000
Selector: app=nginx-app
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable
Pod Template:
Labels: app=nginx-app
Containers:
nginx-container:
Image: nginx:latest
Port: 80/TCP
This output verifies that the deployment is managing 3 replicas and that the container is correctly named nginx-container
with the nginx:latest
image.
Describe Service
kubectl describe service nginx-service
Output:
Name: nginx-service
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=nginx-app
Type: NodePort
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30011/TCP
Endpoints: 10.244.0.5:80,10.244.0.6:80,10.244.0.7:80
This output confirms that the service is of type NodePort and is exposing the pods on NodePort 30011. It also shows that the service has correctly identified and connected to the three running pods.
Top comments (0)