当前位置:网站首页>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.
边栏推荐
猜你喜欢

Code solution of simplex method (including super detailed code notes and the whole flow chart)

中国 璞富腾酒店及度假村旗下酒店推出全新水疗产品共庆6月11日全球健康日

618大促将至,用AI挖掘差评,零代码实现亿级评论观点情感分析

云图说|每个成功的业务系统都离不开APIG的保驾护航

China pufuteng hotels and resorts launched new spa products to celebrate the global health day on June 11

100003 words, take you to decrypt the system architecture under the double 11 and 618 e-commerce promotion scenarios

Developers changing the world - Yao Guang teenagers playing Tetris

Analysis of optical storage direct flexible power distribution system

腾讯云数据库TDSQL-大咖论道 | 基础软件的过去、现在、未来

Esp8266 system environment setup
随机推荐
Rmarkdown 轻松录入数学公式
2022.05.25 (lc_718_longest repeating subarray)
Prospect of database firewall technology [final chapter]
Logback排除指定包/类/方法日志输出
2022.05.28(LC_516_最长回文子序列)
Chapter 6 relational data theory exercise
【6.4-6.10】博客精彩回顾
MySQL (17 trigger)
Design and development of hospital reservation registration platform based on JSP Zip (thesis + project source code)
【web】个人主页web大作业「课表」「相册」「留言板」
SAR回波信号基本模型与性质
个人如何投资理财比较安全?
Basic model and properties of SAR echo signal
[C language] accidentally write a bug? Mortals teach you how to write good code [explain debugging skills in vs]
Performance and high availability analysis of database firewall
Monotonic stack structure
In the all digital era, how can enterprise it complete transformation?
基于改进SEIR模型分析上海疫情
Design and reality of JSP project laboratory management system based on SSM doc
全数字时代,企业IT如何完成转型?