[k8s]使用私有harbor镜像源
前言
在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: 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
- 创建pod测试能否正常拉取
kubectl create -f xxx.yaml
本文来自博客园,作者:花酒锄作田,转载请注明原文链接:https://www.cnblogs.com/XY-Heruo/p/17205402.html
分类:
运维
标签:
kubernetes
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示