Deploying a Nginx Application on Kubernetes
In this section, we will explore the process of deploying a Nginx web server application on a Kubernetes cluster. Nginx is a popular open-source web server that can be easily containerized and deployed on Kubernetes.
Nginx Deployment Manifest
To deploy Nginx on Kubernetes, we need to create a Deployment manifest. Here's an example YAML file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
This Deployment manifest creates three replicas of the Nginx container, each listening on port 80.
Deploying the Nginx Application
To deploy the Nginx application, you can use the kubectl
command-line tool:
kubectl apply -f nginx-deployment.yaml
This command will create the Nginx Deployment in your Kubernetes cluster.
Accessing the Nginx Application
To access the Nginx application, you need to create a Kubernetes Service. Here's an example Service manifest:
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
selector:
app: nginx
This Service manifest exposes the Nginx Deployment using a LoadBalancer service type, which will create a public IP address for accessing the application.
You can apply the Service manifest using the following command:
kubectl apply -f nginx-service.yaml
Once the Service is created, you can access the Nginx application using the external IP address assigned to the LoadBalancer service.
By deploying Nginx on Kubernetes, you can take advantage of Kubernetes' features, such as automatic scaling, self-healing, and load balancing, to ensure the reliability and scalability of your web application.