首页 > 解决方案 > 无法在私有注册表中授权 Openshift 服务帐户

问题描述

我创建了一个非常简单的图像,仅用于测试:

FROM alpine:3.8
ENTRYPOINT top

我将它推送到 hub.docker.com 上的私有存储库。

我创造了秘密。我尝试了两种不同的方法,但得到了相同的结果。

oc create secret docker-registry pull-secret --docker-server=auth.docker.io/token --docker-username=MY_USER --docker-password=MY_PASS --docker-email=MY_EMAIL

或者

oc create secret generic dockerhub --from-file=.dockerconfigjson=C:\Users\USER_NAME\.docker\config.json  --type=kubernetes.io/dockerconfigjson

onfig.json 文件的内容:

{
    "auths": {
        "https://index.docker.io/v1/": {
            "auth": "MY_USER_AND_PASS_BASE64_TOKEN",
            "email": "MY_EMAIL"
        }
    },
    "HttpHeaders": {
        "User-Agent": "Docker-Client/18.03.1-ce (windows)"
    },
    "credsStore": "wincred"
}

我向服务帐户添加了秘密:

oc secrets link --for=pull default pull-secret
oc secrets link builder pull-secret
oc secrets link deployer pull-secret

我尝试了这样的事情:

oc secrets add serviceaccount/default secrets/pull-secret --for=pull
oc secrets add serviceaccount/builder secrets/pull-secret
oc secrets add serviceaccount/deployer secrets/pull-secret

然后,当我尝试部署图像时,openshift 显示图像可用,甚至显示图像的大小。所以,秘密工作。没有秘密,就无法访​​问图像。

当我尝试部署映像时,出现以下问题:

2:38:49 AM  Normal  Pulling     pulling image "docker.io/MY_USER/simple-test-image@sha256:a9d7749ce23069865a4e540862271bv8e66f9452acb33668e72029fdfdb4e9f4"

2:38:51 AM  Warning Failed  Error: ErrImagePull
2 times in the last minute

2:38:51 AM  Warning Failed  Failed to pull image "docker.io/MY_USER/simple-test-image@sha256:a9d7749ce23069865a4e540862271bv8e66f9452acb33668e72029fdfdb4e9f4": rpc error: code = Unknown desc = repository docker.io/MY_USER/simple-test-image not found: does not exist or no pull access
2 times in the last 

2:39:00 AM  Normal  Sandbox Changed     Pod sandbox changed, it will be killed and re-created.
7 times in the last minute

2:39:02 AM  Normal  Back-off    Back-off pulling image "docker.io/MY_USER/simple-test-image@sha256:a9d7749ce23069865a4e540862271bv8e66f9452acb33668e72029fdfdb4e9f4"
6 times in the last 

2:39:02 AM  Warning Failed  Error: ImagePullBackOff
6 times in the last minute

系统似乎可以访问图像,但服务帐户无权访问或不使用机密。

我尝试从控制台(oc new-app docker.io/MY_USER/simple-test-image)和站点部署图像,但得到了相同的结果。

我重新创建了秘密,尝试编辑服务帐户等等,但没有任何帮助。当我将存储库的类型更改为公共时,一切正常,但我需要它是私有的。

看来我错过了什么。我将不胜感激任何建议。

标签: dockeropenshift

解决方案


推荐阅读