AKS。无法从 acr 中提取图像
AKS. Can't pull image from an acr
我尝试使用秘密从 ACR 中提取图像,但我做不到。
我使用 azure cli 命令创建了资源:
az login
az provider register -n Microsoft.Network
az provider register -n Microsoft.Storage
az provider register -n Microsoft.Compute
az provider register -n Microsoft.ContainerService
az group create --name aksGroup --location westeurope
az aks create --resource-group aksGroup --name aksCluster --node-count 1 --generate-ssh-keys -k 1.9.2
az aks get-credentials --resource-group aksGroup --name aksCluster
az acr create --resource-group aksGroup --name aksClusterRegistry --sku Basic --admin-enabled true
之后我登录并成功将图像推送到从本地计算机创建的 ACR。
docker login aksclusterregistry.azurecr.io
docker tag jetty aksclusterregistry.azurecr.io/jetty
docker push aksclusterregistry.azurecr.io/jetty
下一步是创建一个秘密:
kubectl create secret docker-registry secret --docker-server=aksclusterregistry.azurecr.io --docker-username=aksClusterRegistry --docker-password=<Password from tab ACR/Access Keys> --docker-email=some@email.com
最后我尝试使用来自 ACR 的图像创建 pod:
#pod.yml
apiVersion: v1
kind: Pod
metadata:
name: jetty
spec:
containers:
- name: jetty
image: aksclusterregistry.azurecr.io/jetty
imagePullSecrets:
- name: secret
kubectl create -f pod.yml
结果我有一个状态为 ImagePullBackOff:
的 pod
>kubectl get pods
NAME READY STATUS RESTARTS AGE
jetty 0/1 ImagePullBackOff 0 1m
> kubectl describe pod jetty
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m default-scheduler Successfully assigned jetty to aks-nodepool1-62963605-0
Normal SuccessfulMountVolume 2m kubelet, aks-nodepool1-62963605-0 MountVolume.SetUp succeeded for volume "default-token-w8png"
Normal Pulling 2m (x2 over 2m) kubelet, aks-nodepool1-62963605-0 pulling image "aksclusterregistry.azurecr.io/jetty"
Warning Failed 2m (x2 over 2m) kubelet, aks-nodepool1-62963605-0 Failed to pull image "aksclusterregistry.azurecr.io/jetty": rpc error: code = Unknown desc = Error response from daemon: Get https://aksclusterregistry.azurecr.io/v2/jetty/manifests/latest: unauthorized: authentication required
Warning Failed 2m (x2 over 2m) kubelet, aks-nodepool1-62963605-0 Error: ErrImagePull
Normal BackOff 2m (x5 over 2m) kubelet, aks-nodepool1-62963605-0 Back-off pulling image "aksclusterregistry.azurecr.io/jetty"
Normal SandboxChanged 2m (x7 over 2m) kubelet, aks-nodepool1-62963605-0 Pod sandbox changed, it will be killed and re-created.
Warning Failed 2m (x6 over 2m) kubelet, aks-nodepool1-62963605-0 Error: ImagePullBackOff
怎么了?为什么秘密方法不起作用?
请不要建议我使用服务主体的方法,因为我想了解为什么这种方法不起作用。我认为它必须工作。
这对我来说也不错。也就是说,建议不要使用管理员帐户,而是一种服务原则。使用 SP,您可以对 ACR 实例的访问权限(读取、贡献者、所有者)进行一些精细的控制。
此文档包括使用服务原则在 AKS 和 ACR 之间进行身份验证的两种方法。
https://docs.microsoft.com/en-us/azure/container-registry/container-registry-auth-aks
使用 AKS 的 "old" 方法就是按照您提到的 create secret
进行操作。不再推荐。
"new"方式是附加容器注册表。 This 文章解释了附加 ACR 的 "new" 方法,还提供了 link 旧方法以消除混淆。创建集群时,附加:
az aks create -n myAKSCluster -g myResourceGroup --attach-acr $MYACR
或者,如果您已经创建了集群,请将其更新为:
az aks update -n myAKSCluster -g myResourceGroup --attach-acr $MYACR
备注:
$MYACR
只是没有 .azurecr.io
的注册表名称。例如:MYACR=foobar
而不是 MYACR=foobar.azurecr.io
.
附加 ACR 后,ImagePullBackOff
需要几分钟才能转换为 Running
。
这不完全是问题案例。但是我在使用 Attach ACR 方法时遇到了类似的问题。我的问题是注册表名称中的大写字符。 az cli 生成了以下警告。
Uppercase characters are detected in the registry name. When using its server url in docker commands, to avoid authentication errors, use all lowercase
因此请确保在 Docker 命令的 ACR 网址中使用所有小写字母。
我尝试使用秘密从 ACR 中提取图像,但我做不到。
我使用 azure cli 命令创建了资源:
az login
az provider register -n Microsoft.Network
az provider register -n Microsoft.Storage
az provider register -n Microsoft.Compute
az provider register -n Microsoft.ContainerService
az group create --name aksGroup --location westeurope
az aks create --resource-group aksGroup --name aksCluster --node-count 1 --generate-ssh-keys -k 1.9.2
az aks get-credentials --resource-group aksGroup --name aksCluster
az acr create --resource-group aksGroup --name aksClusterRegistry --sku Basic --admin-enabled true
之后我登录并成功将图像推送到从本地计算机创建的 ACR。
docker login aksclusterregistry.azurecr.io
docker tag jetty aksclusterregistry.azurecr.io/jetty
docker push aksclusterregistry.azurecr.io/jetty
下一步是创建一个秘密:
kubectl create secret docker-registry secret --docker-server=aksclusterregistry.azurecr.io --docker-username=aksClusterRegistry --docker-password=<Password from tab ACR/Access Keys> --docker-email=some@email.com
最后我尝试使用来自 ACR 的图像创建 pod:
#pod.yml
apiVersion: v1
kind: Pod
metadata:
name: jetty
spec:
containers:
- name: jetty
image: aksclusterregistry.azurecr.io/jetty
imagePullSecrets:
- name: secret
kubectl create -f pod.yml
结果我有一个状态为 ImagePullBackOff:
的 pod>kubectl get pods
NAME READY STATUS RESTARTS AGE
jetty 0/1 ImagePullBackOff 0 1m
> kubectl describe pod jetty
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m default-scheduler Successfully assigned jetty to aks-nodepool1-62963605-0
Normal SuccessfulMountVolume 2m kubelet, aks-nodepool1-62963605-0 MountVolume.SetUp succeeded for volume "default-token-w8png"
Normal Pulling 2m (x2 over 2m) kubelet, aks-nodepool1-62963605-0 pulling image "aksclusterregistry.azurecr.io/jetty"
Warning Failed 2m (x2 over 2m) kubelet, aks-nodepool1-62963605-0 Failed to pull image "aksclusterregistry.azurecr.io/jetty": rpc error: code = Unknown desc = Error response from daemon: Get https://aksclusterregistry.azurecr.io/v2/jetty/manifests/latest: unauthorized: authentication required
Warning Failed 2m (x2 over 2m) kubelet, aks-nodepool1-62963605-0 Error: ErrImagePull
Normal BackOff 2m (x5 over 2m) kubelet, aks-nodepool1-62963605-0 Back-off pulling image "aksclusterregistry.azurecr.io/jetty"
Normal SandboxChanged 2m (x7 over 2m) kubelet, aks-nodepool1-62963605-0 Pod sandbox changed, it will be killed and re-created.
Warning Failed 2m (x6 over 2m) kubelet, aks-nodepool1-62963605-0 Error: ImagePullBackOff
怎么了?为什么秘密方法不起作用? 请不要建议我使用服务主体的方法,因为我想了解为什么这种方法不起作用。我认为它必须工作。
这对我来说也不错。也就是说,建议不要使用管理员帐户,而是一种服务原则。使用 SP,您可以对 ACR 实例的访问权限(读取、贡献者、所有者)进行一些精细的控制。
此文档包括使用服务原则在 AKS 和 ACR 之间进行身份验证的两种方法。
https://docs.microsoft.com/en-us/azure/container-registry/container-registry-auth-aks
使用 AKS 的 "old" 方法就是按照您提到的 create secret
进行操作。不再推荐。
"new"方式是附加容器注册表。 This 文章解释了附加 ACR 的 "new" 方法,还提供了 link 旧方法以消除混淆。创建集群时,附加:
az aks create -n myAKSCluster -g myResourceGroup --attach-acr $MYACR
或者,如果您已经创建了集群,请将其更新为:
az aks update -n myAKSCluster -g myResourceGroup --attach-acr $MYACR
备注:
$MYACR
只是没有.azurecr.io
的注册表名称。例如:MYACR=foobar
而不是MYACR=foobar.azurecr.io
.附加 ACR 后,
ImagePullBackOff
需要几分钟才能转换为Running
。
这不完全是问题案例。但是我在使用 Attach ACR 方法时遇到了类似的问题。我的问题是注册表名称中的大写字符。 az cli 生成了以下警告。
Uppercase characters are detected in the registry name. When using its server url in docker commands, to avoid authentication errors, use all lowercase
因此请确保在 Docker 命令的 ACR 网址中使用所有小写字母。