https://www.jianshu.com/p/fd13c2762d81
私有仓库虽然可以通过docker pull
命令拉取镜像, 但无法通过k8s
创建pod
方式拉取。因为没有配置秘钥。
1、生成密钥secret 【
以阿里云docker镜像仓库
为例】
kubectl create secret docker-registry regsecret \
--docker-server=registry.cn-hangzhou.aliyuncs.com \
--docker-username=yin32167@aliyun.com \
--docker-password=xxxxxx \
--docker-email=yin32167@aliyun.com
其中:
regsecret: 指定密钥的名称, 可自行定义
--docker-server: 指定docker仓库地址
--docker-username: 指定docker仓库账号
--docker-password: 指定docker仓库密码
--docker-email: 指定邮件地址(选填)
要注意的是, 该密钥只能在对应namespace
使用, 默认为default
, 如果需要用到其他namespace
, 比如说test
, 就需要在生成的时候指定参数 -n test 。
2、yml
文件加入密钥参数
containers:
- name: channel
image: registry-internal.cn-hangzhou.aliyuncs.com/yin32167/channel:dev-1.0
ports:
- containerPort: 8114
imagePullSecrets:
- name: regsecret
其中imagePullSecrets
是声明拉取镜像时需要指定密钥, regsecret
必须和上面生成密钥的名称一致, 另外检查一下pod
和密钥是否在同一个namespace
, 之后k8s
便可以拉取镜像