使用环境变量创建容器镜像

时间:2021-04-27 15:22:11

标签: kubernetes

我正在 kubernetes 中创建一些将在三个月后运行的 cron 作业。虽然启动这些 cron 作业的容器的映像名称是众所周知的,但要运行的版本有点未来感。

当我安排 <form> <label>Markup</label> <input id="cof" type="number" value="2"> <br> <label>Materials</label> <input id='mat' type="number" value="0.00" step=".01"> <br> <label>Labor</label> <input id='lab' type="number" value='0.00' step=".01"> <hr> <label>Total: </label> <output id='sum'>0.00</output> </form> 时无法知道映像的版本,因为我希望 cronjob 运行当时可用的最新生产部署。我们的 import React, { useState, useMemo, useEffect } from 'react'; // ... other imports function gridHeatMap({ height, title, viewName }) { const heatMap = useMemo(() => ([ { color: 'redVeryHigh', value: 50 }, { color: 'redHigh', value: 25 }, { color: 'redMedium', value: 20 }, { color: 'redLow', value: 15 }, { color: 'white', value: 0 }, { color: 'greenLow', value: 15 }, { color: 'greenMedium', value: 20 }, { color: 'greenHigh', value: 25 }, { color: 'greenVeryHigh', value: 50 }, ]), []); const [currentHeatMap, setCurrentHeatMap] = useState(heatMap); useEffect(() => { viewName === 'demand' ? setCurrentHeatMap(heatMap) : setCurrentHeatMap(heatMap.reverse()); }, [viewName]); const classes = useStyles(); return ( <div className={classes.root}> <div className={classes.title}>{title}</div> <GridContainer spacing={0}> { currentHeatMap.map((item, index) => ( <Grid key={`grid-${index}-${item.color}`} className={item.color} style={{ flexGrow: '1', height, width: '11%' }} item /> )); } </GridContainer> </div> ); } export default gridHeatMap; 中没有 cronjob,必须从配置映射中获取版本。

  • 有没有办法在 cronjob 中指定容器映像,以便使用从配置映射指定的 env 变量解析映像版本?

1 个答案:

答案 0 :(得分:0)

<块引用>

有没有办法在 cronjob 中指定容器映像,以便使用从配置映射指定的 env 变量解析映像版本?

您可以尝试使用 gitRepo Volume 来实现这一点。

这里不写,你可以参考gitRepo volume in category

注意:在当前版本的 Kubernetes 中,它已被弃用。

不过,同样可以在 initContainer config 中进行配置。 snipped 的参考。

apiVersion: apps/v1
kind: Pod
metadata:
  name: pod
spec:
  volumes:
  - name: config-volume               
    emptyDir: {}
  initContainers:
  - name: clone
    image: alpine/git:1.0.4           
    volumeMounts:
    - name: config-volume
      mountPath: /config              
    envFrom:
      - configMapRef:
          name: cfg                   
    command: ['/bin/sh', '-c']        
    args: ['git clone --branch $(version) https://github.com/ajavageek/foo-config && mv foo-config/* /config']
  containers:
  - name: foo
    image: ajavageek/foo:1.0          
    volumeMounts:
    - name: config-volume
      mountPath: /config              
      readOnly: true