如何在kubernetes / openshift中的初始化容器args中使用环境变量?

时间:2018-11-13 06:49:58

标签: git docker kubernetes containers openshift

这是我的部署配置的摘录:

...
spec:
  containers:
    - env:
        - name: GIT_USERNAME
          valueFrom:
            secretKeyRef:
              key: username
              name: git
        - name: GIT_PASSWORD
          valueFrom:
            secretKeyRef:
              key: password
              name: git
  initContainers:
    - args:
        - clone
        - '--single-branch'
        - '--'
        - 'https://$(GIT_USERNAME):$(GIT_PASSWORD)@someurl.com/something.git'
        - '/testing/'
      image: alpine/git
      imagePullPolicy: Always
      name: init-clone-repo
      resources: {}
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      volumeMounts:
        - mountPath: /testing
          name: test-volume
  volumes:
    - emptyDir: {}
      name: test-volume
  ...

initContainer失败,因为 $(GIT_USERNAME) $(GIT_PASSWORD)照原样使用并且未扩展。我已经尝试过 $ GIT_USERNAME $ {GIT_USERNAME} ,但我几乎没有想法。

如何在args中为初始化容器正确使用环境变量?

1 个答案:

答案 0 :(得分:3)

在初始化容器中添加环境变量。 规格:   initContainers:     -参数:         -克隆         -'-单分支'         -'-'         -'https:// $(GIT_USERNAME):$(GIT_PASSWORD)@ someurl.com / something.git'         -'/ testing /'       图片:alpine / git       imagePullPolicy:始终       名称:init-clone-repo       环境:         -名称:GIT_USERNAME           valueFrom:             secretKeyRef:               密钥:用户名               名称:git         -名称:GIT_PASSWORD           valueFrom:             secretKeyRef:               密钥:密码               名称:git       资源:{}       TerminationMessagePath:/ dev / termination-log       TerminationMessagePolicy:文件       volumeMounts:         -mountPath:/测试           名称:测试卷   数量:     -emptyDir:{}       名称:测试卷