![](/img/trans.png)
[英]Gitlab CI/CD using Kubernetes agent and the private container registry
[英]Connect kubernetes to GitLab Container Registry
我在將我的 k3s 集群連接到 GitLab Docker 注冊表時遇到問題。
在集群上,我在默認命名空間中創建了這樣的秘密
kubectl create secret docker-registry regcred --docker-server=https://gitlab.domain.tld:5050 --docker-username=USERNAME --docker-email=EMAIL --docker-password=TOKEN
然后在部署配置中我得到了這個秘密,我的配置:
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
labels:
app.kubernetes.io/name: "app"
app.kubernetes.io/version: "1.0"
namespace: default
spec:
template:
metadata:
labels:
app: app
spec:
imagePullSecrets:
- name: regcred
containers:
- image: gitlab.domain.tld:5050/group/appproject:1.0
name: app
imagePullPolicy: Always
ports:
- containerPort: 80
但是創建的 pod 還是無法拉取這個鏡像。 仍然有以下錯誤信息:
failed to authorize: failed to fetch anonymous token: unexpected status: 403 Forbidden
你能幫我一下,錯誤可能在哪里? 如果我嘗試在本地 docker 上通過上面的秘密連接到這個 GitLab 注冊表,它工作正常,docker 登錄是正確的,也是這個圖像的拉動。
謝謝
要從 Gitlab 上的私有容器注冊表中提取數據,您必須首先創建一個類似於管道或類似“服務”訪問它的方式的Deploy Token
。 Go 到存儲庫然后 go 到Settings
-> Repository
-> Deploy Tokens
給部署令牌一個name
和一個username
(它說是可選的,但我們將能夠將這個自定義用戶名與令牌一起使用)並確保它具有 read_registry 訪問權限。 這就是它需要從注冊表中提取的全部內容。 如果您稍后需要推送,那么您將需要 write_registry。 單擊create deploy token
后,它會向您顯示令牌,請務必復制它,因為您不會再看到它。
現在只需在您的 k8s 集群中重新創建您的秘密。
kubectl create secret docker-registry regcred --docker-server=<private gitlab registry> --docker-username=<deploy token username> --docker-password=<deploy token>
確保將密鑰應用到與拉取映像的部署相同的命名空間。
[參見文檔] https://docs.gitlab.com/ee/user/project/deploy_tokens/#gitlab-deploy-token
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.