首页 > 其他分享 >[kubernetes]使用私有harbor镜像源

[kubernetes]使用私有harbor镜像源

时间:2023-03-11 10:34:06浏览次数:48  
标签:name kubernetes nginx harbor -- registry 镜像 docker

前言

在node上手动执行命令可以正常从harbor拉取镜像,但是用k8s不行,使用kubectl describe pods xxx 提示未授权 unauthorized to access repository。

处理方法

  1. 创建一个secrete资源对象。以下示例中 registry-harbor 为secret资源对象的名称。除了邮箱可以随便填,其它三个需要使用实际的harbor地址和账号。
kubectl create secret docker-registry registry-harbor \
    --docker-server=harbor.interlweb.com \
    --docker-username=admin \
    --docker-password='Harbor12345' \
    [email protected]
  1. 在pod的yaml定义文件中使用 imagePullSecrets 引用secret
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
      env: uat
  template:
    metadata:
      labels:
      	app: nginx
        env: uat
    spec:
      containers:
      - name: nginx
        image: harbor.interlweb.com/public/nginx:1.23.3
        ports:
        - containerPort: 80
      imagePullSecrets:
      - name: registry-harbor
  1. 创建pod测试能否正常拉取
kubectl create -f xxx.yaml

标签:name,kubernetes,nginx,harbor,--,registry,镜像,docker
From: https://www.cnblogs.com/XY-Heruo/p/17205402.html

相关文章