.
├── prepare
│ ├── snapshot.yaml
│ └── storageclass.yaml
├── README.md
├── script
│ └── ping.sh
├── templates
│ ├── common-preferences-bundle-v1.0.0.yaml
│ └── common-templates.yaml
└── vms
├── simple_demo.yaml
└── vm_demo.yaml
4 directories, 8 files
OKEのプロビジョニングはこちらを参考に実施してください。
Worker NodeのスペックはVM.Standard.E5.Flex
シェイプで2oCPU、16GB RAMで作成してください。
なお、CNIはFlannelで構築してください。
以下のコマンドを実行します。
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64
minikube start --nodes=2 --cni=flannel
export VERSION=$(curl -s https://storage.googleapis.com/kubevirt-prow/release/kubevirt/kubevirt/stable.txt)
echo $VERSION
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/kubevirt-operator.yaml
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/kubevirt-cr.yaml
以下のコマンドを実行し、Deployed
になればインストールは完了
$ kubectl get kubevirt.kubevirt.io/kubevirt -n kubevirt -o=jsonpath="{.status.phase}"
Deployed
virtctlをインストール
VERSION=$(kubectl get kubevirt.kubevirt.io/kubevirt -n kubevirt -o=jsonpath="{.status.observedKubeVirtVersion}")
ARCH=$(uname -s | tr A-Z a-z)-$(uname -m | sed 's/x86_64/amd64/') || windows-amd64.exe
echo ${ARCH}
curl -L -o virtctl https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/virtctl-${VERSION}-${ARCH}
chmod +x virtctl
sudo install virtctl /usr/local/bin
nested virtualizationを有効化
kubectl -n kubevirt patch kubevirt kubevirt --type=merge --patch '{"spec":{"configuration":{"developerConfiguration":{"useEmulation":true}}}}'
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/master/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/master/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml
kubectl apply -f prepare/snapshot.yaml
export TAG=$(curl -s -w %{redirect_url} https://github.com/kubevirt/containerized-data-importer/releases/latest)
export VERSION=$(echo ${TAG##*/})
kubectl apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/$VERSION/cdi-operator.yaml
kubectl apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/$VERSION/cdi-cr.yaml
curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/v4.7.0/deploy/install-driver.sh | bash -s v4.7.0 --
kubectl apply -f prepare/nfs.yaml
kubectl apply -f - <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: kubevirt-config
namespace: kubevirt
labels:
kubevirt.io: ""
data:
feature-gates: "LiveMigration"
EOF
kubectl apply -f vms/simple_demo.yaml
virtctl start testvm
virtctl console testvm
kubectl apply -f templates/
ssh-keygen
PUBKEY=`cat <作成した公開鍵のパス>`
sed -i "s%ssh-rsa.*%$PUBKEY%" vms/vm_demo.yaml
kubectl apply -f vms/vm_demo.yaml
virtctl expose vm ocha-vm --name=ocha-ssh --port=20222 --target-port=22 --type=LoadBalancer
アサインされているパブリックIPを確認
kubect get svc ocha-ssh
ssh -i private.pem ubuntu@xxx.xxx.xxx.xxx -p 20222
sudo systemctl stop nginx
$ kubectl get vm -w
NAME AGE STATUS READY
ocha-vm 28m Running True
ocha-vm 29m Stopped True
ocha-vm 29m Stopped False
ocha-vm 29m Starting False
ocha-vm 29m Starting False
ocha-vm 29m Starting False
ocha-vm 29m Starting False
ocha-vm 29m Starting False
ocha-vm 29m Running False
ocha-vm 29m Running True
kubectxをインストール
kubectx minikube
kubectl apply -f vms/simple_demo.yaml
SSH接続後にバックグラウンドで8080番ポートでhttp接続受付
virtctl console testvm
while true; do ( echo "HTTP/1.0 200 Ok"; echo; echo "Migration test" ) | nc -l -p 8080; done &
NodePortで8080ポートを公開
virtctl expose vmi testvm --name=testvm-http --port=8080 --type=NodePort
別ターミナルでtestvmに対してhttp pingを送信
IP=$(minikube ip)
PORT=$(kubectl get svc testvm-http -o jsonpath='{.spec.ports[0].nodePort}')
curl ${IP}:${PORT}
Migrateを実行
virtctl migrate testvm
Pod(VM)のMigrate状態を観察
$ kuebctl get pods -o -w
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
virt-launcher-testvm-2t4bn 3/3 Running 0 12s 10.244.1.21 minikube-m02 <none> 1/1
virt-launcher-testvm-zp99b 0/3 Init:0/2 0 1s <none> minikube <none> 0/1
virt-launcher-testvm-zp99b 0/3 Init:1/2 0 2s 10.244.0.18 minikube <none> 0/1
virt-launcher-testvm-zp99b 0/3 PodInitializing 0 3s 10.244.0.18 minikube <none> 0/1
virt-launcher-testvm-zp99b 3/3 Running 0 4s 10.244.0.18 minikube <none> 0/1
virt-launcher-testvm-zp99b 3/3 Running 0 6s 10.244.0.18 minikube <none> 0/1
virt-launcher-testvm-zp99b 3/3 Running 0 6s 10.244.0.18 minikube <none> 1/1
virt-launcher-testvm-zp99b 3/3 Running 0 6s 10.244.0.18 minikube <none> 1/1
virt-launcher-testvm-zp99b 3/3 Running 0 7s 10.244.0.18 minikube <none> 1/1
virt-launcher-testvm-2t4bn 2/3 NotReady 0 18s 10.244.1.21 minikube-m02 <none> 1/1
virt-launcher-testvm-2t4bn 1/3 NotReady 0 19s 10.244.1.21 minikube-m02 <none> 1/1
virt-launcher-testvm-2t4bn 0/3 Completed 0 20s 10.244.1.21 minikube-m02 <none> 1/1
virt-launcher-testvm-2t4bn 0/3 Completed 0 21s <none> minikube-m02 <none> 1/1
virt-launcher-testvm-2t4bn 0/3 Completed 0 22s 10.244.1.21 minikube-m02 <none> 1/1
Migrate後でもhttp pingが通ることを確認
curl ${IP}:${PORT}