【发布时间】:2020-06-25 17:46:51
【问题描述】:
我正在尝试使用 azure devops git repo 中的管道设置将 Spring Boot 应用程序部署到 azure kubernetes 集群。但是 aks 部署失败并出现以下错误:
无法提取图像“sapcemission.azurecr.io/spaceship”:[rpc 错误: 代码 = 未知 desc = 来自守护进程的错误响应:清单 sapcemission.azurecr.io/spaceship:最新未找到:清单未知: 未找到标记为“最新”的清单,rpc 错误:代码 = 未知 desc = 来自守护程序的错误响应:获取 https://sapcemission.azurecr.io/v2/spaceship/manifests/latest: 未授权:需要认证,访问 https://aka.ms/acr/authorization 了解更多信息。]
我的项目是一个包含两个模块的 Spring Boot 多模块项目。我正在尝试同时部署它们。我在这里做错了什么?
azure-pipelines.yml
# Deploy to Azure Kubernetes Service
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: 'd5d300b9-b22f-4b38-a5c8-35526548a630'
imageRepositoryCommandCenter: 'commandcenter'
imageRepositorySpaceShip: 'spaceship'
containerRegistry: 'sapcemissipion.azurecr.io'
dockerfilePathCommandCenter: '**/command-center/Dockerfile'
dockerfilePathSpaceShip: '**/space-ship/Dockerfile'
tag: '$(Build.BuildId)'
imagePullSecret: 'sapcemission13564b3d-auth'
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
- task: Docker@2
displayName: Build and push an command center image to container registry
inputs:
command: buildAndPush
repository: $(imageRepositoryCommandCenter)
dockerfile: $(dockerfilePathCommandCenter)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- task: Docker@2
displayName: Build and push an space ship image to container registry
inputs:
command: buildAndPush
repository: $(imageRepositorySpaceShip)
dockerfile: $(dockerfilePathSpaceShip)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- upload: manifests
artifact: manifests
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
jobs:
- deployment: Deploy
displayName: Deploy
pool:
vmImage: $(vmImageName)
environment: 'spacemission-1550.kube-system'
strategy:
runOnce:
deploy:
steps:
- task: KubernetesManifest@0
displayName: Create imagePullSecret
inputs:
action: createSecret
secretName: $(imagePullSecret)
dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
- task: KubernetesManifest@0
displayName: Deploy to Kubernetes cluster
inputs:
action: deploy
manifests: |
$(Pipeline.Workspace)/manifests/deployment.yml
$(Pipeline.Workspace)/manifests/service.yml
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepositoryCommandCenter):$(tag)
$(containerRegistry)/$(imageRepositorySpaceShip):$(tag)
deployment.yml
apiVersion : apps/v1beta1
kind: Deployment
metadata:
name: commandcenter
spec:
replicas: 1
template:
metadata:
labels:
app: commandcenter
spec:
containers:
- name: commandcenter
image: sapcemission.azurecr.io/commandcenter
ports:
- containerPort: 8080
---
apiVersion : apps/v1beta1
kind: Deployment
metadata:
name: spaceship
spec:
replicas: 1
template:
metadata:
labels:
app: spaceship
spec:
containers:
- name: spaceship
image: sapcemission.azurecr.io/spaceship
ports:
- containerPort: 8081
service.yml
apiVersion: v1
kind: Service
metadata:
name: commandcenter
spec:
type: LoadBalancer
ports:
- port: 8080
selector:
app: commandcenter
---
apiVersion: v1
kind: Service
metadata:
name: spaceship
spec:
type: LoadBalancer
ports:
- port: 8080
selector:
app: spaceship
【问题讨论】:
-
实际错误是
unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information。你看过那个链接吗?您正在创建一个镜像拉取密钥,但我没有看到您在 Kubernetes 清单中指定它。如果您使用的是 AKS 和 ACR,则可以将两者集成,因此不需要图像拉取机密。您尝试过如何解决身份验证问题? -
还有问题吗?它解决了你的问题吗?
标签: docker kubernetes azure-devops azure-aks azure-container-registry