Kubernetes JSON configMap 未安装

发布于 2025-01-20 03:38:15 字数 1077 浏览 0 评论 0原文

我正在尝试将JSON格式的ConfigMap映射到Kubernetes中的Docker Image 我正在使用Config NPM软件包获取配置。

这个想法是我将拥有一个文件开发。这一切都在Localhost中起作用。配置文件的名称与node_env变量相同,我也在部署中设置了该变量。yaml

我使用默认名称空间

这是configmap的开始(我可以看到它是在Google kubernetes中创建的)

我正在运行LS是查看是否已安装了development.json文件,但事实并非如此。我希望替换 /config,并且仅包含开发。json文件,

我也尝试使用子路参数,但结果

我在做什么错?我是否应该在安装configmap的事件中看到。没有任何日志,除非我删除configmap并尝试执行安装座,所以我认为安装

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-development
  namespace: default
data:
  development.json: |
    {
      "production": false,

在这里发生的是安装座:

volumes:
        - name: config-volume
          configMap:
            name: config-development
      containers:
        - name: salesforce-compare-api
          image: XXXX
          command: ["ls"]
          args: ["config", "-la"]
          imagePullPolicy: Always
          env:
          - name: NODE_ENV
            value: "development"
          volumeMounts:
          - name: config-volume
            mountPath: /config/development.json

I am trying to map a configMap in JSON format to my docker image in Kubernetes
I am using config npm package to fetch the configurations.

The idea is that I will have a file development.json in /config directory from there the config package will pick it up. This all works in localhost. The name of the config file is the same as the NODE_ENV variable, which I am also setting in the deployment.yaml

I am using default namespace

This is the beginning of the configMap (I can see it is created in google kubernetes)

I am running ls is the config directory to see if the development.json file has been mounted but it is not. I want the /config to be replaced and only contain the development.json file

I have also tried with the subPath parameter but same result

What am I doing wrong ? Should I see in the events that the configMap is mounted. There is no log of that except when I delete the configMap and try to do the mount, so I figure that the mounting is happening

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-development
  namespace: default
data:
  development.json: |
    {
      "production": false,

Here is the mount:

volumes:
        - name: config-volume
          configMap:
            name: config-development
      containers:
        - name: salesforce-compare-api
          image: XXXX
          command: ["ls"]
          args: ["config", "-la"]
          imagePullPolicy: Always
          env:
          - name: NODE_ENV
            value: "development"
          volumeMounts:
          - name: config-volume
            mountPath: /config/development.json

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2025-01-27 03:38:15

通常,当 configmap 无法挂载时,pod 甚至无法启动。所以它开始的事实表明它已经安装了。

无论如何,您的volumeMounts看起来有问题。

volumeMounts:
  - name: config-volume
    mountPath: /config/development.json

这会导致完整的 configmap 被挂载到名为development.json 的文件夹中,而您实际上只想挂载一个文件。

为此,请使用 子路径

volumeMounts:
  - name: config-volume
    mountPath: /config/development.json
    subPath: development.json

也就是说,如果容器内的 config 文件夹为空,您也可以删除子路径并将 configmap 安装到 /config 目录,因为它不会覆盖任何重要的内容。

volumeMounts:
  - name: config-volume
    mountPath: /config

Usually, when the configmap cannot be mounted, the pod will not even start. So the fact that it started, shows that its mounted.

In any case, your volumeMounts looks problematic.

volumeMounts:
  - name: config-volume
    mountPath: /config/development.json

This lead to the full configmap being mounted into a folder named development.json, while you actually only want to mount the one file.

Use a subpath for this.

volumeMounts:
  - name: config-volume
    mountPath: /config/development.json
    subPath: development.json

That said, if you config folder inside the container is otherwise empty, you can also drop the subpath and mount the configmap to the /config dir, since it will not override anything important.

volumeMounts:
  - name: config-volume
    mountPath: /config
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文