简体   繁体   English

从 Azure DevOps 部署到 AKS 时如何传入环境变量

[英]How to pass in environment variables when deploying to AKS from Azure DevOps

I want to deploy a custom SQL Server image, which needs 4 environment variables passed in to AKS using the following pipeline definition:我想部署一个自定义 SQL 服务器映像,它需要使用以下管道定义将 4 个环境变量传递给 AKS:

  jobs:
  - deployment: Deploy
    condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
    displayName: Deploy
    pool:
      vmImage: $(vmImageName)
    environment: 'xxxx.default'
    strategy:
      runOnce:
        deploy:
          steps:
          - task: KubernetesManifest@0
            displayName: Create imagePullSecret
            inputs:
              action: createSecret
              namespace: $(k8sNamespace)
              secretName: $(imagePullSecret)
              dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
              
          - task: KubernetesManifest@0
            displayName: Deploy to Kubernetes cluster
            inputs:
              action: deploy
              namespace: $(k8sNamespace)
              manifests: |
                $(Pipeline.Workspace)/manifests/deployment.yml
                $(Pipeline.Workspace)/manifests/service.yml
              imagePullSecrets: |
                $(imagePullSecret)
              containers: |
                $(containerRegistry)/$(imageRepository):$(tag)

The manifest files are created by Azure DevOps in this instance, so how would I go along, if I wanted to inject the SA_Password / inistial user configuration for this container?在这种情况下,清单文件是由 Azure DevOps 创建的,那么如果我想为这个容器注入 SA_Password / inistial 用户配置,我该怎么做?

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes-manifest?view=azure-devops#deploy-action https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes-manifest?view=azure-devops#deploy-action

kubernetes-manifest deploy action doesn't have the option to add extra environment variables. kubernetes-manifest 部署操作没有添加额外环境变量的选项。 Feel free to open a feature request at https://github.com/microsoft/azure-pipelines-tasks/issues随时在https://github.com/microsoft/azure-pipelines-tasks/issues打开功能请求

steps:
- task: KubernetesManifest@0
  displayName: Patch
  inputs: 
    action: patch
    kind: pod
    name: demo-5fbc4d6cd9-pgxn4
    mergeStrategy: strategic
    patch: '{"spec":{"template":{"spec":{"containers":[{"env":[{"name":"SA_Password","value":"1234"}]}]}}}}'
    kubernetesServiceConnection: someK8sSC
    namespace: default

My contribution to Tummala comment is that if you have control over how the docker image is built, I suggest adding env variables from there instead.我对 Tummala 评论的贡献是,如果您可以控制 docker 图像的构建方式,我建议从那里添加 env 变量。 So if you have a docker build that is triggered when commiting on the develop branch, you can just pass that env to that docker image.因此,如果您有一个在开发分支上提交时触发的 docker 构建,您可以将该环境传递给该 docker 映像。

I have a dedicated post talking about CI/CD in Azure DevOps, in case you're interested in: Building CI/CD pipelines for Kubernetes with Azure DevOps and GitFlow .如果您对以下内容感兴趣,我在 Azure DevOps 中有专门的帖子讨论 CI/CD: 使用 Z3A580F142203677F1F0BC30898F63 为 Kubernetes 构建 CI/CD 管道

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

相关问题 Azure 用于 AKS Kubectl 任务的 devops 管道未能将清单部署到 AKS - Azure devops pipeline for AKS Kubectl task failing to deploying manifest into AKS AKS Azure DevOps 构建代理 - AKS Azure DevOps Build Agent Azure开发人员将推送映像构建到Aks - Azure devops build push image to aks 如何编写正确的 yaml 以在 Azure devops 中部署 kubernetes 集群? - How to write correct yaml for deploying kubernetes cluster in Azure devops? 从 AzureML 部署到 AKS - 设置污点和容忍度 - Deploying from AzureML into AKS - Set Taints & Tolerations 尝试通过 Azure 管道将来自 Azure KeyVault 的秘密作为环境变量传递给部署在 AKS 上的应用程序 - Trying to pass secret from Azure KeyVault via Azure pipeline as env var to an app deployed on AKS 如何使用 python 从 azure aks 获取 kubectl 配置? - how to get kubectl configuration from azure aks with python? 使用Azure DevOps Pipeline的AKS Kubernetes-头盔升级错误 - AKS Kubernetes with Azure DevOps Pipeline - helm upgrade error 与詹金斯同时部署到多个k8s集群的azure aks - azure aks deploying to multiple k8s clusters simultaneously with jenkins 使用 azure-sdk-for-python 将节点部署到 AKS 集群 - Deploying node to AKS cluster using azure-sdk-for-python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM