Change index.html nginx kubernetes deployment

4/18/2018

I have this deployment:

enter image description here

I was able to edit the index page at one of my pods, but how can I commit it to the deployment image? So when I scale the application all new pods will have the same image with index edited.

-- Fabiano Jamati
kubernetes
nginx

4 Answers

4/19/2018

You will have to create a new image with the updated index.html, and then use this new image on your deployments.

If you want index.html to be easily modifiable, then

  1. Create a new image without the index.html file
  2. Store the contents of index.html in a configMap
  3. Volume mount the configMap (as explained here) onto the path where you want index.html to be mounted

Then, whenever you want to update the index.html, you just have to update the ConfigMap and wait for a few minutes. Kubernetes will take care of syncing the updated index.html.

-- Nizar M
Source: StackOverflow

2/27/2020

Use init container for any preprocessing or as stated above change docker image accordingly before using it.

-- vishnu gupta
Source: StackOverflow

9/25/2019

Following this answer and this readme

One can create a configMap with the following command

kubectl create configmap nginx-index-html-configmap --from-file=index.html -o yaml --dry-run

And then add this cm as a volumeMount in k8s deployment object.

-- Sat93
Source: StackOverflow

2/27/2020

It's worked for me

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    name: nginx
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
      - containerPort: 80
    volumeMounts:
      - mountPath: /usr/share/nginx/html/index.html
        name: nginx-conf
        subPath: index.html
  volumes:
    - name: nginx-conf
      configMap:
        name: nginx-index-html-configmap

And simple configmap with:

data:
<html></html>
-- cryptoparty
Source: StackOverflow