gpt4 book ai didi

ibm-cloud - 如何从 IBM Cloud Delivery Pipeline (Tekton) 访问私有(private) Container Registry

转载 作者:行者123 更新时间:2023-12-01 23:01:35 25 4
gpt4 key购买 nike

我正在尝试在我的一项任务中使用来自私有(private)容器注册表的容器镜像。

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: echo-hello-world
spec:
steps:
- name: echo
image: de.icr.io/reporting/status:latest
command:
- echo
args:
- "Hello World"

但是当我在 IBM Cloud Delivery Pipeline (Tekton) 中运行此任务时,无法拉取图像

 message: 'Failed to pull image "de.icr.io/reporting/status:latest": rpc error: code = Unknown desc = failed to pull and unpack image "de.icr.io/reporting/status:latest": failed to resolve reference "de.icr.io/reporting/status:latest": failed to authorize: failed to fetch anonymous token: unexpected status: 401 Unauthorized'

我阅读了几个教程和博客,但到目前为止找不到解决方案。这可能是我需要完成的,以便 IBM Cloud Delivery Pipeline (Tekton) 可以访问我的私有(private)容器注册表:https://tekton.dev/vault/pipelines-v0.15.2/auth/#basic-authentication-docker

到目前为止,我已经在我的 .tekton 目录中创建了一个 secret.yaml 文件:

apiVersion: v1
kind: Secret
metadata:
name: basic-user-pass
annotations:
tekton.dev/docker-0: https://de.icr.io # Described below
type: kubernetes.io/basic-auth
stringData:
username: $(params.DOCKER_USERNAME)
password: $(params.DOCKER_PASSWORD)

我也在创建一个 ServiceAccount

apiVersion: v1
kind: ServiceAccount
metadata:
name: default-runner
secrets:
- name: basic-user-pass

在我的触发器定义中,我告诉管道使用 default-runner ServiceAccount:

apiVersion: tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: theTemplateTrigger
spec:
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: pipelinerun-$(uid)
spec:
serviceAccountName: default-runner
pipelineRef:
name: hello-goodbye

最佳答案

我找到了一种将我的 API key 传递到我的 IBM Cloud Delivery Pipeline (Tekton) 的方法,我的管道中的任务现在能够从我的私有(private)容器注册表中提取容器镜像。

这是我的工作触发器模板:

apiVersion: tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: theTemplateTrigger
spec:
params:
- name: pipeline-dockerconfigjson
description: dockerconfigjson for images used in .pipeline-config.yaml
default: "eyJhdXRocyI6e319" # ie. {"auths":{}} base64 encoded
resourcetemplates:
- apiVersion: v1
kind: Secret
data:
.dockerconfigjson: $(tt.params.pipeline-dockerconfigjson)
metadata:
name: pipeline-pull-secret
type: kubernetes.io/dockerconfigjson
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: pipelinerun-$(uid)
spec:
pipelineRef:
name: hello-goodbye
podTemplate:
imagePullSecrets:
- name: pipeline-pull-secret

它首先定义了一个名为pipeline-dockerconfigjson的参数:

  params:
- name: pipeline-dockerconfigjson
description: dockerconfigjson for images used in .pipeline-config.yaml
default: "eyJhdXRocyI6e319" # ie. {"auths":{}} base64 encoded

第二部分将传递给这个参数的值变成一个 Kubernetes secret:

    - apiVersion: v1
kind: Secret
data:
.dockerconfigjson: $(tt.params.pipeline-dockerconfigjson)
metadata:
name: pipeline-pull-secret
type: kubernetes.io/dockerconfigjson

然后这个 secret 被推送到 PodTemplate 的 imagePullSecrets 字段。

最后一步是使用有效的 dockerconfigjson 填充参数,这可以在 Delivery Pipeline UI (IBM Cloud UI) 中完成。

要为我的注册表 de.icr.io 创建一个有效的 dockerconfigjson,我必须使用以下 kubectl 命令:

kubectl create secret docker-registry mysecret \
--dry-run=client \
--docker-server=de.icr.io \
--docker-username=iamapikey \
--docker-password=<MY_API_KEY> \
--docker-email=<MY_EMAIL> \
-o yaml

然后在输出中有一个有效的 base64 编码的 .dockerconfigjson 字段。

关于ibm-cloud - 如何从 IBM Cloud Delivery Pipeline (Tekton) 访问私有(private) Container Registry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71718042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com