當 OpenShift 安裝在受限制的網絡上時,Operator Lifecycle Manager(OLM)不能再使用默認的 OperatorHub 來源,因為它們需要完全的Internet連接。系統管理員可以禁用這些默認 OperatorHub 來源並創建本地鏡像,以便 OLM 可以改為從本地來源安裝和管理Operator。
主要的概念如下:
CatalogSource
物件,將來源指向本地映像倉庫,例如 Quay。我會使用 Grafana Operator 當範例,在受限制的網絡上部署 Grafana Operator 到我自己的專案空間。
oc patch OperatorHub cluster --type json \
-p '[{"op": "add", "path": "/spec/disableAllDefaultSources", "value": true}]'
$ curl https://quay.io/cnr/api/v1/packages?namespace=community-operators | jq . > packages.txt
{
"channels": null,
"created_at": "2019-07-26T13:43:46",
"default": "3.5.0",
"manifests": [
"helm"
],
"name": "community-operators/grafana-operator",
"namespace": "community-operators",
"releases": [
"3.5.0",
"2.0.0",
"1.3.0"
],
"updated_at": "2020-07-31T18:43:47",
"visibility": "public"
},
$ curl -k https://quay.io/cnr/api/v1/packages/community-operators/grafana-operator/3.5.0 | jq .
[
{
"content": {
"digest": "cc44387393bbb233201a5a02de7697b38cfaa5bb89fbdf22b6b0cd78be3e96ef",
"mediaType": "application/vnd.cnr.package.helm.v0.tar+gzip",
"size": 8630,
"urls": []
},
"created_at": "2020-07-31T18:43:47",
"digest": "sha256:0aaed6bdaa093c3eb58378d45ae72f2d332f4632681e59507b8639c29a371b4c",
"mediaType": "application/vnd.cnr.package-manifest.helm.v0.json",
"metadata": null,
"package": "community-operators/grafana-operator",
"release": "3.5.0"
}
]
$ curl -k -XGET https://quay.io/cnr/api/v1/packages/community-operators/grafana-operator/blobs/sha256/cc44387393bbb233201a5a02de7697b38cfaa5bb89fbdf22b6b0cd78be3e96ef -o grafana-operator.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 8630 100 8630 0 0 13782 0 --:--:-- --:--:-- --:--:-- 13808
$ tar -xf grafana-operator.tar.gz
$ mkdir -p manifests/grafana-operator
$ cp -r grafana-operator-njs08tsk/* manifests/grafana-operator/
在 Quay 建立 Mirror Repository 來下載 manifests 中的operator 映像檔到本地端。
修改 manifests 中映像檔位址並指導本地映像檔倉庫。
$ sed -i "s;quay.io/integreatly/grafana-operator:v3.5.0;quay-uat/mirrors/grafana-operator:v3.5.0;g" ./3.5.0/grafana-operator.v3.5.0.clusterserviceversion.yaml
$ sed -i "s;quay.io/integreatly/grafana-operator:v2.0.0;quay-uat/mirrors/grafana-operator:v2.0.0;g" ./2.0.0/grafana-operator.v2.0.0.clusterserviceversion.yaml
Dockerfile:
FROM registry.redhat.io/openshift4/ose-operator-registry:v4.2.24 AS builder
COPY manifests manifests
RUN /bin/initializer -o ./bundles.db
FROM registry.access.redhat.com/ubi7/ubi
COPY --from=builder /registry/bundles.db /bundles.db
COPY --from=builder /usr/bin/registry-server /registry-server
COPY --from=builder /bin/grpc_health_probe /bin/grpc_health_probe
EXPOSE 50051
ENTRYPOINT ["/registry-server"]
CMD ["--database", "bundles.db"]
透過 podman 指令建立映像檔並上傳到本地映像檔倉庫。
$ podman build -t quay-uat/applications/operator-catalog-registry:0.1.0 .
$ podman push quay-uat/applications/operator-catalog-registry:0.1.0
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: brandon-operator-catalog
namespace: openshift-marketplace
spec:
displayName: Brandon Operator Catalog
sourceType: grpc
image: quay-uat/applications/operator-catalog-registry:0.1.0
上述步驟是參考 OpenShift 4.2 的官方文件, 在 OpenShift 4.5 的官方文件 又是不同的方法,真心覺得 OpenShift 的官方文件設計的很差,常常 Google 到舊版本的文件,喵的!
最後,國慶日快樂!