Docker 登录私有仓库

  1. 首先配置私有仓库免 ssl 验证
1{
2  "insecure-registries": ["szharbor.xxx.cn"]
3}
  1. 输入用户名密码并登录
1docker login szharbor.xxx.cn
  1. 查看登录成功后的 Docker 认证文件
1cat ~/.docker/config.json
1{
2	"auths": {
3		"szharbor.xxx.cn": {
4			"auth": "cm...nVVM="
5		}
6	}
7}
  1. 压缩,base64编码
1{"auths":{"szharbor.xxx.cn":{"auth":"cm9ib3QkaGllbXNfZGV2K3ByaXY6Rk1iSXQ5bFI2RXA5bDd6cU9pUU1MYUg5eVdQWnFnVVM="}}}
1eyJhdXRocyI6eyJzemhhcmJvci5oaXRoaXVtLmNuIjp7ImF1dGgiOiJjbTlpYjNRa2FHbGxiWE5mWkdWMkszQnlhWFk2UmsxaVNYUTViRkkyUlhBNWJEZDZjVTlwVVUxTVlVZzVlVmRRV25GblZWTT0ifX19

harbor

1eyJhdXRocyI6eyIxMC4xMDEuNy4xMDg6ODAiOnsiYXV0aCI6ImVtaDFZVzVuY1dZNlFFQXhXR2xoYjNOb1lXZDFZUT09In19fQ==

创建 imagePullSecret

1apiVersion: v1
2kind: Secret
3metadata:
4  name: harbor-secret
5  namespace: szhems
6data:
7  .dockerconfigjson: eyJhdXRocyI6eyJzemhhcmJvci5oaXRoaXVtLmNuIjp7ImF1dGgiOiJjbTlpYjNRa2FHbGxiWE5mWkdWMkszQnlhWFk2UmsxaVNYUTViRkkyUlhBNWJEZDZjVTlwVVUxTVlVZzVlVmRRV25GblZWTT0ifX19
8type: kubernetes.io/dockerconfigjson

将 secret 与 account 绑定

1apiVersion: v1
2kind: ServiceAccount
3metadata:
4  namespace: szhems
5  name: find-endpoints
6imagePullSecrets:
7  - name: harbor-secret

或者直接将 secret 与 deployment 进行绑定

 1apiVersion: apps/v1
 2kind: Deployment
 3metadata:
 4  name: assets-api
 5  namespace: szhems
 6  labels:
 7    app: assets-api
 8spec:
 9  selector:
10    matchLabels:
11      app: assets-api
12  template:
13    metadata:
14      labels:
15        app: assets-api
16    spec:
17      serviceAccountName: find-endpoints
18      imagePullSecrets:
19        - name: harbor
20      containers:
21        - name: assets-api
22          image: 10.101.7.108:80/szhems_dev/be_assets_api:0.1.0.210