【问题标题】:Cannot pull a private package/image from GitHub Container Registry into Okteto Kubernetes无法将私有包/图像从 GitHub Container Registry 拉入 Okteto Kubernetes
【发布时间】:2022-01-22 09:43:06
【问题描述】:

我希望可以征求您的意见。

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

我在 Windows 10 上使用 WSL2-Ubuntu 20.04 LTS 和 kinD 进行开发,也尝试了 minikube。

我在 Okteto 中收到一个错误,指出图像拉取是“未经授权的”->“imagePullBackOff”。

我做过的事情:浏览 Stack Overflow、RTFM、Okteto 常见问题解答、下载 Okteto kubeconfig、拔掉头发,花了比我想承认的更多的时间——仍然没有成功。

无论出于何种原因,我都无法创建一个有效的“kubectl secret”。当通过“docker login --username”登录到 ghcr.io 时,我可以在本地提取私有图像。

无论我尝试过什么,当我尝试在 Okteto 中提取私有图像时,仍然会收到“未授权”错误。

带有最新更新的我的设置:

  • Windows 10 专业版
  • JetBrains Rider IDE
  • WSL2-Ubuntu 20.04 LTS
  • ASP.NET Core MVC 应用程序
  • .NET 6 SDK
  • 码头工人
  • 亲人
  • minikube
  • 巧克力
  • 家酿

设置种类

kind create cluster --name my-name

kubectl create my-namespace

// create a secret to pull images from ghcr.io       
kubectl 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"

// patch local service account
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "my-secret"}]}'

kubernetes.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: okteto-repo
  namespace: my-namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: okteto-repo
  template:
    metadata:
      labels:
        app: okteto-repo
    spec:
      containers:
        - name: okteto-repo
          image: ghcr.io/user/okteto-repo:latest
          ports:
            - containerPort: 80
      imagePullSecrets:
        - name: my-secret
---
apiVersion: v1
kind: Service
metadata:
  name: okteto-repo
  annotations:
    dev.okteto.com/auto-ingress: "true"
spec:
  type: ClusterIP
  selector:
    app: okteto-repo
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 80

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

非常感谢我亲爱的朋友们,非常感谢每一个输入!

希望你们假期愉快。

干杯, 迈克尔

【问题讨论】:

    标签: docker kubernetes minikube ghcr okteto


    【解决方案1】:

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

    1. 在 GitHub 中创建具有 repo 访问权限的个人令牌。
    2. 构建镜像并将其推送到 GitHub 的容器注册表(我使用了okteto build -t ghcr.io/rberrelleza/go-getting-started:0.0.1
    3. 运行 okteto context update-kubeconfig 从 Okteto Cloud 下载我的 kubeconfig credentials
    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
    
    # 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
    

    【讨论】:

    • 它有效,非常感谢拉米罗!我感谢你的努力!起初我无法下载 kubeconfig 凭据,所以我在 #3 之前挤了一个步骤: okteto context create cloud.okteto.com --token // 继续第 3 步。再次,非常感谢.干杯
    猜你喜欢
    • 2023-03-07
    • 2023-02-01
    • 2020-02-01
    • 2021-03-13
    • 2020-10-03
    • 1970-01-01
    • 2019-08-23
    • 2020-09-16
    • 2022-11-07
    相关资源
    最近更新 更多