[英]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打开功能请求
You can do two options, write a script with yq ( https://github.com/mikefarah/yq ) to update the manifest files before deployment您可以执行两个选项,使用 yq ( https://github.com/mikefarah/yq ) 编写脚本以在部署前更新清单文件
Or use the KubernetesManifest patch option ( https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes-manifest?view=azure-devops#patch-action ), for example或者使用 KubernetesManifest 补丁选项( https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes-manifest?view=azure-devops#patch-action ),例如
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.