k8s使用私有harbor镜像源

前言

在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'
    --docker-email=foo@bar.com

  2. 在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

  3. 创建pod测试能否正常拉取

    kubectl create -f xxx.yaml

相关推荐
为什么要做囚徒34 分钟前
IntelliJ IDEA 远程断点调试完全指南
java·ide·intellij-idea
探索宇宙真理.1 小时前
Apache Tomcat RewriteValve目录遍历漏洞 | CVE-2025-55752 复现
java·经验分享·tomcat·apache·安全漏洞
元直数字电路验证1 小时前
ASP.NET Core Web APP(MVC)开发中无法全局配置 NuGet 包,该怎么解?
前端·javascript·ui·docker·asp.net·.net
Boilermaker19921 小时前
【Redis】集群与分布式缓存
java·数据库·redis·1024程序员节
YC运维1 小时前
Kubernetes资源管理全解析
java·容器·kubernetes
Leinwin1 小时前
微软发布Azure Kubernetes Service Automatic国际版
microsoft·kubernetes·azure
rexling12 小时前
【Spring Boot】Spring Boot解决循环依赖
java·前端·spring boot
武子康2 小时前
Java-163 MongoDB 生产安全加固实战:10 分钟完成认证、最小权限、角色详解
java·数据库·分布式·mongodb·性能优化·系统架构·nosql
ZIM学编程2 小时前
「学长有话说」作为一个大三学长,我想对大一计算机专业学生说这些!
java·c语言·数据结构·c++·python·学习·php
Dolphin_Home2 小时前
轻量实用的 XML 与 JSON / 对象互转工具类(Jackson 实现)
xml·java·json