KubeVirt 02:部署 KubeVirt

前往 https://github.com/kubevirt/kubevirt/releases 可以看到当前已经 release 的版本,在 Assets 下可以看到提供的用于部署的 YAML 文件和 virtctl 管理工具。

部署 KubeVirt

获取当前 KubeVirt 的最新版本:

export KUBEVIRT_VERSION=$(curl -s https://api.github.com/repos/kubevirt/kubevirt/releases/latest | jq -r .tag_name)
echo $KUBEVIRT_VERSION
v1.2.0

当前使用的版本是 v1.2.0

开始部署 KubeVirt Operator:

vagrant@master01:~$ kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml

namespace/kubevirt created
customresourcedefinition.apiextensions.k8s.io/kubevirts.kubevirt.io created
priorityclass.scheduling.k8s.io/kubevirt-cluster-critical created
clusterrole.rbac.authorization.k8s.io/kubevirt.io:operator created
serviceaccount/kubevirt-operator created
role.rbac.authorization.k8s.io/kubevirt-operator created
rolebinding.rbac.authorization.k8s.io/kubevirt-operator-rolebinding created
clusterrole.rbac.authorization.k8s.io/kubevirt-operator created
clusterrolebinding.rbac.authorization.k8s.io/kubevirt-operator created
deployment.apps/virt-operator created

接下来部署 KubeVirt 通过创建 CRD,用于触发 operator 进行部署:

vagrant@master01:~$ kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml

kubevirt.kubevirt.io/kubevirt created

因为当前使用的 K8S 集群是在 VM 中的,如果硬件虚拟化不可用,可以配置 KubeVirt 使用软件虚拟化,这会降低性能,在能使用硬件虚拟化的时候不建议使用,默认 developerConfiguration 配置为空。

vagrant@master01:~$ kubectl -n kubevirt patch kubevirt kubevirt --type=merge --patch '{"spec":{"configuration":{"developerConfiguration":{"useEmulation":true}}}}'

kubevirt.kubevirt.io/kubevirt patched

等待 KubeVirt 部署完成

查看 kubevirt 的状态:

vagrant@master01:~$ kubectl get kubevirt -n kubevirt
NAME       AGE     PHASE
kubevirt   7m52s   Deployed

状态已经是 Deployed 说明已经部署完成了。

查看 kubevirt 命名空间中的 Pod:

vagrant@master01:~$ kubectl get pod -o wide -n kubevirt
NAME                              READY   STATUS    RESTARTS   AGE     IP              NODE       NOMINATED NODE   READINESS GATES
virt-api-54666f869-j84m2          1/1     Running   0          8m27s   10.244.241.86   master01   <none>           <none>
virt-api-54666f869-msk6c          1/1     Running   0          8m27s   10.244.30.85    worker02   <none>           <none>
virt-controller-c67776ccb-kk7fv   1/1     Running   0          7m51s   10.244.5.20     worker01   <none>           <none>
virt-controller-c67776ccb-phl9q   1/1     Running   0          7m52s   10.244.241.87   master01   <none>           <none>
virt-handler-6cx8p                1/1     Running   0          7m51s   10.244.5.21     worker01   <none>           <none>
virt-handler-8xs4s                1/1     Running   0          7m51s   10.244.241.88   master01   <none>           <none>
virt-handler-tk6b8                1/1     Running   0          7m51s   10.244.30.86    worker02   <none>           <none>
virt-operator-6776f5689d-6rjww    1/1     Running   0          15m     10.244.5.19     worker01   <none>           <none>
virt-operator-6776f5689d-zvl74    1/1     Running   0          15m     10.244.241.84   master01   <none>           <none>

当前还没有创建 VM,所以看不到 virt-launcher 相关的 Pod,在 kubevirt 命名空间中,可以看到 kubevirt 的核心组件,包括 virt-controller 和 virt-api 。

安装 virtctl

virtctl 可用于管理虚拟机,启动,停止。可以借助它进行 vnc、console 和 ssh 连接到 VM 。

直接下载可执行文件,赋予执行权限即可:

vagrant@master01:~$ wget -O virtctl https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/virtctl-${KUBEVIRT_VERSION}-linux-amd64

vagrant@master01:~$ chmod +x virtctl
vagrant@master01:~$ sudo mv virtctl /usr/local/bin/

vagrant@master01:~$ virtctl version
Client Version: version.Info{GitVersion:"v1.2.0", GitCommit:"f26e45d99ac35743fc33d6a121b629e9a9af6b63", GitTreeState:"clean", BuildDate:"2024-03-05T20:34:24Z", GoVersion:"go1.21.5 X:nocoverageredesign", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{GitVersion:"v1.2.0", GitCommit:"f26e45d99ac35743fc33d6a121b629e9a9af6b63", GitTreeState:"clean", BuildDate:"2024-03-05T21:32:21Z", GoVersion:"go1.21.5 X:nocoverageredesign", Compiler:"gc", Platform:"linux/amd64"}

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

滚动至顶部