2.16. 初始 Operator 配置
在 control plane 初始化后,您必须立即配置一些 Operator,以便它们都可用。
先决条件
- 您的 control plane 已初始化。
流程
观察集群组件上线:
watch -n5 oc get clusteroperators
$ watch -n5 oc get clusteroperators
Copy to Clipboard Copied! 输出示例
NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE authentication 4.16.0 True False False 19m baremetal 4.16.0 True False False 37m cloud-credential 4.16.0 True False False 40m cluster-autoscaler 4.16.0 True False False 37m config-operator 4.16.0 True False False 38m console 4.16.0 True False False 26m csi-snapshot-controller 4.16.0 True False False 37m dns 4.16.0 True False False 37m etcd 4.16.0 True False False 36m image-registry 4.16.0 True False False 31m ingress 4.16.0 True False False 30m insights 4.16.0 True False False 31m kube-apiserver 4.16.0 True False False 26m kube-controller-manager 4.16.0 True False False 36m kube-scheduler 4.16.0 True False False 36m kube-storage-version-migrator 4.16.0 True False False 37m machine-api 4.16.0 True False False 29m machine-approver 4.16.0 True False False 37m machine-config 4.16.0 True False False 36m marketplace 4.16.0 True False False 37m monitoring 4.16.0 True False False 29m network 4.16.0 True False False 38m node-tuning 4.16.0 True False False 37m openshift-apiserver 4.16.0 True False False 32m openshift-controller-manager 4.16.0 True False False 30m openshift-samples 4.16.0 True False False 32m operator-lifecycle-manager 4.16.0 True False False 37m operator-lifecycle-manager-catalog 4.16.0 True False False 37m operator-lifecycle-manager-packageserver 4.16.0 True False False 32m service-ca 4.16.0 True False False 38m storage 4.16.0 True False False 37m
NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE authentication 4.16.0 True False False 19m baremetal 4.16.0 True False False 37m cloud-credential 4.16.0 True False False 40m cluster-autoscaler 4.16.0 True False False 37m config-operator 4.16.0 True False False 38m console 4.16.0 True False False 26m csi-snapshot-controller 4.16.0 True False False 37m dns 4.16.0 True False False 37m etcd 4.16.0 True False False 36m image-registry 4.16.0 True False False 31m ingress 4.16.0 True False False 30m insights 4.16.0 True False False 31m kube-apiserver 4.16.0 True False False 26m kube-controller-manager 4.16.0 True False False 36m kube-scheduler 4.16.0 True False False 36m kube-storage-version-migrator 4.16.0 True False False 37m machine-api 4.16.0 True False False 29m machine-approver 4.16.0 True False False 37m machine-config 4.16.0 True False False 36m marketplace 4.16.0 True False False 37m monitoring 4.16.0 True False False 29m network 4.16.0 True False False 38m node-tuning 4.16.0 True False False 37m openshift-apiserver 4.16.0 True False False 32m openshift-controller-manager 4.16.0 True False False 30m openshift-samples 4.16.0 True False False 32m operator-lifecycle-manager 4.16.0 True False False 37m operator-lifecycle-manager-catalog 4.16.0 True False False 37m operator-lifecycle-manager-packageserver 4.16.0 True False False 32m service-ca 4.16.0 True False False 38m storage 4.16.0 True False False 37m
Copy to Clipboard Copied! - 配置不可用的 Operator。
2.16.1. 安装过程中删除的镜像 registry
在不提供可共享对象存储的平台上,OpenShift Image Registry Operator bootstraps 本身为 Removed
。这允许 openshift-installer
在这些平台类型上完成安装。
安装后,您必须编辑 Image Registry Operator 配置,将 managementState
从 Removed
切换到 Managed
。完成此操作后,您必须配置存储。
2.16.2. 镜像 registry 存储配置
对于不提供默认存储的平台,Image Registry Operator 最初不可用。安装后,您必须将 registry 配置为使用存储,以便 Registry Operator 可用。
显示配置生产集群所需的持久性卷的说明。如果适用,显示有关将空目录配置为存储位置的说明,这仅适用于非生产集群。
提供了在升级过程中使用 Recreate
rollout 策略来允许镜像 registry 使用块存储类型的说明。
2.16.2.1. 为裸机和其他手动安装配置 registry 存储
作为集群管理员,在安装后需要配置 registry 来使用存储。
先决条件
-
您可以使用具有
cluster-admin
角色的用户访问集群。 - 您有一个使用手动置备的 Red Hat Enterprise Linux CoreOS(RHCOS)节点(如裸机)的集群。
您已为集群置备持久性存储,如 Red Hat OpenShift Data Foundation。
重要当您只有一个副本时,OpenShift Container Platform 支持对镜像 registry 存储的
ReadWriteOnce
访问。ReadWriteOnce
访问还要求 registry 使用Recreate
rollout 策略。要部署支持高可用性的镜像 registry,需要两个或多个副本,ReadWriteMany
访问。- 必须具有 100Gi 容量。
流程
要将 registry 配置为使用存储,修改
configs.imageregistry/cluster
资源中的spec.storage.pvc
。注意使用共享存储时,请查看您的安全设置以防止外部访问。
验证您没有 registry pod:
oc get pod -n openshift-image-registry -l docker-registry=default
$ oc get pod -n openshift-image-registry -l docker-registry=default
Copy to Clipboard Copied! 输出示例
No resources found in openshift-image-registry namespace
No resources found in openshift-image-registry namespace
Copy to Clipboard Copied! 注意如果您的输出中有一个 registry pod,则不需要继续这个过程。
检查 registry 配置:
oc edit configs.imageregistry.operator.openshift.io
$ oc edit configs.imageregistry.operator.openshift.io
Copy to Clipboard Copied! 输出示例
storage: pvc: claim:
storage: pvc: claim:
Copy to Clipboard Copied! 将
claim
字段留空以允许自动创建image-registry-storage
PVC。检查
clusteroperator
状态:oc get clusteroperator image-registry
$ oc get clusteroperator image-registry
Copy to Clipboard Copied! 输出示例
NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE MESSAGE image-registry 4.16 True False False 6h50m
NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE MESSAGE image-registry 4.16 True False False 6h50m
Copy to Clipboard Copied! 确保 registry 设置为 managed,以启用镜像的构建和推送。
运行:
oc edit configs.imageregistry/cluster
$ oc edit configs.imageregistry/cluster
Copy to Clipboard Copied! 然后,更改行
managementState: Removed
managementState: Removed
Copy to Clipboard Copied! 至
managementState: Managed
managementState: Managed
Copy to Clipboard Copied!
2.16.2.2. 在非生产集群中为镜像 registry 配置存储
您必须为 Image Registry Operator 配置存储。对于非生产集群,您可以将镜像 registry 设置为空目录。如果您这样做,重启 registry 时会丢失所有镜像。
流程
将镜像 registry 存储设置为空目录:
oc patch configs.imageregistry.operator.openshift.io cluster --type merge --patch '{"spec":{"storage":{"emptyDir":{}}}}'
$ oc patch configs.imageregistry.operator.openshift.io cluster --type merge --patch '{"spec":{"storage":{"emptyDir":{}}}}'
Copy to Clipboard Copied! 警告仅为非生产集群配置这个选项。
如果在 Image Registry Operator 初始化其组件前运行这个命令,
oc patch
命令会失败并显示以下错误:Error from server (NotFound): configs.imageregistry.operator.openshift.io "cluster" not found
Error from server (NotFound): configs.imageregistry.operator.openshift.io "cluster" not found
Copy to Clipboard Copied! 等待几分钟,然后再次运行 命令。
2.16.2.3. 为裸机配置块 registry 存储
要允许镜像 registry 在作为集群管理员升级过程中使用块存储类型,您可以使用 Recreate rollout 策略
。
支持块存储卷或块持久性卷,但不建议在生产环境中使用镜像 registry。在块存储上配置 registry 的安装不具有高可用性,因为 registry 无法具有多个副本。
如果您选择将块存储卷与镜像 registry 搭配使用,则必须使用文件系统持久性卷声明(PVC)。
流程
输入以下命令将镜像 registry 存储设置为块存储类型,对 registry 进行补丁,使其使用
Recreate
rollout 策略,并只使用一个副本运行:1
oc patch config.imageregistry.operator.openshift.io/cluster --type=merge -p '{"spec":{"rolloutStrategy":"Recreate","replicas":1}}'
$ oc patch config.imageregistry.operator.openshift.io/cluster --type=merge -p '{"spec":{"rolloutStrategy":"Recreate","replicas":1}}'
Copy to Clipboard Copied! 为块存储设备置备 PV,并为该卷创建 PVC。请求的块卷使用 ReadWriteOnce(RWO)访问模式。
创建包含以下内容的
pvc.yaml
文件以定义 VMware vSpherePersistentVolumeClaim
对象:kind: PersistentVolumeClaim apiVersion: v1 metadata: name: image-registry-storage namespace: openshift-image-registry spec: accessModes: - ReadWriteOnce resources: requests: storage: 100Gi
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: image-registry-storage
1 namespace: openshift-image-registry
2 spec: accessModes: - ReadWriteOnce
3 resources: requests: storage: 100Gi
4 Copy to Clipboard Copied! 输入以下命令从文件创建
PersistentVolumeClaim
对象:oc create -f pvc.yaml -n openshift-image-registry
$ oc create -f pvc.yaml -n openshift-image-registry
Copy to Clipboard Copied!
输入以下命令编辑 registry 配置,使其引用正确的 PVC:
oc edit config.imageregistry.operator.openshift.io -o yaml
$ oc edit config.imageregistry.operator.openshift.io -o yaml
Copy to Clipboard Copied! 输出示例
storage: pvc: claim:
storage: pvc: claim:
1 Copy to Clipboard Copied! - 1
- 通过创建自定义 PVC,您可以将
claim
字段留空,以便默认自动创建image-registry-storage
PVC。