前言
在node上手動執行命令可以正常從harbor拉取鏡像,但是用k8s不行,使用kubectl describe pods xxx
提示未授權 unauthorized to access repository。
處理方法
- 創建一個secrete資源對象。以下示例中
registry-harbor
為secret資源對象的名稱。除了郵箱可以隨便填,其它三個需要使用實際的harbor地址和賬號。
kubectl create secret docker-registry registry-harbor \--docker-server=harbor.interlweb.com \--docker-username=admin \--docker-password='Harbor12345' \--docker-email=foo@bar.com
- 在pod的yaml定義文件中使用
imagePullSecrets
引用secret
apiVersion: apps/v1
kind: Deployment
metadata:name: deploy-nginx
spec:replicas: 2selector:matchLabels:app: nginxenv: uattemplate:metadata:labels:app: nginxenv: uatspec:containers:- name: nginximage: harbor.interlweb.com/public/nginx:1.23.3ports:- containerPort: 80imagePullSecrets:- name: registry-harbor
- 創建pod測試能否正常拉取
kubectl create -f xxx.yaml