Kubernetes : KubeVirt インストール2024/11/19 |
KubeVirt をインストールして、Kubernetes クラスターで完全仮想化の仮想マシンを利用できるようにします。 当例では以下のように 4 台のノードを使用して Kubernetes クラスターを構成しています。 +----------------------+ +----------------------+ | [ mgr.srv.world ] | | [ dlp.srv.world ] | | Manager Node | | Control Plane | +-----------+----------+ +-----------+----------+ eth0|10.0.0.25 eth0|10.0.0.30 | | ------------+--------------------------+----------- | | eth0|10.0.0.51 eth0|10.0.0.52 +-----------+----------+ +-----------+----------+ | [ node01.srv.world ] | | [ node02.srv.world ] | | Worker Node#1 | | Worker Node#2 | +----------------------+ +----------------------+ |
[1] | KubeVirt と virtctl コマンドをインストールします。 |
[root@mgr ~]#
export VERSION=$(curl https://storage.googleapis.com/kubevirt-prow/release/kubevirt/kubevirt/stable.txt) [root@mgr ~]# wget https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/kubevirt-operator.yaml [root@mgr ~]# wget https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/kubevirt-cr.yaml [root@mgr ~]# wget https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/virtctl-${VERSION}-linux-amd64
[root@mgr ~]#
[root@mgr ~]# mv virtctl-${VERSION}-linux-amd64 /usr/local/bin/virtctl [root@mgr ~]# chmod 755 /usr/local/bin/virtctl
kubectl apply -f 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
[root@mgr ~]#
kubectl apply -f kubevirt-cr.yaml kubevirt.kubevirt.io/kubevirt created # 一定時間経過すると 関連 pod が起動 [root@mgr ~]# kubectl get pods -n kubevirt NAME READY STATUS RESTARTS AGE virt-api-768454998c-kq7vv 1/1 Running 0 102s virt-api-768454998c-sj828 1/1 Running 0 102s virt-controller-7466b4d5f-fshtw 1/1 Running 0 62s virt-controller-7466b4d5f-tw6nv 1/1 Running 0 62s virt-handler-smbkf 1/1 Running 0 62s virt-handler-wdggw 1/1 Running 0 62s virt-operator-5b5f954844-4s4xv 1/1 Running 0 2m26s virt-operator-5b5f954844-f8zfq 1/1 Running 0 2m26s |
[2] | テスト用の仮想マシンを作成して動作確認します。 |
[root@mgr ~]#
[root@mgr ~]# wget https://raw.githubusercontent.com/kubevirt/kubevirt.github.io/master/labs/manifests/vm.yaml [root@mgr ~]# kubectl apply -f vm.yaml virtualmachine.kubevirt.io/testvm created kubectl get vms NAME AGE STATUS READY testvm 4s Stopped False # 仮想マシン起動 [root@mgr ~]# virtctl start testvm VM testvm was scheduled to start kubectl get vms NAME AGE STATUS READY testvm 25s Starting False[root@mgr ~]# kubectl get vmi NAME AGE PHASE IP NODENAME READY testvm 17s Running 192.168.241.131 node02.srv.world True # 仮想マシンのコンソールに接続 [root@mgr ~]# virtctl console testvm Successfully connected to testvm console. The escape sequence is ^] login as 'cirros' user. default password: 'gocubsgo'. use 'sudo' for root. testvm login: cirros Password: $ # ホストのコンソールに戻るには Ctrl + ] キー # * virsh コマンドと同じ操作 [root@mgr ~]# # 仮想マシンに ssh で接続 # ユーザー名 'cirros', パスワード 'gocubsgo' [root@mgr ~]# kubectl get pods NAME READY STATUS RESTARTS AGE virt-launcher-testvm-65r9d 3/3 Running 0 2m46s
[root@mgr ~]#
[root@mgr ~]# kubectl port-forward pod/virt-launcher-testvm-65r9d 222:22 &
ssh cirros@localhost -p 222 Handling connection for 222 The authenticity of host '[localhost]:222 ([::1]:222)' can't be established. ECDSA key fingerprint is SHA256:wBRmPQ0Bji0Hz5joZrXJfbil7oxvX8omvU2TECT5bqo. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '[localhost]:222' (ECDSA) to the list of known hosts. cirros@localhost's password: $ $ uname -a Linux testvm 4.4.0-28-generic #47-Ubuntu SMP Fri Jun 24 10:09:13 UTC 2016 x86_64 GNU/Linux $ cat /etc/os-release NAME=Buildroot VERSION=2015.05-g31af4e3-dirty ID=buildroot VERSION_ID=2015.05 PRETTY_NAME="Buildroot 2015.05" $ exit Connection to localhost closed. # 仮想マシン停止 [root@mgr ~]# virtctl stop testvm VM testvm was scheduled to stop [root@mgr ~]# kubectl get vms NAME AGE STATUS READY testvm 4m30s Stopped False # 仮想マシン削除 [root@mgr ~]# kubectl delete vm testvm virtualmachine.kubevirt.io "testvm" deleted [root@mgr ~]# kubectl get vms No resources found in default namespace. |
Sponsored Link |