我可以使用从Pod中的init容器创建的configmap吗 [英] can i use a configmap created from an init container in the pod

查看:83
本文介绍了我可以使用从Pod中的init容器创建的configmap吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将值从init容器传递"到容器.由于configmap中的值在命名空间之间共享,因此我认为可以将其用于此目的.这是我的job.yaml(包含伪造的信息):

I am trying to "pass" a value from the init container to a container. Since values in a configmap are shared across the namespace, I figured I can use it for this purpose. Here is my job.yaml (with faked-out info):

apiVersion: batch/v1
kind: Job
metadata:
  name: installer-test
spec:
  template:
    spec:
      containers:
      - name: installer-test
        image: installer-test:latest
        env:
        - name: clusterId
          value: "some_cluster_id"
        - name: in_artifactoryUrl
          valueFrom:
            configMapKeyRef:
              name: test-config
              key: artifactorySnapshotUrl
      initContainers:
      - name: artifactory-snapshot
        image: busybox
        command: ['kubectl', 'create configmap test-config --from-literal=artifactorySnapshotUrl=http://artifactory.com/some/url']
      restartPolicy: Never
  backoffLimit: 0

这似乎不起作用(尽管此编辑注释后面的语句可能仍然正确,但这不起作用,因为在busybox映像中kubectl不是可识别的命令),我假设pod只能在创建容器之前,从创建的配置映射中读取值.还有其他人遇到过在容器之间传递值的困难吗,您是怎么解决的?

This does not seem to work ( although the statements following this edit note may still be correct, this is not working because kubectl is not a recognizable command in the busybox image), and I am assuming that the pod can only read values from a configmap created BEFORE the pod is created. Has anyone else come across the difficulty of passing values between containers, and what did you do to solve this?

我是否应该将configmap部署在另一个Pod中,然后等待部署它,直到configmap存在?

Should I deploy the configmap in another pod and wait to deploy this one until the configmap exists?

(我知道我可以将文件写入卷,但是除非绝对必要,否则我不愿意这样做,因为这实际上意味着我们的docker映像必须耦合到存在某些特定文件的环境中)

(I know I can write files to a volume, but I'd rather not go that route unless it's absolutely necessary, since it essentially means our docker images must be coupled to an environment where some specific files exist)

推荐答案

您可以创建一个EmptyDir卷,并将该卷安装到两个容器上.与persistent volume不同,EmptyDir没有可移植性问题.

You can create an EmptyDir volume, and mount this volume onto both containers. Unlike persistent volume, EmptyDir has no portability issue.

apiVersion: batch/v1
kind: Job
metadata:
  name: installer-test
spec:
  template:
    spec:
      containers:
      - name: installer-test
        image: installer-test:latest
        env:
        - name: clusterId
          value: "some_cluster_id"
        volumeMounts:
        - name: tmp
          mountPath: /tmp/artifact
      initContainers:
      - name: artifactory-snapshot
        image: busybox
        command: ['/bin/sh', '-c', 'cp x /tmp/artifact/x']
        volumeMounts:
        - name: tmp
          mountPath: /tmp/artifact
      restartPolicy: Never
      volumes:
      - name: tmp
        emptyDir: {}
  backoffLimit: 0

这篇关于我可以使用从Pod中的init容器创建的configmap吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆