Operator离线安装
文章目录
前言
OADP安装:
全程参考红帽官方文档:
https://access.redhat.com/documentation/zh-cn/openshift_container_platform/4.6/html-single/operators/index#olm-restricted-networks
强烈推荐操作系统使用REHL8。(安装过程避免依赖错误)
一、登陆红帽镜像仓库
通过 registry.redhat.io 进行身份验证(使用docker和podman都可以):
docker login registry.redhat.io
会提示输入红帽账号密码,没有账号的密码的自行进行申请在红帽官网。
二、查看软件包列表。
其实就是所有operator 安装源,因为全量很多很大需要进行裁剪 ,本次我需要离线安装OADP。
运行您要修剪容器中的源索引镜像。例如:
运用可以加上 -d 后台运行
docker run -p50051:50051 \
-it -d registry.redhat.io/redhat/redhat-operator-index:v4.6
输出示例
Trying to pull registry.redhat.io/redhat/redhat-operator-index:v4.6...
Getting image source signatures
Copying blob ae8a0c23f5b1 done
...
INFO[0000] serving registry database=/database/index.db port=50051
三、安装 opm,grpcurl
opm:用来同步镜像
wget https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/4.7.6/opm-linux-4.7.6.tar.gz
grpcurl :用来查看安装源列表
wget https://github.com/fullstorydev/grpcurl/releases/download/v1.8.0/grpcurl_1.8.0_linux_x86_64.tar.gz
四、裁剪软件包列表
在一个单独的终端会话中,使用 grpcurl 命令获取由索引提供的软件包列表:
这个列表红帽所有operators列表。
grpcurl -plaintext localhost:50051 api.Registry/ListPackages > packages.out
由于默认软件包比较多所有需要裁剪,留下自己需要的依赖源。
** registry.example.com/redhat-operator-index:v4.6 这个换成你自己的镜像仓库。**
sudo ./opm index prune -f registry.redhat.io/redhat/redhat-operator-index:v4.6 -p redhat-oadp-operator -i registry.redhat.io/openshift4/ose-operator-registry:v4.6 -t registry.example.com/zpf-redhat/redhat-operator-index:v4.6 -c docker
使用rehl8 不会遇到此问题,直接可以跳过,或者opm指令正常运行直接跳过
报错 解决方案:升级glibc到2.28版本 make –j2 时间有点长
安装glibc 编译失败需要升级GMP 4.2+,MPFR 2.4.0+ MPC 0.8.0+
最终解决方案:https://blog.csdn.net/wangying202/article/details/113178159
还有报错如下:
解决方案:
不报错以后继续进行裁剪:
默认是podman 我用的docker 使用 –c 来进行切换
sudo ./opm index prune -f registry.redhat.io/redhat/redhat-operator-index:v4.6 -p redhat-oadp-operator -i registry.redhat.io/openshift4/ose-operator-registry:v4.6 -t registry.example.com/zpf-redhat/redhat-operator-index:v4.6 -c docker
成功显示以下:
docker images 查看刚生成的镜像(生成的镜像作用就是里面有你需要安装的operator安装源,后面使用这个镜像来进行同步)然后重新运行,检查是否裁剪成功,(我刚才只保存oadp正常只有一个)
docker run -p50051:50051 -it -d registry.example.com/zpf-redhat/redhat-operator-index:v4.6
grpcurl -plaintext localhost:50051 api.Registry/ListPackages > packages.out
已上镜像裁剪成功!!!!
五、配置访问harbor证书
配置docker证书 dockerx509问题
/etc/docker/certs.d/
复制CA file到以上目录
如果是自签发镜像仓库证书
cp /root/ca.crt /etc/pki/ca-trust/source/anchors/
update-ca-trust
执行update-ca-trust 更新证书
然后重新登陆镜像仓库
docker login --username pop --password xxx registry.example.com
六、同步镜像
把本地镜像同步到harbor仓库
./oc adm catalog mirror (本地images)registry.example.com/zpf-test/redhat-operator-index:v4.6 (远程镜像仓库地址)registry.example.com/zpf-test --insecure
需要漫长的时间(1.5G 2个小时待优化)
七、镜像地址映射
虽然导入到本地镜像仓库,但是ocp集群还是会去联网下载镜像,所以需要加一下映射管理,把外网的地址映射到本地的harborr镜像仓库中。
生成了一个文件imageContentSourcePolicy.yaml, mirror文件,用于导入到ocp 中,将外部仓库地址映射到我们的私有仓库
oc create –f imageContentSourcePolicy.yaml
八、从索引镜像创建目录
创建一个 CatalogSource 对象来引用索引镜像。如果使用 oc adm catalog mirror 命令将目录镜像到目标 registry,您可以使用生成的 catalogSource.yaml 文件作为起点。
根据您的规格修改以下内容,并将它保存为 catalogSource.yaml 文件:
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: my-operator-catalog
namespace: openshift-marketplace
spec:
sourceType: grpc
image: <registry>:<port>/<namespace>/redhat-operator-index:v4.6
displayName: My Operator Catalog
publisher: <publisher_name>
updateStrategy:
registryPoll:
interval: 30m
oc apply -f catalogSource.yaml
检查 pod:
oc get pods -n openshift-marketplace
检查目录源:
oc get catalogsource -n openshift-marketplace
检查软件包清单:
oc get packagemanifest -n openshift-marketplace
现在,您可以在 OpenShift Container Platform Web 控制台中通过 OperatorHub 安装 Operator。
九、重启集群
重启master、worker、infra、route
如果签发起始时间发生更新,运行业务准备好进行重启后,可开启MachineConfigPool的更新开关
oc patch --type=merge --patch='{"spec":{"paused":false}}' machineconfigpool/master
oc patch --type=merge --patch='{"spec":{"paused":false}}' machineconfigpool/worker
oc patch --type=merge --patch='{"spec":{"paused":false}}' machineconfigpool/infra
oc patch --type=merge --patch='{"spec":{"paused":false}}' machineconfigpool/router
主机全部重启完成后,使用同样的方法再将MachineConfigPool的更新开关关闭
oc patch --type=merge --patch='{"spec":{"paused":true}}' machineconfigpool/master
oc patch --type=merge --patch='{"spec":{"paused":true}}' machineconfigpool/worker
oc patch --type=merge --patch='{"spec":{"paused":true}}' machineconfigpool/infra
oc patch --type=merge --patch='{"spec":{"paused":true}}' machineconfigpool/router