gpt4 book ai didi

azure - 新镜像未部署到 AKS

转载 作者:行者123 更新时间:2023-12-02 07:34:51 25 4
gpt4 key购买 nike

我已经将最初的 azure-pipelines.yml 拆分出来使用模板、迭代等...无论出于何种原因,尽管使用了latest,但新图像都没有被部署标签和/或imagePullPolicy: Always .

此外,我基本上有两个管道 PRRelease :

  • PR当提交 PR 请求合并到 production 时触发。它会自动触发此管道来运行单元测试、构建 Docker 镜像、进行集成测试等,然后如果一切都通过,则将镜像推送到 ACR。
  • PR pipeline正在通过,PR获得批准,合并到production然后触发Release管道。

这是我的 k8s 之一的示例部署 list (应用这些 list 时,管道显示 unchanged):

apiVersion: apps/v1
kind: Deployment
metadata:
name: admin-v2-deployment-prod
namespace: prod
spec:
replicas: 3
selector:
matchLabels:
component: admin-v2
template:
metadata:
labels:
component: admin-v2
spec:
containers:
- name: admin-v2
imagePullPolicy: Always
image: appacr.azurecr.io/app-admin-v2:latest
ports:
- containerPort: 4001
---
apiVersion: v1
kind: Service
metadata:
name: admin-v2-cluster-ip-service-prod
namespace: prod
spec:
type: ClusterIP
selector:
component: admin-v2
ports:
- port: 4001
targetPort: 4001

这里是各种管道相关的.yamls我已经分手了:

公关和发布:

# templates/variables.yaml
variables:
dockerRegistryServiceConnection: '<GUID>'
imageRepository: 'app'
containerRegistry: 'appacr.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)'
tag: '$(Build.BuildId)'
imagePullSecret: 'appacr1c5a-auth'

vmImageName: 'ubuntu-latest'
<小时/>

公关:

# pr.yaml
trigger: none

resources:
- repo: self

pool:
vmIMage: $(vmImageName)

variables:
- template: templates/variables.yaml

stages:
- template: templates/changed.yaml
- template: templates/unitTests.yaml
- template: templates/build.yaml
parameters:
services:
- api
- admin
- admin-v2
- client
- template: templates/integrationTests.yaml
# templates/build.yaml
parameters:
- name: services
type: object
default: []

stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
steps:
- ${{ each service in parameters.services }}:
- task: Docker@2
displayName: Build and push an ${{ service }} image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)-${{ service }}
dockerfile: $(dockerfilePath)/${{ service }}/Dockerfile
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
<小时/>

发布:

# release.yaml
trigger:
branches:
include:
- production

resources:
- repo: self

variables:
- template: templates/variables.yaml

stages:
- template: templates/publish.yaml
- template: templates/deploy.yaml
parameters:
services:
- api
- admin
- admin-v2
- client
# templates/deploy.yaml
parameters:
- name: services
type: object
default: []

stages:
- 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)
- ${{ each service in parameters.services }}:
- task: KubernetesManifest@0
displayName: Deploy to ${{ service }} Kubernetes cluster
inputs:
action: deploy
kubernetesServiceConnection: 'App Production AKS'
manifests: |
$(Pipeline.Workspace)/k8s/aks/${{ service }}.yaml
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepository)-${{ service }}:$(tag)
  • 两者PRRelease通过...
  • 新图像位于 ACR 中...
  • 我已提取图像以验证它们是否具有最新更改...
  • 它们只是没有部署到 AKS。

对于我在这里做错的事情有什么建议吗?

最佳答案

For whatever reason, the new images are not being deployed despite using latest tag

Kubernetes 如何知道有新镜像? Kubernetes 配置是声明性的。 Kubernetes 已经在运行曾经的“最新”镜像。

Here is an example of one of my k8s deployment manifests (the pipeline says unchanged when these are applied)

是的,它未更改,因为声明性分散状态更改。部署 list 规定了应该部署什么,它不是命令。

建议的解决方案

每当您构建图像时,请始终为其指定一个唯一的名称。每当您想要部署某些内容时,请始终为应该运行的内容设置一个唯一的名称 - 然后 Kubernetes 将使用滚动部署以优雅的零停机方式管理它 - 除非您将其配置为不同的行为。

关于azure - 新镜像未部署到 AKS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66658836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com