And*_*006 19 azure docker kubernetes azure-cli2
我尝试使用秘密从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
Run Code Online (Sandbox Code Playgroud)
之后我登录并成功将图像推送到本地机器创建的ACR.
docker login aksclusterregistry.azurecr.io
docker tag jetty aksclusterregistry.azurecr.io/jetty
docker push aksclusterregistry.azurecr.io/jetty
Run Code Online (Sandbox Code Playgroud)
下一步是创建一个秘密:
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
Run Code Online (Sandbox Code Playgroud)
最后我尝试使用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
Run Code Online (Sandbox Code Playgroud)
结果我有一个状态为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
Run Code Online (Sandbox Code Playgroud)
怎么了?为什么秘密的方法不起作用?请不要建议我与服务主管的方法,因为我想了解为什么这个方法不起作用.我认为它必须有效.
K.S*_*.S. 17
AKS 的“旧”方法是create secret
按照您提到的方式进行操作。那不再推荐了。
“新”方法是附加容器注册表。此文章解释了“新”的方式来连接ACR,并且还提供了一个链接到旧的方式来清理混乱。创建集群时,附加:
az aks create -n myAKSCluster -g myResourceGroup --attach-acr $MYACR
Run Code Online (Sandbox Code Playgroud)
或者,如果您已经创建了集群,请使用以下内容更新它:
az aks update -n myAKSCluster -g myResourceGroup --attach-acr $MYACR
Run Code Online (Sandbox Code Playgroud)
笔记:
$MYACR
只是您的注册表名称,没有.azurecr.io
. 例如:MYACR=foobar
不是MYACR=foobar.azurecr.io
。
附加 ACR 后,将需要几分钟时间ImagePullBackOff
才能转换为Running
.
小智 10
这对我来说也很好。也就是说,建议不要使用管理员帐户,而应该使用服务原则。使用SP,您可以对ACR实例(读取,贡献者,所有者)的访问权限进行一些精细控制。
该文档包括两种使用服务原理在AKS和ACR之间进行身份验证的方法。
https://docs.microsoft.com/zh-CN/azure/container-registry/container-registry-auth-aks
归档时间: |
|
查看次数: |
6928 次 |
最近记录: |