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

标签 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 中正确使用环境变量?

最佳答案

在init容器中添加环境变量。

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

关于git - 如何在 kubernetes/openshift 的初始化容器参数中使用环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53275332/

相关文章:

kubernetes - 仪表板未运行

git - 在没有远程的情况下创建 git 子模块

ruby - Gitlab - NoMethodError(未定义的方法 `tag_names' 为 nil :NilClass):

windows - 如何在 Windows 上安装 Git - 下载位置和版本

git - 使用 Nginx 和 Phusion Passenger 将 rails Gitlab 项目自动部署到子域

mysql - 无法使用 go 和 docker 连接到 mysql 服务器 - 调用 tcp 127.0.0.1 :3306: connect: connection refused

docker - Apache kafka 无效接收大小

Dockerfile 构建从最终镜像中删除源代码

kubernetes - 如何在每个月的第一个星期日运行 Kubernetes Cron Job?

Azure Kubernetes - 具有 Https 服务的内部负载均衡器?