ECI默认不提供公网资源的访问,因此ECI默认是不能拉取自建镜像仓库的镜像,如果您需要从自建镜像仓库等公网镜像仓库拉取镜像来创建ECI实例时需要实例具备公网访问的能力。本文介绍在自建镜像仓库使用自签发证书的情况下,如何拉取自建镜像仓库中的镜像来创建ECI Pod。
前提条件
确保您已经创建Serverless集群,具体操作请参阅创建Serverless集群。
当拉取公网镜像时,确保集群所在VPC已经开启公网NAT网关,能访问公网拉取镜像。
确保kubectl工具已经连接目标集群。
操作步骤
创建镜像拉取凭证。
构造镜像拉取凭证,并且进行base64编码:
echo "your_name:your_password" | base64
echo '{"auths":{"harborxxxxx.xxx.com":{"username":"your_name","password":"your_password","email":"test@tel.com","auth":"xxxxx"}}}' |base64
镜像拉取凭证保密字典test-internetimage.yaml示例如下:
apiVersion: "v1"
kind: "Secret"
metadata:
labels:
serviceAccountName: "default"
name: "test-internetimage"
namespace: "default"
data:
".dockerconfigjson": "xxxxxxxxxxxx" # 填写base64编码后的镜像拉取凭证
type: "kubernetes.io/dockerconfigjson"
创建镜像拉取凭证保密字典:
kubectl crate -f test-internetimage.yaml
创建工作负载。
构建工作负载pod-internetimage.yaml,填写镜像拉取凭证,示例如下:
apiVersion: "apps/v1"
kind: "Deployment"
metadata:
name: "test-internetimage"
namespace: "default"
spec:
replicas: 1
selector:
matchLabels:
app: "test"
version: "v1"
template:
metadata:
labels:
app: "test"
version: "v1"
spec:
containers:
- image: "harborxxxxx.xxx.com/test/nginx:latest" # 填写dockerhub镜像仓库或者自建镜像仓库
imagePullPolicy: "IfNotPresent"
name: "container-1"
resources:
limits:
cpu: "200m"
memory: "512Mi"
imagePullSecrets:
- name: "test-internetimage" # 使用刚才创建的镜像拉取凭证
创建工作负载:
kubectl create -f pod-internetimage.yaml
查看pod是否已经创建完成,ECI pod会使用镜像拉取凭证拉取自建仓库镜像:
kubectl get pod