> ## Content Index
> Fetch the complete content index at: https://scriptcrunch.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How To Change Nginx index.html in Kubernetes With Configmap
- URL: https://scriptcrunch.com/change-nginx-index-configmap/
- Published: 2022-08-29T05:07:00.000Z
- Updated: 2026-06-23T08:56:00.000Z
- Author: Aswin Vijayan
- Tags: Kubernetes, #Migrated-1758801465347, #wp, #wp-post, #Import 2025-09-25 11:57

In this [guide](https://scriptcrunch.com/tag/guides/), you will learn how to change the default index.html in [Kubernetes](https://scriptcrunch.com/tag/kubernetes/) Nginx deployment with an `index.html` file from the configmap.

Here is what we are going to do.

1. Create a config map with `index.html` file as data
2. Add the `index.html` configmap to the Nginx deployment as volume.

## Kubernetes Nginx index.html Configmap

If you take a look at the following configmap, under the data section, we are creating are adding a file index.html with custom HTML content.

Save the manifest as `index-html-configmap.yaml`

```
apiVersion: v1
kind: ConfigMap
metadata:
  name: index-html-configmap
  namespace: default
data:
  index.html: |
    <html>
    <h1>Welcome</h1>
    </br>
    <h1>Hi! This is a configmap Index file </h1>
    </html
```

Create the config map

```
kubectl apply -f index-html-configmap.yaml
```

## Kubernetes Nginx Deployment With index.html Configmap

Now let's have a look at the deployment config which uses the `index.html` config map.

Save the following manifest as `nginx.yaml`

```
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: default
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
        volumeMounts:
            - name: nginx-index-file
              mountPath: /usr/share/nginx/html/
      volumes:
      - name: nginx-index-file
        configMap:
          name: index-html-configmap
```

Here is what we are doing in the deployment.

1. Creating a volume named `nginx-index-file` mapping the configmap.
2. Under `volumeMounts`, we are adding the configmap that contains the index.html file to the `/usr/share/nginx/html/` location to replace the Nginx default `index.html`

Now create the deployment.

```
kubectl apply -f nginx.yaml
```

Now if you check the Nginx deployment will have the custom index.html file you have added through the configmap.

## Validate the Change With an Nginx Service

If you want to validate the change from the UI, you need to add an Nginx service to the deployment.

We will create a NodePort service to access the Nginx deployment from any Kubernetes node IP on port 32000.

Save the following manifest as `nginx-service.yaml`

```
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: default
spec:
  selector:
    app: nginx
  type: NodePort
  ports:
    - port: 80
      nodePort: 32000
      targetPort: 80
```

Here we are explicitly mentioning the nodeport as 32000.

Create the service.

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

Now you will be able to access the Nginx deployment on the Node port `32000` which displays the custom index.html file created via configmap.

## Conclusion

In this guide, you have learned to effectively use Kubernetes configmap to replace the Nginx index page.

Configmap is an important topic in [Kubernetes certification](https://scriptcrunch.com/kubernetes-exam-guide/).

If you are preparing for [Kubernetes certification](https://scriptcrunch.com/tag/kubernetes-certifications/), check out the [Linux Foundation Coupon](https://scriptcrunch.com/linux-foundation-coupon/) page to get discounts on CKA, CKAD, CKS, and KCNA certifications.