# Deploy Nginx Service in Kubernetes

## Nginx service Deployment

## Prerequisites

You have to set the Kubernetes cluster to follow these [links](https://docs.neevcloud.com/neevcloud-products/kubernetes/launch-kubernetes-cluster).

### Access the Kubernetes Master Node

To access the master node in a Kubernetes cluster, follow these [LINK:](https://docs.neevcloud.com/neevcloud-products/kubernetes/launch-kubernetes-cluster#to-ssh-into-the-master-node)

Open a terminal session.

Use the SSH protocol to connect:

```
ssh -i access_key user@master-node-address
```

{% hint style="info" %}
Replace `user` with your username and `master-node-address` with the IP address or hostname of the master node.
{% endhint %}

Enter your password or authenticate with your SSH key when prompted.

Once connected, you can perform administrative tasks on the Kubernetes master node.

**Create a Deployment**: Define a Kubernetes Deployment manifest to specify the desired state for the Nginx deployment.

**Expose the Deployment**: Expose the Nginx Deployment through a Kubernetes Service of type **NodePort** or **LoadBalancer**.

**Access from External Sources**: Access the Nginx service using the assigned NodePort or the external IP if you're using a LoadBalancer.

## Here is a step-by-step guide

First, check your nodes Check the status  of your nodes&#x20;

<figure><img src="/files/LgTyMdPH39zF0SNvDtoU" alt=""><figcaption></figcaption></figure>

### **Create a Deployment YAML File (deployment.yaml)**

```
vi deployment.yaml
```

```
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80
```

### **Create a Service YAML File (service.yaml)**

```
vi service.yaml
```

```
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: LoadBalancer
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
```

### Apply the YAML file to create the Nginx Service&#x20;

Once you have created this manifest (deployment.yaml ,  service.yaml for example ), you can apply it to your Kubernetes cluster using the following command:

```
kubectl apply -f deployment.yaml
```

```
kubectl apply -f service.yaml
```

* Check the status of your service using:

```
kubectl get services 
```

<figure><img src="/files/EkMfydZbTQRGRLcFLSzC" alt=""><figcaption></figcaption></figure>

* Once the external IP is assigned, you can use it to access your application.
* For detailed information about the service, run:

```
kubectl describe services 
```

<figure><img src="/files/JNjF9Xk6IqJl49llpJK7" alt=""><figcaption></figcaption></figure>

When you create a LoadBalancer Service in Kubernetes for your NGINX deployment, an external IP address is automatically allocated. This allows you to access NGINX from any location using the given public IP.

After deploying the application and service, find the **public IP** of a node in the Kubernetes cluster.

To verify the service is operational, access it through the load balancer by visiting: <http://load\\_balancer\\_IP>.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.neevcloud.com/neevcloud-guide/kubernetes/deploy-nginx-service-in-kubernetes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
