首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >拆分构建和部署管道,无法确定k8s清单上传的位置

拆分构建和部署管道,无法确定k8s清单上传的位置
EN

Stack Overflow用户
提问于 2021-03-14 08:07:56
回答 1查看 69关注 0票数 0

所以我采用了系统生成的azure-pipelines.yml,现在我将它分成build.yamldeployment.yaml,它们在Azure DevOps中都有自己的管道。

我已经向production分支添加了分支和构建验证,因此需要将PR合并到其中。创建PR时,它会自动运行Build,从而运行build.yaml管道。

如果通过,则可以审批并合并到production中。然后,合并触发Deployment,从而触发deployment.yaml管道。

Build正在工作。Deployment不是,原因是它找不到k8s清单...基本上,这一部分在系统中生成azure-pipelines.yml

代码语言:javascript
复制
- upload: k8s
  artifact: k8s

以下是自动生成的内容的完整上下文:

代码语言:javascript
复制
trigger:
- production

resources:
- repo: self

variables:

  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: '<GUID>'
  imageRepository: 'app'
  containerRegistry: 'appacr.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)'
  tag: '$(Build.BuildId)'
  imagePullSecret: 'appacr1c5a-auth'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: Docker@2
      displayName: Build and push an api image to container registry
      inputs:
        command: buildAndPush
        repository: $(imageRepository)-api
        dockerfile: $(dockerfilePath)/api/Dockerfile
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: |
          $(tag)

    - upload: k8s
      artifact: k8s

- stage: Deploy
  displayName: Deploy stage
  dependsOn: Build
  jobs:
    - deployment: Deploy
      displayName: Deploy
      pool:
        vmImage: $(vmImageName)
      environment: 'App Production AKS'
      strategy:
        runOnce:
          deploy:
            steps:
            - task: KubernetesManifest@0
              displayName: Create imagePullSecret
              inputs:
                action: createSecret
                secretName: $(imagePullSecret)
                kubernetesServiceConnection: 'App Production AKS'
                dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
            - task: KubernetesManifest@0
              displayName: Deploy to api Kubernetes cluster
              inputs:
                action: deploy
                kubernetesServiceConnection: 'App Production AKS'
                manifests: |
                  $(Pipeline.Workspace)/k8s/aks/api.yaml
                imagePullSecrets: |
                  $(imagePullSecret)
                containers: |
                  $(containerRegistry)/$(imageRepository)-api:$(tag)

这是我如何将其拆分的方法:

代码语言:javascript
复制
# build.yaml (works)
trigger: none

resources:
- repo: self

variables:
- template: templates/variables.yaml

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: Docker@2
      displayName: Build and push an api image to container registry
      inputs:
        command: buildAndPush
        repository: $(imageRepository)-api
        dockerfile: $(dockerfilePath)/api/Dockerfile
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: |
          $(tag)
    - upload: k8s
      artifact: k8s

还有..。

代码语言:javascript
复制
# deployment.yaml (does not work)
trigger: 
  branches: 
    include:
    - production

resources:
- repo: self

variables:
- template: templates/variables.yaml

stages:
# - template: templates/changed.yaml
- stage: Deploy
  displayName: Deploy stage
  # dependsOn: Build
  jobs:
  - deployment: Deploy
    displayName: Deploy
    pool:
      vmImage: $(vmImageName)
    environment: 'App Production AKS'
    strategy:
      runOnce:
        deploy:
          steps:
          - task: PublishPipelineArtifact@1
            displayName: Publish k8s manifests
            inputs:
              targetPath: $(Build.SourcesDirectory)/k8s
              artifactName: k8s
              artifactType: pipeline
          - task: KubernetesManifest@0
            displayName: Create imagePullSecret
            inputs:
              action: createSecret
              secretName: $(imagePullSecret)
              kubernetesServiceConnection: 'App Production AKS'
              dockerRegistryEndpoint: $(dockerRegistryServiceConnection)        
          - task: KubernetesManifest@0
            displayName: Deploy to api Kubernetes cluster
            inputs:
              action: deploy
              kubernetesServiceConnection: 'App Production AKS'
              manifests: |
                $(Pipeline.Workspace)/k8s/aks/api.yaml
              imagePullSecrets: |
                $(imagePullSecret)
              containers: |
                $(containerRegistry)/$(imageRepository)-api:$(tag)

我尝试了十几种不同的方法来发布k8s清单,错误消息通常是这样的:

代码语言:javascript
复制
##[error]Path does not exist: /home/vsts/work/1/s/k8s

# or 

##[error]No manifest file(s) matching /home/vsts/work/1/k8s/aks/api.yaml was found.

如何解决这个问题的建议?

显然,有一些概念我没有完全掌握。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-15 05:58:48

好吧,这是否被认为是好的/实践是另一回事,但我确实让它在以下情况下工作:

代码语言:javascript
复制
# deployment.yaml (does not work)
trigger: 
  branches: 
    include:
    - production

resources:
- repo: self

variables:
- template: templates/variables.yaml

stages:
- stage: Publish
  displayName: Publish artifacts
  jobs:
  - job: Publish
    displayName: Publish
    pool:
      vmImage: $(vmImageName)
    steps:
    - upload: k8s
      artifact: k8s
- stage: Deploy
  displayName: Deploy stage
  dependsOn: Publish
  jobs:
  - deployment: Deploy
    displayName: Deploy
    pool:
      vmImage: $(vmImageName)
    environment: 'App Production AKS'
    strategy:
      runOnce:
        deploy:
          steps:
          - task: KubernetesManifest@0
            displayName: Create imagePullSecret
            inputs:
              action: createSecret
              secretName: $(imagePullSecret)
              kubernetesServiceConnection: 'App Production AKS'
              dockerRegistryEndpoint: $(dockerRegistryServiceConnection)        
          - task: KubernetesManifest@0
            displayName: Deploy to api Kubernetes cluster
            inputs:
              action: deploy
              kubernetesServiceConnection: 'App Production AKS'
              manifests: |
                $(Pipeline.Workspace)/k8s/aks/api.yaml
              imagePullSecrets: |
                $(imagePullSecret)
              containers: |
                $(containerRegistry)/$(imageRepository)-api:$(tag)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66619806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档