Skip to content

Instantly share code, notes, and snippets.

@phoracek
Created February 25, 2020 18:34
Show Gist options
  • Save phoracek/c54b3a618a33fe16b1b71216340eb8a2 to your computer and use it in GitHub Desktop.
Save phoracek/c54b3a618a33fe16b1b71216340eb8a2 to your computer and use it in GitHub Desktop.
KubeVirt FQDN connectivity

KubeVirt FQDN connectivity

This example sets up two KubeVirt VMs connected to the cluster network via masquerade. These VMs can use their FQDN to access themselves locally and get from one to another over the cluster network.

Apply VMs and Services

kubectl apply -f vms.yaml

Wait for VMs to be running

kubectl wait vmi vm1 vm2 --for condition=Available

Connect to one of the VMs

virtctl console vm1  # login with fedora:fedora

Verify that FQDN of the VM can be resolved locally

sudo dnf install -y traceroute
traceroute vm1.default.svc.cluster.local
traceroute to vm1.default.svc.cluster.local (127.0.0.1), 30 hops max, 60 byte packets
 1  localhost (127.0.0.1)  0.542 ms  0.400 ms  0.375 ms

Verify that it is possible to reach out to the second VM using the service name

ssh fedora@vm2.default.svc.cluster.local
The authenticity of host 'vm2.default.svc.cluster.local (10.96.130.9)' can't be established.
ECDSA key fingerprint is SHA256:nyj164Cw67561g1d7kO9TthUZtMfVyfWwFzuHn0LNjM.
ECDSA key fingerprint is MD5:d3:10:16:ff:1a:79:48:73:13:e2:61:d3:18:ee:a1:df.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'vm2.default.svc.cluster.local,10.96.130.9' (ECDSA) to the list of known host
s.                                                                                                     
fedora@vm2.default.svc.cluster.local's password: 
[fedora@vm2 ~]$ 
---
apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
name: vm1
labels:
kubevirt.io/vm: vm1
spec:
running: true
template:
metadata:
labels:
kubevirt.io/vm: vm1
spec:
domain:
devices:
interfaces:
- name: default
masquerade: {}
disks:
- disk:
bus: virtio
name: registryvolume
- disk:
bus: virtio
name: cloudinitvolume
resources:
requests:
memory: 512M
networks:
- name: default
pod: {}
volumes:
- name: registryvolume
containerDisk:
image: kubevirt/fedora-cloud-registry-disk-demo:latest
- cloudInitNoCloud:
userData: |-
#cloud-config
password: fedora
chpasswd: { expire: False }
hostname: vm1
fqdn: vm1.default.svc.cluster.local
bootcmd:
- echo 127.0.0.1 vm1.default.svc.cluster.local >> /etc/hosts
name: cloudinitvolume
---
apiVersion: v1
kind: Service
metadata:
name: vm1
spec:
ports:
- port: 22
protocol: TCP
selector:
kubevirt.io/vm: vm1
type: ClusterIP
---
apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
name: vm2
spec:
running: true
template:
metadata:
labels:
kubevirt.io/vm: vm2
spec:
domain:
devices:
interfaces:
- name: default
masquerade: {}
disks:
- disk:
bus: virtio
name: registryvolume
- disk:
bus: virtio
name: cloudinitvolume
resources:
requests:
memory: 512M
networks:
- name: default
pod: {}
volumes:
- name: registryvolume
containerDisk:
image: kubevirt/fedora-cloud-registry-disk-demo:latest
- cloudInitNoCloud:
userData: |-
#cloud-config
password: fedora
chpasswd: { expire: False }
hostname: vm2
fqdn: vm2.default.svc.cluster.local
bootcmd:
- echo 127.0.0.1 vm2.default.svc.cluster.local >> /etc/hosts
name: cloudinitvolume
---
apiVersion: v1
kind: Service
metadata:
name: vm2
spec:
ports:
- port: 22
protocol: TCP
selector:
kubevirt.io/vm: vm2
type: ClusterIP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment