《OpenShift / RHEL / DevSecOps 汇总目录》
说明:本文已经在 OpenShift 4.12 + OpenShift Virtualization 4.12 + ACM 2.8 或 MCE 2.3 的环境中验证
利用 OpenShift Virtualization 运行 OpenShift Hosted Cluster 即托管集群的架构如下图,该模式就是在 OpenShift 管理集群中的由 OpenShift Virtualization 提供的 VM 中运行托管集群的 Worker 节点。
$ oc patch mce multiclusterengine --type=merge -p '{"spec":{"overrides":{"components":[{"name":"hypershift-preview","enabled":true}]}}}'
apiVersion: addon.open-cluster-management.io/v1alpha1
kind: ManagedClusterAddOn
metadata:
name: hypershift-addon
namespace: local-cluster
spec:
installNamespace: open-cluster-management-agent-addon
$ oc get deployment -n hypershift
NAME READY UP-TO-DATE AVAILABLE AGE
operator 2/2 2 2 6m6s
$ oc get pod -n hypershift
NAME READY STATUS RESTARTS AGE
operator-7fdc8d998b-8s7pl 1/1 Running 0 9h
operator-7fdc8d998b-l9xpd 1/1 Running 0 9h
apiVersion: metallb.io/v1beta1
kind: MetalLB
metadata:
name: metallb
namespace: metallb-system
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: ip-addresspool
namespace: metallb-system
spec:
addresses:
- 10.39.127.20-10.39.127.26
autoAssign: true
avoidBuggyIPs: false
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: l2-adv
namespace: metallb-system
spec:
ipAddressPools:
- ip-addresspool
$ oc patch ingresscontroller -n openshift-ingress-operator default --type=json -p '[{ "op": "add", "path": "/spec/routeAdmission", "value": {wildcardPolicy: "WildcardsAllowed"}}]'
$ oc new-project clusters
$ curl -LOk https://hypershift-cli-download-multicluster-engine.$(
oc get ingresscontroller default -n openshift-ingress-operator -o json | jq -r '.status.domain'
)/linux/amd64/hypershift.tar.gz
$ tar -xvf hypershift.tar.gz
在 RHACM 控制台的集群页面中点击“创建集群”,然后进入 Red Hat OpenShift Virtualization,再点击 “托管”就可看到以下创建集群的提示界面。
根据上图的提示执行以下命令,即可创建托管集群,其 Worker 节点将运行在有 kubevirt 供应的 VM 环境中。另外,其中的 pull-secret 文件是从 Red Hat 官方下载。
$ export PULL_SECRET="$HOME/pull-secret"
$ export MEM="6Gi"
$ export CPU="2"
$ export WORKER_COUNT="2"
$ export CLUSTER_NAME=my-cluster-1
$ export OCP_VERSION=4.13.2
$ hypershift create cluster kubevirt \
--name $CLUSTER_NAME \
--release-image quay.io/openshift-release-dev/ocp-release:$OCP_VERSION-x86_64 \
--node-pool-replicas $WORKER_COUNT \
--pull-secret $PULL_SECRET \
--memory $MEM \
--cores $CPU
$ hypershift destroy cluster kubevirt --name my-cluster-1
2023-09-06T11:59:18Z INFO Found hosted cluster {"namespace": "clusters", "name": "my-cluster-1"}
2023-09-06T11:59:19Z INFO Updated finalizer for hosted cluster {"namespace": "clusters", "name": "my-cluster-1"}
2023-09-06T11:59:19Z INFO Deleting hosted cluster {"namespace": "clusters", "name": "my-cluster-1"}
2023-09-06T12:01:41Z INFO Deleting Secrets {"namespace": "clusters"}
2023-09-06T12:01:41Z INFO Deleted CLI generated secrets
2023-09-06T12:01:41Z INFO Finalized hosted cluster {"namespace": "clusters", "name": "my-cluster-1"}
2023-09-06T12:01:41Z INFO Successfully destroyed cluster and infrastructure {"namespace": "clusters", "name": "my-cluster-1d", "infraID": "my-cluster-1-zkrvf"}
视频
https://medium.com/@ben.swinney_ce/hypershift-with-kubevirt-564bd1f850ce
https://cloud.redhat.com/blog/effortlessly-and-efficiently-provision-openshift-clusters-with-openshift-virtualization