Change index.html nginx kubernetes deployment

放肆的年华 提交于 2021-02-08 10:12:58

问题


I have this deployment:

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.


回答1:


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>



回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/49904784/change-index-html-nginx-kubernetes-deployment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!