# 查看现有secrets
[root@node1 shop-api]# kubectl get secrets NAME TYPE DATA AGE default-token-v4cld kubernetes.io/service-account-token 3 4h5m
# 创建一个私库secrets
[root@node1 shop-api]# kubectl create secret docker-registry harbor --docker-server=reg.xxx.com --docker-username=admin --docker-password=123 --docker-email=admin@xxx.com secret/harbor created
# 查看创建
[root@node1 shop-api]# kubectl get secrets NAME TYPE DATA AGE default-token-v4cld kubernetes.io/service-account-token 3 4h6m harbor kubernetes.io/dockerconfigjson 1 2s
# yaml中添加私库认证信息,截取部分。
spec: containers: - image: reg.xxx.com/prod/shop-api:0426 name: java ports: - containerPort: 8080 resources: #limits: #cpu: 1 #memory: 1024G #requests: #cpu: 1 #memory: 1024G command: ["java"] args: ["-jar","shop-api-0.0.1-SNAPSHOT.jar","--spring.profiles.active=test","--server.port=8080"] workingDir: /mnt # 私库认证 imagePullSecrets: - name: harbor
注意imagePullSecrets和containers配置同级。
这样就会从私库自动认证并拉取镜像。
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/4757.html