文章大纲
内部注册表适合使用对象存储作为存储镜像实际数据的持久存储。
实施步骤分为三个步骤:
- 创建 OBC
- 创建 Secret
- 更改内部注册表配置
创建 OBC
在 openshift-image-registry
项目中创建内部注册表需要使用的 OBC 资源,资源定义参考如下:
apiVersion: objectbucket.io/v1alpha1
kind: ObjectBucketClaim
metadata:
name: obc-registry
namespace: openshift-image-registry
spec:
additionalConfig:
bucketclass: noobaa-default-bucket-class
generateBucketName: obc-registry
storageClassName: openshift-storage.noobaa.io
创建 OBC:
oc apply -f obc-registry.yaml
验证:
oc get obc
NAME STORAGE-CLASS PHASE AGE
obc-registry openshift-storage.noobaa.io Bound 79s
创建 Secret
将伴随 obc-registry
创建的 secret 进行提取:
oc get secrets -l app=noobaa -n openshift-image-registry
NAME TYPE DATA AGE
obc-registry Opaque 2 2m13s
oc extract secret/obc-registry -n openshift-image-registry
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
使用 AWS_KEY_ID
和 AWS_SECRET_ACCESS_KEY
文件的内容来创建 image-registry-private-configureation-user
的 secret:
oc create secret generic \
image-registry-private-configuration-user \
--from-literal=REGISTRY_STORAGE_S3_ACCESSKEY="$(cat AWS_ACCESS_KEY_ID)" \
--from-literal=REGISTRY_STORAGE_S3_SECRETKEY="$(cat AWS_SECRET_ACCESS_KEY)" \
-n openshift-image-registry
secret/image-registry-private-configuration-user created
更改内部注册表配置
获取创建的 OBC 对应的 Bucket 名称:
oc get -n openshift-image-registry objectbucketclaim/obc-registry -o jsonpath='{.spec.bucketName}{"\n"}'
obc-registry-0d8fecac-673b-4ef4-9387-de5083631658
编写 patch 文件:
apiVersion: imageregistry.operator.openshift.io/v1
kind: Config
metadata:
name: cluster
spec:
storage:
managementState: Managed
pvc: null
s3:
bucket: obc-registry-0d8fecac-673b-4ef4-9387-de5083631658
region: us-east-1
regionEndpoint: <S3 对应的路由>
对镜像注册表应用 patch 文件:
oc patch configs.imageregistry.operator.openshift.io cluster --type=merge --patch-file=patch.yaml
config.imageregistry.operator.openshift.io/cluster patched