如何从 Kubernetes 中的 ConfigMap 填充图像值?

May*_*ani 6 kubernetes

我想在 kubernetes 配置中写入 docker 映像名称,然后在我的部署文件中使用它,而不是直接对其进行硬编码。所以而不是:

image: "nginx:latest

我想做以下事情:

image:
 valueFrom:
  configMapKeyRef:
   name: docker-config
   key: docker-image
Run Code Online (Sandbox Code Playgroud)

怎样才能做到或有其他替代方案?谢谢。

Sur*_*noi 5

如果您想更新图像键的值您可以使用以下数据驱动命令,例如使用set verb

  # Set a deployment's nginx container image to 'nginx:1.9.1', and its busybox container image to 'busybox'.
  kubectl set image deployment/nginx busybox=busybox nginx=nginx:1.9.1

  # Update all deployments' and rc's nginx container's image to 'nginx:1.9.1'
  kubectl set image deployments,rc nginx=nginx:1.9.1 --all

  # Update image of all containers of daemonset abc to 'nginx:1.9.1'
  kubectl set image daemonset abc *=nginx:1.9.1

  # Print result (in yaml format) of updating nginx container image from local file, without hitting the server
  kubectl set image -f path/to/file.yaml nginx=nginx:1.9.1 --local -o yaml
Run Code Online (Sandbox Code Playgroud)

您可以通过使用获得更多详细信息

kubectl set image --help
Run Code Online (Sandbox Code Playgroud)

这是更新资源的更多示例


P E*_*ram 4

这不是从 configmap 更新图像值的正确方法。也可能有其他方法。我能想到的实现方法之一是使用以下命令

cat some-depl.yaml | run 'sed' command to update image value | kubectl apply -f - 
Run Code Online (Sandbox Code Playgroud)