当前位置:网站首页>Harbor镜像拉取凭证配置
Harbor镜像拉取凭证配置
2022-06-10 18:43:00 【51CTO】
镜像拉取凭证
主题:在k8s创建Pod过程中,从Harbor私有镜像仓库下载镜像。Harbor的私有镜像为保证镜像的安全性,需要通过配置Secret才可以从Harbor下载镜像。公有仓库不需要配置。
之前在我的专栏《Harbor宝典》中分享了Harbor系列的文章。
本期将继续分享在k8s的容器内如何拉取Harbor中的私有镜像。
Harbor中公有的镜像我们可以随便拉取,但是一些私有的镜像无法直接拉取到。我们可以使用Secret资源对象来拉取私有镜像,以下为详细的操作步骤。
Harbor地址: https://192.168.2.250:443
Harbor用户:admin
Harbor密码:Harbor12345
文末记录遇到的问题及解决办法!
1、登录Harbor
登录成功后会在~/.docker/config.json文件中记录登录信息,然后基于该信息创建Secret,容器中通过imagePullSecret指定该Secret来实现认证,从而拉取私有镜像。
如果登录Harbor失败,请查看专栏的问题解决。
# docker login -u admin -p Harbor12345 192.168.2.250:443
WARNING! Using
--password via the CLI is insecure. Use
--password
-stdin.
WARNING! Your password will be stored unencrypted
in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/
#credentials-store
Login Succeeded //登录成功
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
2、用BASH64编码解析密钥数据
一下创建Secret的时候需要用到解析出来的结果;-w 0 表示生成秘钥不转行,默认转行不是正确的格式会出错。
3、创建Secret镜像拉取凭证
.dockerconfigjson的值就是第2步解析的结果(将结果复制到该处)
# vim harbor-image-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: harbor-pull
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: ewoJImF1dGhzIjogewoJCSIxOTIuMTY4LjIuMjUwOjQ0MyI6IHsKCQkJImF1dGgiOiAiWVdSdGFXNDZTR0Z5WW05eU1USXpORFU9IgoJCX0KCX0sCgkiSHR0cEhlYWRlcnMiOiB7CgkJIlVzZXItQWdlbnQiOiAiRG9ja2VyLUNsaWVudC8xOS4wMy44IChsaW51eCkiCgl9Cn0=
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
命令行创建secret的方法见kubectl create secret -h来创建,本处不详细说明了。
4、容器中使用镜像拉取凭证来拉取私有镜像
本处以拉取私有镜像192.168.2.250:443/muli/tomcat:8.5.34-jre8-alpine为例。
# cat tomcat-pod1.yaml
kind: Pod
apiVersion: v1
metadata:
name: tomcat-v2.3.1
namespace: test
spec:
imagePullSecrets:
- name: image-secret
containers:
- name: tomcat-po
image: 192.168.2.250:443/muli/tomcat:8.5.34-jre8-alpine
imagePullPolicy: IfNotPresent
# kubectl apply -f tomcat-pod1.yaml
pod/tomcat-v2.3.1 created
# kubectl get pods
NAME READY STATUS RESTARTS AGE
tomcat-v2.3.1 1/1 Running 0 20h
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
边栏推荐
- Analysis of optical storage direct flexible power distribution system
- 深入理解LightGBM
- frp reverse proxy
- Framework and practice of smart city network security construction
- C知识练习
- Source code analysis of Tencent libco collaborative process open source library (II) -- persimmon starts from the soft pinch, and the sample code officially begins to explore the source code
- 618大促将至,用AI挖掘差评,零代码实现亿级评论观点情感分析
- 【C语言进阶】指针的进阶【上篇】
- 【web】个人主页web大作业「课表」「相册」「留言板」
- Source code analysis of Tencent libco collaboration open source library (III) -- Exploring collaboration switching process assembly register saving and efficient collaboration environment
猜你喜欢

This article introduces you to j.u.c's futuretask, fork/join framework and BlockingQueue

Matlab draws ellipse code according to any angle, sampling points (resolution), position and size

Lingo12 software download and lingo language introduction resources

如何查询 SAPGUI 屏幕上某个字段对应的数据库表存储

What are the current mainstream all-optical technology solutions- Part II

2022.05.25(LC_718_最长重复子数组)

【6.4-6.10】博客精彩回顾

【 Web 】 page d'accueil personnelle 】 Programme d'études 】 albums de photos 】 babillard d'information 】

c指针(面试经典题目练习)

APICloud可视化开发丨一键生成专业级源码
随机推荐
[C language] still don't understand the structure? Take a look at this article to give you a preliminary understanding of structure
DDD landing practice repeat record of theoretical training & Event storm
100003字,带你解密 双11、618电商大促场景下的系统架构体系
SAR回波信号基本模型与性质
【C语言进阶】数据的存储【下篇】【万字总结】
【C语言进阶】数据的存储【上篇】【万字总结】
MySQL (17 trigger)
Logback排除指定包/类/方法日志输出
软件测试月薪10K如何涨到30K,只有自动化测试能做到
2022.05.24(LC_674_最长连续递增序列)
【C语言进阶】指针的进阶【上篇】
数据库防火墙的性能和高可用性分析
Design and development of hospital reservation registration platform based on JSP Zip (thesis + project source code)
Source code analysis of Tencent libco collaboration open source library (III) -- Exploring collaboration switching process assembly register saving and efficient collaboration environment
腾讯Libco协程开源库 源码分析(二)---- 柿子先从软的捏 入手示例代码 正式开始探究源码
2022.05.29(LC_6079_价格减免)
[advanced C language] data storage [part I] [ten thousand words summary]
HW蓝队中级面试复盘
mixin-- 混入
[C language] have you mastered these classic questions? Learn these questions in one article