无法将私有包/镜像从 GitHub 容器注册表拉入 Okteto Kubernetes

Mic*_*ael 3 docker kubernetes minikube okteto ghcr

我希望可以征求您的建议。

\n

简而言之,问题是:我的管道无法将私有镜像从 GHCR.IO 拉入 Okteto Kubernetes,但来自同一私有存储库的公共镜像可以工作。

\n

我使用的是 Windows 10,使用 WSL2-Ubuntu 20.04 LTS 和 kinD 进行开发,也尝试过 minikube。

\n

我在 Okteto 中收到错误,表示图像拉取为 \xe2\x80\x9cunauthorized\xe2\x80\x9d -> \xe2\x80\x9cimagePullBackOff\xe2\x80\x9d。

\n

我所做的事情:浏览 Stack Overflow、RTFM、Okteto FAQ,下载 Okteto kubeconfig,费尽心思,花了比我愿意承认的更多的时间 \xe2\x80\x93 仍然没有成功。

\n

无论出于何种原因,我无法创建有效的 \xe2\x80\x9ckubectl Secret\xe2\x80\x9d 。当通过 \xe2\x80\x9cdocker login --username\xe2\x80\x9d 登录到 ghcr.io 时,我可以在本地提取私有镜像。

\n

无论我\xe2\x80\x99ve如何尝试,当尝试在Okteto中提取私有映像时,我仍然收到错误\xe2\x80\x9cunauthorized\xe2\x80\x9d。

\n

我的设置与最新更新:

\n
    \n
  • Windows 10 专业版
  • \n
  • JetBrains Rider IDE
  • \n
  • WSL2-Ubuntu 20.04 LTS
  • \n
  • ASP.NET Core MVC 应用程序
  • \n
  • .NET 6 SDK
  • \n
  • 码头工人
  • \n
  • 种类
  • \n
  • 迷你库贝
  • \n
  • 巧克力味
  • \n
  • 自制
  • \n
\n

设置类型

\n
kind create cluster --name my-name\n\nkubectl create my-namespace\n\n// create a secret to pull images from ghcr.io       \nkubectl create secret docker-registry my-secret -n my-namespace --docker-username="my-username" --docker-password="my-password" --docker-email="my-email" --docker-server="https://ghcr.io"\n\n// patch local service account\nkubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "my-secret"}]}'\n
Run Code Online (Sandbox Code Playgroud)\n

kubernetes.yaml

\n
apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: okteto-repo\n  namespace: my-namespace\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: okteto-repo\n  template:\n    metadata:\n      labels:\n        app: okteto-repo\n    spec:\n      containers:\n        - name: okteto-repo\n          image: ghcr.io/user/okteto-repo:latest\n          ports:\n            - containerPort: 80\n      imagePullSecrets:\n        - name: my-secret\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: okteto-repo\n  annotations:\n    dev.okteto.com/auto-ingress: "true"\nspec:\n  type: ClusterIP\n  selector:\n    app: okteto-repo\n  ports:\n    - protocol: TCP\n      port: 8080\n      targetPort: 80\n
Run Code Online (Sandbox Code Playgroud)\n

您知道为什么它不起作用以及我能做什么吗?

\n

非常感谢亲爱的朋友们,我们非常感谢您的每一次投入!

\n

希望你们假期愉快。

\n

干杯,\n迈克尔

\n

Ram*_*eza 7

我能够通过执行以下操作来提取私有映像:

  1. 在 GitHub 中创建具有访问权限的个人令牌repo
  2. 构建镜像并将其推送到 GitHub 的容器注册表(我使用过okteto build -t ghcr.io/rberrelleza/go-getting-started:0.0.1
  3. 通过运行从 Okteto Cloud下载我的kubeconfig 凭证okteto context update-kubeconfig
  4. 使用我的凭据创建一个秘密:kubectl create secret docker-registry gh-regcred --docker-server=ghcr.io --docker-username=rberrelleza --docker-password=ghp_XXXXXX
  5. 修补了默认帐户以将机密包含为图像拉取机密:kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "gh-regcred"}]}'
  6. 更新了 kubernetes 清单中的镜像名称
  7. 创建部署 ( kubectl apply -f k8s.yaml)

这些是我的 kubernetes 资源的样子,以防有帮助:

# k8s.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - image: ghcr.io/rberrelleza/go-getting-started:0.0.1
        name: hello-world

---

apiVersion: v1
kind: Service
metadata:
  name: hello-world
  annotations:
    dev.okteto.com/auto-ingress: "true"
spec:
  type: ClusterIP  
  ports:
  - name: "hello-world"
    port: 8080
  selector:
    app: hello-world
Run Code Online (Sandbox Code Playgroud)
# default SA
apiVersion: v1
imagePullSecrets:
- name: gh-regcred
- name: okteto-regcred
kind: ServiceAccount
metadata:
  creationTimestamp: "2021-05-21T22:26:38Z"
  name: default
  namespace: rberrelleza
  resourceVersion: "405042662"
  uid: 2b6a6eef-2ce7-40d3-841a-c0a5497279f7
secrets:
- name: default-token-7tm42
Run Code Online (Sandbox Code Playgroud)