部署kubevirt教程

前提条件

已安装:kubernetes集群、kubectl、docker
apt install -y qemu-kvm libvirt virt-install bridge-utils 【所有节点全部安装】

virt-host-validate qemu

部署kubevirt

下载kubevirt-cr.yaml和kubevirt-operator.yaml
先执行:

Kubectl apply -f kubevirt-operator.yaml

在执行

Kubectl apply -f kubevirt-cr.yaml

查看是否部署成功

Kubectl get pods -A

安装virtctl,virtctl是kubevirt一个命令行工具
Github上搜索,进行下载【下载最新版本】:

cp -p virtctl-v0.58.0-linux-amd64 /usr/bin/virtctl
chmod +x /usr/bin/virtctl/
virtctl --help

删除Kubectl

kubectl delete -n kubevirt kubevirt kubevirt --wait=true   # --wait=true should anyway be default
kubectl delete apiservices v1.subresources.kubevirt.io   # this needs to be deleted to avoid stuck terminating namespaces
kubectl delete mutatingwebhookconfigurations virt-api-mutator   # not blocking but would be left over
kubectl delete validatingwebhookconfigurations virt-operator-validator   # not blocking but would be left over
kubectl delete validatingwebhookconfigurations virt-api-validator   # not blocking but would be left over
kubectl delete -f kubevirt-operator.yaml --wait=false

注意:如果您错误地首先删除了运算符,KV自定义资源将卡在Terminating状态,要修复它,请从资源中手动删除终结器。

运行kubevirt-operator.yaml会出现告警:Warning: Detected changes to resource kubevirts.kubevirt.io which is currently being deleted.
在这里插入图片描述
运行kubevirt-operator.yaml出现,链接不到kubevirt-operator-webhook。
在这里插入图片描述
注意:由于一个错误,需要手动删除apiservice和webhook配置。

kubectl -n kubevirt patch kv kubevirt --type=json -p '[{ "op": "remove", "path": "/metadata/finalizers" }]'

测试

curl https://kubevirt.io/labs/manifests/vm.yaml
kubectl apply -f https://kubevirt.io/labs/manifests/vm.yaml
kubectl get vm

启动虚拟机:

virtctl start testvm 
kubectl get vmi

部署kubevirt教程_第1张图片

进入虚拟机
部署kubevirt教程_第2张图片
对外发布端口

virtctl expose virtualmachine testvm --name vmiservice --target-port 22 --port 8022 --type NodePort
ssh -p30822 cirros@本地主机IP

你可能感兴趣的:(k8s,kubernets,in,docker)