我试图从Docker集线器中提取一个私有(private)镜像,并且每次在pod上使用describe收到错误“ImagePullBackOff”时,我都会看到错误“未经授权:错误的用户名或密码”,我使用以下命令在集群中创建了 secret 指南:https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/使用带有正确证书的cli方法(我检查了一下,并可以使用这些证书登录网站),这是我的yaml文件。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-typescript
  labels:
    app: app-typescript
spec:
  selector:
      matchLabels:
        app: app-typescript
  replicas: 1
  minReadySeconds: 15
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: app-typescript
    spec:
      containers:
      - name: api
        image: dockerhuborg/api:latest
        imagePullPolicy: Always
        env:
          - name: "ENV_TYPE"
            value: "production"
          - name: "NODE_ENV"
            value: "production"
          - name: "MONGODB_URI"
            value: "mongodb://mongo-mongodb/db"
        ports:
        - containerPort: 4000
      imagePullSecrets:
      - name: regcred

最佳答案

我找到了一个解决方案,显然问题是Docker中心使用不同的域进行登录和容器拉动,因此您必须编辑使用kubectl命令创建的 secret ,并用此json的编码base64版本替换.dockerconfigjson的base64(是的,知道也许我添加了太多域名,但是我正试图从大约2天后开始解决此问题,我再也没有耐心来找到确切的域名了)

{
    "auths":{
        "https://index.docker.io/v1/":{
            "username":"user",
            "password":"password",
            "email":"[email protected]",
            "auth":"base64 of string user:password"
        },
        "auth.docker.io":{
            "username":"user",
            "password":"password",
            "email":"[email protected]",
            "auth":"base64 of string user:password"
        },
        "registry.docker.io":{
            "username":"user",
            "password":"password",
            "email":"[email protected]",
            "auth":"base64 of string user:password"
        },
        "docker.io":{
            "username":"user",
            "password":"password",
            "email":"[email protected]",
            "auth":"base64 of string user:password"
        },
        "https://registry-1.docker.io/v2/": {
            "username":"user",
            "password":"password",
            "email":"[email protected]",
            "auth":"base64 of string user:password"
        },
        "registry-1.docker.io/v2/": {
            "username":"user",
            "password":"password",
            "email":"[email protected]",
            "auth":"base64 of string user:password"
        },
        "registry-1.docker.io": {
            "username":"user",
            "password":"password",
            "email":"[email protected]",
            "auth":"base64 of string user:password"
        },
        "https://registry-1.docker.io": {
            "username":"user",
            "password":"password",
            "email":"[email protected]",
            "auth":"base64 of string user:password"
        }
    }
}

关于docker - kubernetes中的dockerhub提供未经授权的用户名或密码正确的凭据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55773755/

10-16 22:36