我想做的是建立并推送我的docker鏡像到Azure容器注冊處,并在Azure kubernetes中部署。所有的作業都很順利,部署正常,應用程式運行正常。 請注意,所有的靜態標簽都是1.0的
。我希望我的管道在嘗試部署時一直采用最新的鏡像,但我不知道如何在鏡像上設定這個最新標簽。
Azure Pipeline
trigger:
- main
資源:
- repo: self
變數:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '4e6ea1xxxxxxxxxxxx9ae2-5f72194d4960'
imageRepository: 'watchdogapp'/span>
containerRegistry: 'xxxx.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/Follis.WatchDog/Dockerfile'
tag: '$(Build.BuildId)'
# Agent VM鏡像名稱
vmImageName: 'ubuntu-latest'
階段:
- 階段: Build
displayName: Build and push stage
作業:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
步驟:
- task: Docker@2
displayName: Build and push image
輸入:
命令: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
buildContext: $(Build.Repository.LocalPath)
tags: |(tag)
$(tag)
- task: Kubernetes@1
displayName: Deploy to Aks
輸入:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'ksWatchDog'
namespace: 'default'
命令: 'apply'
useConfigurationFile: true
configuration: '$(Build.SourcesDirectory)/Follis.WatchDog/deploy_watchdog_kube.yaml'
secretType: 'dockerRegistry'。
containerRegistryType: 'Azure Container Registry'/span>
azureSubscriptionEndpointForSecrets: 'Follis-Az'。
azureContainerRegistry: 'acrfollis.azurecr.io'
forceUpdate: false
kube_deploy.yml是
apiVersion: apps/v1
kind: Deployment
metadata: Deployment
name: watchdog-app
規格:
replicas: 1
選擇器:
matchLabels:/span>
app: watchdog-app
template:
metadata: 元資料:
namespace: default
標簽:
app: watchdog-app
規格:
nodeSelector:
"kubernetes.io/os": linux
容器:
- name:/span> watchdog-app
image: acrfollis.azurecr.io/watchdogapp:latest
imagePullPolicy: Always
resources: Always
請求:
cpu: 100m
記憶體: 128Mi
限制:
cpu: 250m
記憶體: 256Mi
港口:
- containerPort: 5555
env:
- name:/span> WEB_PORT
value: "5555"/span>
- name:/span> ASPNETCORE_URLS
value: "http:// :5555"
- name:/span> ASPNETCORE_ENVIRONMENT
value: "Local"
---
apiVersion: v1
kind: Service
metadata: 服務
name: watchdog-app-service
規格:
型別: LoadBalancer
ports:
- protocol: TCP
埠: 80
targetPort: 5555
選擇器:
app: watchdog-app
該管道沒有抱怨影像上的最新標簽,但部署后
NAME READY STATUS RESTARTS NOMINATED NODE READINESS GATES
client-api-78ff55456-wk5sf 1/1 Running 0 21h 10. 244.0. 6 aks-agentpool-34700069-vmss000000 <none>/span> <none>
watchdog-app-66797b7776-fz94b 1/1 Running 0 82m 10. 244.1. 11 aks-agentpool-34700069-vmss000001 <none> <none>
watchdog-app-b7ddb988-9zsjl 01 **ImagePullBackOff** 0 39s 10. 244.0. 8 aks-agentpool-34700069-vmss000000 <none>/span> <none>
當我做kubectl describe pods describe imagename時
Failed to pull image "acrfollis. azurecr. io/watchdogapp:latest": [rpc錯誤。 code = NotFound desc = failed failed string">failed to pull and unpack image
"acrfollis.azurecr. io/watchdogapp:latest": failed to resolve reference "acrfollis. azurecr.io/watchdogapp:latest": acrfollis.azurecr. io/watchdogapp:latest: not found, rpc error: code = Unknown desc = failed. string">failed to pull and unpack image
"acrfollis.azurecr. io/watchdogapp:latest": failed to resolve reference "acrfollis. azurecr.io/watchdogapp:latest": failed to authorize: failed to fetch anonymous token: unexpected status: 401 Unauthorized]
有什么辦法可以在從管道構建時將我的影像標記為最新的嗎?或者有什么辦法可以引數化kube_deploy.yml以從pipelineyaml獲取$(tag)?
有誰經歷過這種情況?我不是這方面的專家,
uj5u.com熱心網友回復:
最后我想明白了,這個帖子幫了我大忙
https://medium.com/nerd-for-tech/how-to-inject-variables-in-kubernetes-manifest-with-azure-pipelines-e598755be9b。
# Docker。
# 構建并推送鏡像到Azure容器注冊中心 # Docker
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
觸發器:
- main
資源:
- repo: self
變數:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: 'XXXXXXXXXX72194d4960'
imageRepository: 'watchdogapp'
containerRegistry: 'acrXXXX.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/XXXX.WatchDog/Dockerfile'
image-tag: '$(Build.BuildId)'
# Agent VM鏡像名稱
vmImageName: 'ubuntu-latest'
階段:
- 階段: Build
displayName: Build and push stage
作業:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
步驟:
- task: Docker@2
displayName: Build and push image
輸入:
命令: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
buildContext: $(Build.Repository.LocalPath)
tags:
$(image-tag)
- 任務: CopyFiles@2
displayName: Copy files
輸入:
內容: $(build.sourcesDirectory)/XXXX.WatchDog/*.yaml
targetFolder: $(build.artifactStagingDirectory)/k8
- task: PublishBuildArtifacts@1
輸入:
pathtoPublish: $(build.artifactStagingDirectory)
artifactName: drop
- stage:/span> Staging
displayName: Deployment
作業:
- deployment: Staging
池子:
vmImage: $(vmImageName)
environment: STG
戰略:
runOnce:
部署: 部署:
步驟: 步驟:
- 任務: replacetokens@4
輸入:
rootDirectory: '$(Pipeline.Workspace)/drop'
targetFiles: '**/*.yaml'/span>
encoding: 'auto'
tokenPattern: 'rm'
writeBOM: true
actionOnMissing: ' warn'
keepToken: false
actionOnNoFiles: 'fail'/span>
enableTransforms: false
useLegacyPattern: false
enableTelemetry: true
- task: Kubernetes@1
displayName: Deploy to Aks
輸入:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'ksWatchDog'
namespace: 'default'
命令: 'apply'
useConfigurationFile: true
configuration: '$(Pipeline.Workspace)/drop/k8/XXXX.WatchDog/deploy_watchdog_kube.yaml'
secretType: 'dockerRegistry'。
containerRegistryType: 'Azure Container Registry'/span>
azureSubscriptionEndpointForSecrets: 'XXXX-Az'。
azureContainerRegistry: 'acrXXXX.azurecr.io'
forceUpdate: false
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/330615.html
標籤:
