

K8S学习笔记(3)-从私有仓库拉取镜像
source link: http://vearne.cc/archives/39402
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

版权声明 本站原创文章 由 萌叔 发表
转载请注明 萌叔 | http://vearne.cc
警告:本文仅用于萌叔自己总结之用,对其它人而言可能毫无营养,没有阅读价值。
在k8s中要使用自己搭建的私有仓库,还需要一些额外的配置。
萌叔使用的harbor搭建的私有仓库 goharbor/harbor, 假定地址为
https://docker-harbor.vearne.cc
2. 配置过程
要能够成功拉去image,需要解决2个问题
2.1 TLS证书验证
由于我们的私有仓库,使用的自签名的证书,所以需要能够通过TLS的握手阶段对证书。
如果证书认证失败,你可能收到如下错误
[root@xx ~]# docker pull docker-harbor.vearne.cc/ut/helloworld:0.2.6
Error response from daemon: Get https://docker-harbor.vearne.cc/ut/helloworld:0.2.6: x509: certificate signed by unknown authority
一种做法是直接添加CA根证书到操作系统获得信任。但是萌叔尝试后,发现无效。
这里验证有效的做法是,使用dockerd的--insecure-registry
参数
2.1.1 修改dockerd的配置文件
默认路径为/etc/docker/daemon.json
{
"insecure-registries" : ["docker-harbor.vearne.cc"]
}
2.1.2 重启dockerd
systemctl restart docker
2.2 登录
要想在宿主机拉取镜像,可以用
docker login docker-harbor.vearne.cc
在k8s集群中拉取镜像可以使用
kubectl create secret docker-registry regcred \
--docker-server=<你的镜像仓库服务器> \
--docker-username=<你的用户名> \
--docker-password=<你的密码> \
--docker-email=<你的邮箱地址>
创建一个密钥,用于拉取镜像
检查 Secret regcred
kubectl get secret regcred --output="jsonpath={.data.\.dockerconfigjson}" | base64 --decode
输出和下面类似:
{"auths":{"yourprivateregistry.com":{"username":"janedoe","password":"xxxxxxxxxxx","email":"[email protected]","auth":"c3R...zE2"}}}
读者应该已经发现用户名和密码只是简单的用base64编码以后保存成字符串文本。实际上docker client和harbor的交互用的就是使用Basic Auth
进行鉴权。
2.3 创建使用你的 Secret 的 Pod
注意: Secret
regcred所在的Namespace
要和Pod
所在的Namespace
保持一致
apiVersion: v1
kind: Pod
metadata:
name: private-reg
spec:
containers:
- name: private-reg-container
image: docker-harbor.vearne.cc/ut/helloworld:0.2.6
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: regcred
经过上面的操作,就可以方便的从私有仓库拉取image了。
请我喝杯咖啡

Recommend
-
9
搭建私有docker镜像仓库 作者: wencst 分类: linux,Uncategorized,
-
10
kubeadm init 时从本地私有仓库下载镜像 作者: wencst 分类: docker,云计算
-
11
本文预计阅读时间 6 分钟 1,直接通过如下命令启动私有仓库。 docker run -d --name registry -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always registry 2,通过配置,连接私服。
-
13
docker学习笔记–使用nexus搭建docker私有仓库(推荐) |坐而言不如起而行! 二丫讲梵 > 术业专攻 >
-
13
V2EX › 程序员 GitLab CI/CD - publish 镜像到私有镜像仓库出错 JasonLaw · 4 小时 35...
-
9
Docker 虽然提供公有镜像仓库 Docker hub,但是满足不了绝大部分企业对镜像仓库私有化部署的需求。 私有镜像仓库解决方案中,作为 CNCF 项目的 Harbor 长期处于统治地...
-
7
Harbor 安装条件 官网给出了安装需要的最低硬件和软件的条件:https://goharbor.io/docs/2.0.0/install-config/installation-prereq...
-
7
V2EX › 分享发现 找到了 github 拉取私有仓库的方法
-
8
搭建私有Docker镜像仓库学习笔记 搭建没有GUI界面的仓库 通过Docker官方提供的镜像搭建镜像仓库 docker run --name registry --restart=always -p 5000:5000 -d -v registry-data:/var/lib...
-
7
V2EX › Kubernetes k8s 如何每次拉取最新镜像 or...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK