环境说明
kubevirt创建两个虚机
root@shawn-server:~# kubectl get po -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
virt-launcher-testvm-v2nnd 2/2 Running 0 36m 10.244.0.18 shawn-server <none> 1/1
virt-launcher-testvm2-2zg8r 2/2 Running 0 10m 10.244.0.19 shawn-server <none> 1/1
root@shawn-server:~# kubectl get vms
NAME AGE STATUS READY
testvm 37m Running True
testvm2 11m Running True
网络
结论: 通过pod ip即可访问虚机
virt launcher pod内的qemu进程就是kubevirt运行的虚机,pod内虚假tap设备接在linux bridge上,
iptables规则将pod veth设备的ip和虚机tap设备的ip做一一对应,以此访问pod ip就相当于访问虚机。
vm内ping cni0的ip
root@shawn-server:~# tcpdump -i cni0 -nvel icmp
tcpdump: listening on cni0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
02:05:49.419066 a2:66:26:1a:ff:e1 > 26:c1:ea:4f:46:20, ethertype IPv4 (0x0800), length 98: (tos 0x0, ttl 63, id 22688, offset 0, flags [DF], proto ICMP (1), length 84)
10.244.0.18 > 10.244.0.1: ICMP echo request, id 28930, seq 0, length 64
02:05:49.419106 26:c1:ea:4f:46:20 > a2:66:26:1a:ff:e1, ethertype IPv4 (0x0800), length 98: (tos 0x0, ttl 64, id 4134, offset 0, flags [none], proto ICMP (1), length 84)
10.244.0.1 > 10.244.0.18: ICMP echo reply, id 28930, seq 0, length 64
^C
2 packets captured
2 packets received by filter
0 packets dropped by kernel
testvm2 ping virt-launcher-testvm的pod ip,对比virt-launcher pod中的网卡计数
虚拟化
虚机是跑在virt-launcher pod中的qemu进程,磁盘文件位于/var/run/kubevirt/container-disks/disk_0.img
root@shawn-server:~# kubectl exec -it virt-launcher-testvm-v2nnd bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
bash-5.1$ virsh list
Authorization not available. Check if polkit service is running or see debug message for more information.
Id Name State
--------------------------------
1 default_testvm running
bash-5.1$ ps -ef > /tmp/1
bash-5.1$ cat /tmp/1
UID PID PPID C STIME TTY TIME CMD
qemu 1 0 0 01:00 ? 00:00:00 /usr/bin/virt-launcher-monitor --qemu-timeout 315s --name testvm --uid 23f5f50c-25ee-4e88-aa76-13325dbcb33e --namespace default --kubevirt-share-dir /var/run/kubevirt --ephemeral-disk-dir /var/run/kubevirt-ephemeral-disks --container-disk-dir /var/run/kubevirt/container-disks --grace-period-seconds 45 --hook-sidecars 0 --ovmf-path /usr/share/OVMF --run-as-nonroot
qemu 12 1 0 01:00 ? 00:00:03 /usr/bin/virt-launcher --qemu-timeout 315s --name testvm --uid 23f5f50c-25ee-4e88-aa76-13325dbcb33e --namespace default --kubevirt-share-dir /var/run/kubevirt --ephemeral-disk-dir /var/run/kubevirt-ephemeral-disks --container-disk-dir /var/run/kubevirt/container-disks --grace-period-seconds 45 --hook-sidecars 0 --ovmf-path /usr/share/OVMF --run-as-nonroot
qemu 29 12 0 01:00 ? 00:00:00 /usr/sbin/virtlogd -f /etc/libvirt/virtlogd.conf
qemu 30 12 0 01:00 ? 00:00:00 /usr/sbin/virtqemud -f /var/run/libvirt/virtqemud.conf
qemu 85 1 0 01:00 ? 00:00:04 /usr/libexec/qemu-kvm -name guest=default_testvm,debug-threads=on -S -object {"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/run/kubevirt-private/libvirt/qemu/lib/domain-1-default_testvm/master-key.aes"} -machine pc-q35-rhel9.2.0,usb=off,dump-guest-core=off,memory-backend=pc.ram,acpi=on -accel kvm -cpu Snowridge,ss=on,vmx=on,fma=on,pdcm=on,avx=on,f16c=on,hypervisor=on,tsc-adjust=on,bmi1=on,avx2=on,bmi2=on,invpcid=on,adx=on,pku=on,waitpkg=on,vaes=on,vpclmulqdq=on,rdpid=on,fsrm=on,md-clear=on,serialize=on,stibp=on,avx-vnni=on,fzrm=on,fsrs=on,fsrc=on,xsaves=on,abm=on,ibpb=on,ibrs=on,amd-stibp=on,amd-ssbd=on,rdctl-no=on,ibrs-all=on,skip-l1dfl-vmentry=on,mds-no=on,pschange-mc-no=on,mpx=off,cldemote=off,core-capability=off,split-lock-detect=off -m size=63488k -object {"qom-type":"memory-backend-ram","id":"pc.ram","size":65011712} -overcommit mem-lock=off -smp 1,sockets=1,dies=1,cores=1,threads=1 -object {"qom-type":"iothread","id":"iothread1"} -uuid 5a9fc181-957e-5c32-9e5a-2de5e9673531 -smbios type=1,manufacturer=KubeVirt,product=None,uuid=5a9fc181-957e-5c32-9e5a-2de5e9673531,family=KubeVirt -no-user-config -nodefaults -chardev socket,id=charmonitor,fd=20,server=on,wait=off -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown -boot strict=on -device {"driver":"pcie-root-port","port":16,"chassis":1,"id":"pci.1","bus":"pcie.0","multifunction":true,"addr":"0x2"} -device {"driver":"pcie-root-port","port":17,"chassis":2,"id":"pci.2","bus":"pcie.0","addr":"0x2.0x1"} -device {"driver":"pcie-root-port","port":18,"chassis":3,"id":"pci.3","bus":"pcie.0","addr":"0x2.0x2"} -device {"driver":"pcie-root-port","port":19,"chassis":4,"id":"pci.4","bus":"pcie.0","addr":"0x2.0x3"} -device {"driver":"pcie-root-port","port":20,"chassis":5,"id":"pci.5","bus":"pcie.0","addr":"0x2.0x4"} -device {"driver":"pcie-root-port","port":21,"chassis":6,"id":"pci.6","bus":"pcie.0","addr":"0x2.0x5"} -device {"driver":"pcie-root-port","port":22,"chassis":7,"id":"pci.7","bus":"pcie.0","addr":"0x2.0x6"} -device {"driver":"pcie-root-port","port":23,"chassis":8,"id":"pci.8","bus":"pcie.0","addr":"0x2.0x7"} -device {"driver":"pcie-root-port","port":24,"chassis":9,"id":"pci.9","bus":"pcie.0","multifunction":true,"addr":"0x3"} -device {"driver":"pcie-root-port","port":25,"chassis":10,"id":"pci.10","bus":"pcie.0","addr":"0x3.0x1"} -device {"driver":"virtio-scsi-pci-non-transitional","id":"scsi0","bus":"pci.5","addr":"0x0"} -device {"driver":"virtio-serial-pci-non-transitional","id":"virtio-serial0","bus":"pci.6","addr":"0x0"} -blockdev {"driver":"file","filename":"/var/run/kubevirt/container-disks/disk_0.img","node-name":"libvirt-3-storage","cache":{"direct":true,"no-flush":false},"auto-read-only":true,"discard":"unmap"} -blockdev {"node-name":"libvirt-3-format","read-only":true,"discard":"unmap","cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":"libvirt-3-storage"} -blockdev {"driver":"file","filename":"/var/run/kubevirt-ephemeral-disks/disk-data/containerdisk/disk.qcow2","node-name":"libvirt-2-storage","cache":{"direct":true,"no-flush":false},"auto-read-only":true,"discard":"unmap"} -blockdev {"node-name":"libvirt-2-format","read-only":false,"discard":"unmap","cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":"libvirt-2-storage","backing":"libvirt-3-format"} -device {"driver":"virtio-blk-pci-non-transitional","bus":"pci.7","addr":"0x0","drive":"libvirt-2-format","id":"ua-containerdisk","bootindex":1,"write-cache":"on","werror":"stop","rerror":"stop"} -blockdev {"driver":"file","filename":"/var/run/kubevirt-ephemeral-disks/cloud-init-data/default/testvm/noCloud.iso","node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},"auto-read-only":true,"discard":"unmap"} -blockdev {"node-name":"libvirt-1-format","read-only":false,"discard":"unmap","cache":{"direct":true,"no-flush":false},"driver":"raw","file":"libvirt-1-storage"} -device {"driver":"virtio-blk-pci-non-transitional","bus":"pci.8","addr":"0x0","drive":"libvirt-1-format","id":"ua-cloudinitdisk","write-cache":"on","werror":"stop","rerror":"stop"} -netdev {"type":"tap","fd":"21","vhost":true,"vhostfd":"23","id":"hostua-default"} -device {"driver":"virtio-net-pci-non-transitional","host_mtu":1450,"netdev":"hostua-default","id":"ua-default","mac":"52:54:00:27:ae:b3","bus":"pci.1","addr":"0x0","romfile":""} -chardev socket,id=charserial0,fd=18,server=on,wait=off -device {"driver":"isa-serial","chardev":"charserial0","id":"serial0","index":0} -chardev socket,id=charchannel0,fd=19,server=on,wait=off -device {"driver":"virtserialport","bus":"virtio-serial0.0","nr":1,"chardev":"charchannel0","id":"channel0","name":"org.qemu.guest_agent.0"} -audiodev {"id":"audio1","driver":"none"} -vnc vnc=unix:/var/run/kubevirt-private/23f5f50c-25ee-4e88-aa76-13325dbcb33e/virt-vnc,audiodev=audio1 -device {"driver":"VGA","id":"video0","vgamem_mb":16,"bus":"pcie.0","addr":"0x1"} -global ICH9-LPC.noreboot=off -watchdog-action reset -device {"driver":"virtio-balloon-pci-non-transitional","id":"balloon0","free-page-reporting":true,"bus":"pci.9","addr":"0x0"} -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny -msg timestamp=on
qemu 483 0 0 02:12 pts/0 00:00:00 bash
qemu 493 483 0 02:12 pts/0 00:00:00 ps -ef