繁体   English   中英

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

[英]How to use environment variables in init container args in kubernetes/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中为初始化容器正确使用环境变量?

在初始化容器中添加环境变量。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM