Service objects
Once the VirtualMachineInstance is started, in order to connect to a VirtualMachineInstance, you can create a Service object for a VirtualMachineInstance. Currently, three types of service are supported: ClusterIP, NodePort and LoadBalancer. The default type is ClusterIP.
Note: Labels on a VirtualMachineInstance are passed through to the pod, so simply add your labels for service creation to the VirtualMachineInstance. From there on it works like exposing any other k8s resource, by referencing these labels in a service.
Expose VirtualMachineInstance as a ClusterIP Service
Give a VirtualMachineInstance with the label special: key:
apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachineInstance
metadata:
name: vmi-ephemeral
labels:
special: key
spec:
domain:
devices:
disks:
- disk:
bus: virtio
name: containerdisk
resources:
requests:
memory: 64M
volumes:
- name: containerdisk
containerDisk:
image: kubevirt/cirros-registry-disk-demo:latestwe can expose its SSH port (22) by creating a ClusterIP service:
You just need to create this ClusterIP service by using kubectl:
Alternatively, the VirtualMachineInstance could be exposed using the virtctl command:
Notes: * If --target-port is not set, it will be take the same value as --port * The cluster IP is usually allocated automatically, but it may also be forced into a value using the --cluster-ip flag (assuming value is in the valid range and not taken)
Query the service object:
You can connect to the VirtualMachineInstance by service IP and service port inside the cluster network:
Expose VirtualMachineInstance as a NodePort Service
Expose the SSH port (22) of a VirtualMachineInstance running on KubeVirt by creating a NodePort service:
You just need to create this NodePort service by using kubectl:
Alternatively, the VirtualMachineInstance could be exposed using the virtctl command:
Notes: * If --node-port is not set, its value will be allocated dynamically (in the range above 30000) * If the --node-port value is set, it must be unique across all services
The service can be listed by querying for the service objects:
Connect to the VirtualMachineInstance by using a node IP and node port outside the cluster network:
Expose VirtualMachineInstance as a LoadBalancer Service
Expose the RDP port (3389) of a VirtualMachineInstance running on KubeVirt by creating LoadBalancer service. Here is an example:
You could create this LoadBalancer service by using kubectl:
Alternatively, the VirtualMachineInstance could be exposed using the virtctl command:
Note that the external IP of the service could be forced to a value using the --external-ip flag (no validation is performed on this value).
The service can be listed by querying for the service objects:
Use vinagre client to connect your VirtualMachineInstance by using the public IP and port.
Note that here the external port here (31829) was dynamically allocated.
Last updated