Registry v2:镜像 Registry Operator
Image Registry Operator 安装并管理集群范围的 Registry v2 实例。它会协调来自 Config/cluster 的 Registry 运行时资源,以及来自 ImagePruner/cluster 的计划清理资源。
主要组件
安装 Operator
当 Operator package 在 OperatorHub 中可用时,请从 web console 安装 Image Registry Operator。仅在 web console 不可用时,才将 YAML 路径用于受控自动化、恢复或支持指导下的安装。
不要使用旧版 Registry Cluster Plugin 来安装 Registry v2。旧版 Registry Cluster Plugin 仅对旧版 Registry 部署保留可用。
从 OperatorHub 安装
- 登录 ,并进入 Administrator 页面。
- 在左侧导航栏中,单击 Marketplace > OperatorHub。
- 搜索 Image Registry Operator 或
cluster-image-registry-operator。
- 单击 Install。
- 在安装页面中,除非你的发布指南另有说明,否则使用以下设置:
- 单击 Install。
- 如果出现批准提示,请审查并批准生成的安装计划。
- 等待直到 Operator 状态为 Installed。
验证安装:
kubectl -n image-registry-system get subscription,csv,installplan
kubectl -n image-registry-system get deployment cluster-image-registry-operator
预期结果:
- 已安装的 CSV 为
Succeeded。
cluster-image-registry-operator Deployment 可用。
使用 YAML 安装
如果安装命名空间不存在,请先创建它:
kubectl get namespace image-registry-system >/dev/null 2>&1 || \
kubectl create namespace image-registry-system
kubectl label namespace image-registry-system \
cpaas.io/project=cpaas-system \
pod-security.kubernetes.io/audit=privileged \
pod-security.kubernetes.io/enforce=privileged \
pod-security.kubernetes.io/warn=privileged \
--overwrite
创建一个名为 image-registry-operator-subscription.yaml 的文件:
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
annotations:
cpaas.io/target-namespaces: ""
name: cluster-image-registry-operator
namespace: image-registry-system
spec:
channel: stable
installPlanApproval: Manual
name: cluster-image-registry-operator
source: platform
sourceNamespace: cpaas-system
应用 Subscription:
kubectl apply -f image-registry-operator-subscription.yaml
批准生成的 InstallPlan:
kubectl -n image-registry-system get installplan
kubectl -n image-registry-system patch installplan <installplan-name> \
--type=merge \
-p '{"spec":{"approved":true}}'
等待 Operator:
kubectl -n image-registry-system wait \
--for=condition=Available \
deployment/cluster-image-registry-operator \
--timeout=300s
更改 Registry 管理状态
通过将 Config/cluster.spec.managementState 设置为 Managed 来启用 Registry:
kubectl patch configs.imageregistry.operator.alauda.io cluster \
--type=merge \
-p '{"spec":{"managementState":"Managed"}}'
验证 Registry 数据平面是否可用:
kubectl -n image-registry-system rollout status deployment/image-registry --timeout=300s
kubectl -n image-registry-system rollout status deployment/image-api-server --timeout=300s
kubectl get configs.imageregistry.operator.alauda.io cluster -o yaml
预期结果:
Config/cluster 报告 Available=True、Progressing=False 和 Degraded=False。
将管理状态设置为 Removed 会停止 Registry v2 运行时组件。在 Registry 被移除期间,push 和 pull 流量、Image API server 以及计划清理都不可用。仅在维护窗口或支持指导下的恢复过程中使用此状态。
在切换到 Removed 之前,请备份所需的图像数据,并检查存储管理模式:
kubectl get configs.imageregistry.operator.alauda.io cluster \
-o jsonpath='{.spec.storage.managementState}{"\n"}'
仅当 spec.storage.managementState 为 Unmanaged,或者存储管理员已确认后端存储回收策略会在 Registry 实例移除后保留数据时,才假定图像数据会被保留。
要停止 Registry,请将管理状态设置为 Removed:
kubectl patch configs.imageregistry.operator.alauda.io cluster \
--type=merge \
-p '{"spec":{"managementState":"Removed"}}'
验证数据平面 Deployment 已被移除:
kubectl -n image-registry-system get deployment image-registry image-api-server --ignore-not-found
预期结果:
- 在 Registry 被移除期间,
image-registry 和 image-api-server Deployment 不存在。
Image Pruner 协调
Operator 会将单例 ImagePruner/cluster 协调为 image-registry-system 中的 image-pruner CronJob。在 ImagePruner 资源中配置保留策略。请参阅 设置和配置 registry。
该 CronJob 默认使用 Registry v2 内部 service URL。
检查 Operator 和 Registry 状态
kubectl -n image-registry-system get subscription,csv,installplan
kubectl -n image-registry-system get deploy cluster-image-registry-operator image-registry image-api-server
kubectl -n image-registry-system get daemonset node-ca
kubectl -n image-registry-system get cronjob image-pruner
kubectl get apiservice v1.image.alauda.io
kubectl get configs.imageregistry.operator.alauda.io cluster -o yaml
kubectl get imagepruners.imageregistry.operator.alauda.io cluster -o yaml
预期结果:
- Operator CSV 为
Succeeded。
cluster-image-registry-operator、image-registry 和 image-api-server 可用。
node-ca 在目标节点上就绪。
APIService/v1.image.alauda.io 为 Available=True。
Config/cluster 报告 Available=True、Progressing=False 和 Degraded=False。
检查 Registry 日志和 metrics 访问
检查 Registry Pods:
kubectl -n image-registry-system get pods -l app.kubernetes.io/name=image-registry
查看 Registry 日志:
kubectl -n image-registry-system logs deployment/image-registry -c registry
从 monitoring service account 检查 metrics 访问:
kubectl auth can-i get pods -n image-registry-system \
--as=system:serviceaccount:cpaas-system:prometheus-sa
常见 Operator 问题