通过 kubectl 任务创建 ConfigMap

Create ConfigMap through kubectl task

作为构建管道的一部分,我想创建一个 ConfigMap,其中包含一个文件的内容,该文件是 Git 存储库的一部分,管道 运行s.

来自该存储库

根据 Azure Pipelines 的 Kubectl 任务,这应该是可能的。但我不知道如何应用它。对于此任务,我的 YAML 看起来如何并不重要,结果始终是 'success'。即使我输入 foo / bar 作为输入参数。 https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes?view=azure-devops

我问过 Microsoft 是否缺少文档或实现本身。我得到的唯一答案是在这里问。他们真正将支持的责任转移到了社区。

这是我的定义:

- task: Kubernetes@1
  displayName: 'Create ConfigMap for /data'
  inputs:
    kubernetesServiceEndpoint: 'cluster-test'
    namespace: 'app-test'
    forceUpdateConfigMap: true
    configMapName: data
    configMapArguments: --from-file $(Build.SourcesDirectory)/data/ExcelTemplate.xlsx

我希望根据文档,对于每个 运行,ConfigMap 将被删除并使用给定 Excel 文件的内容重新创建(和 ExcelTemaplte.xlsx 作为钥匙)。 手动我可以这样做:
kubectl create configmap data --from-file ExcelTemplate.xlsx

链接文档提到了这样的用法(我 d:

    - task: Kubernetes@1
      displayName: configMap with literal values
      inputs:
        azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
        azureResourceGroup: $(azureResourceGroup)
        kubernetesCluster: $(kubernetesCluster)
        command: apply
        arguments: -f mhc-aks.yaml
        secretType: generic
        secretArguments: --from-literal=contoso=$(contosovalue)
        secretName: mysecretkey4
        configMapName: myconfig
        forceUpdateConfigMap: true
        configMapArguments: --from-literal=myname=contoso

但我可以为每个 ConfigMap 参数指定一个 运行dom 值,这样任务就成功了。或者在return中,我可以配置正确的值,结果什么都不做就成功了。

- task: Kubernetes@1
  displayName: 'Create ConfigMap for /data'
  inputs:
    kubernetesServiceEndpoint: 'cluster-test'
    namespace: foobar # does not exist
    forceUpdateConfigMap: true
    configMapName: data
    configMapArguments: 'today is sunny'

是否有人已经使用此任务来创建 ConfigMap?或者是否成功尝试了这项任务?

要知道我必须 运行 此任务两次,一次是删除,一次是使用 apply 命令创建 ConfigMap 的专用清单。或者作为第二种解决方案,只需在 bash 脚本中为 deletion/creation 触发 kubectl 命令。

自上周五以来,似乎已经修复了一些问题。现在以下定义按预期工作:

- task: Kubernetes@1
  displayName: 'Create ConfigMap for /data'
  inputs:
    kubernetesServiceEndpoint: 'cluster-test'
    namespace: 'app-test'
    forceUpdateConfigMap: true
    configMapName: data
    configMapArguments: --from-file $(Build.SourcesDirectory)/data/ExcelTemplate.xlsx