更改index.html nginx kubernetes部署

问题描述 投票:0回答:5

我有这样的部署:

我能够在我的一个 Pod 上编辑索引页面,但如何将其提交到部署映像?因此,当我扩展应用程序时,所有新的 Pod 都将具有相同的图像并编辑了索引。

nginx kubernetes
5个回答
5
投票

这对我有用

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

和简单的配置映射:

data:
<html></html>

0
投票

您必须使用更新后的index.html 创建一个新映像,然后在部署中使用此新映像。

如果您希望index.html易于修改,那么

  1. 创建一个没有index.html文件的新图像
  2. 将index.html的内容存储在configMap中
  3. 将 configMap 批量挂载(如此处所述)到您想要挂载 index.html 的路径上

然后,每当你想更新index.html时,你只需要更新ConfigMap并等待几分钟即可。 Kubernetes 将负责同步更新的 index.html。


0
投票

遵循这个答案和这个自述文件

可以使用以下命令创建 configMap

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

然后将此cm添加为k8s部署对象中的volumeMount。


0
投票

使用 init 容器进行任何预处理,或者如上所述在使用之前相应地更改 docker 镜像。


0
投票

那么,在不重新部署的情况下,通常不可能执行到 nginx pod 并更改静态网站的内容吗?

© www.soinside.com 2019 - 2024. All rights reserved.