Skip to content

Commit c9fecc4

Browse files
authored
Merge pull request #76911 from sjhala-ccs/cnv-37038
CNV-37038-37057: Accessing VM using headless services
2 parents 68b2088 + 02edef3 commit c9fecc4

6 files changed

+165
-4
lines changed

_topic_maps/_topic_map.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4189,6 +4189,8 @@ Topics:
41894189
File: virt-connecting-vm-to-default-pod-network
41904190
- Name: Exposing a VM by using a service
41914191
File: virt-exposing-vm-with-service
4192+
- Name: Accessing a VM by using its internal FQDN
4193+
File: virt-accessing-vm-internal-fqdn
41924194
- Name: Connecting a VM to a Linux bridge network
41934195
File: virt-connecting-vm-to-linux-bridge
41944196
- Name: Connecting a VM to an SR-IOV network
@@ -4205,7 +4207,7 @@ Topics:
42054207
File: virt-dedicated-network-live-migration
42064208
- Name: Configuring and viewing IP addresses
42074209
File: virt-configuring-viewing-ips-for-vms
4208-
- Name: Accessing a VM by using the cluster FQDN
4210+
- Name: Accessing a VM by using its external FQDN
42094211
File: virt-accessing-vm-secondary-network-fqdn
42104212
- Name: Managing MAC address pools for network interfaces
42114213
File: virt-using-mac-address-pool-for-vms
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/vm_networking/virt-accessing-vm-internal-fqdn.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="virt-connecting-vm-internal-fqdn_{context}"]
7+
= Connecting to a virtual machine by using its internal FQDN
8+
9+
You can connect to a virtual machine (VM) by using its internal fully qualified domain name (FQDN).
10+
11+
.Prerequisites
12+
* You have installed the `virtctl` tool.
13+
* You have identified the internal FQDN of the VM from the web console or by mapping the VM to a headless service. The internal FQDN has the format `<vm.spec.hostname>.<vm.spec.subdomain>.<vm.metadata.namespace>.svc.cluster.local`.
14+
15+
16+
.Procedure
17+
18+
. Connect to the VM console by entering the following command:
19+
+
20+
[source,terminal]
21+
----
22+
$ virtctl console vm-fedora
23+
----
24+
25+
. To connect to the VM by using the requested FQDN, run the following command:
26+
+
27+
[source,terminal]
28+
----
29+
$ ping myvm.mysubdomain.<namespace>.svc.cluster.local
30+
----
31+
+
32+
.Example output
33+
[source,terminal]
34+
----
35+
PING myvm.mysubdomain.default.svc.cluster.local (10.244.0.57) 56(84) bytes of data.
36+
64 bytes from myvm.mysubdomain.default.svc.cluster.local (10.244.0.57): icmp_seq=1 ttl=64 time=0.029 ms
37+
----
38+
+
39+
In the preceding example, the DNS entry for `myvm.mysubdomain.default.svc.cluster.local` points to `10.244.0.57`, which is the cluster IP address that is currently assigned to the VM.
40+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/vm_networking/virt-accessing-vm-internal-fqdn.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="virt-creating-headless-services_{context}"]
7+
= Creating a headless service in a project by using the CLI
8+
9+
To create a headless service in a namespace, add the `clusterIP: None` parameter to the service YAML definition.
10+
11+
.Prerequisites
12+
* You have installed the OpenShift CLI (`oc`).
13+
14+
.Procedure
15+
16+
. Create a `Service` manifest to expose the VM, such as the following example:
17+
+
18+
[source,yaml]
19+
----
20+
apiVersion: v1
21+
kind: Service
22+
metadata:
23+
name: mysubdomain # <1>
24+
spec:
25+
selector:
26+
expose: me # <2>
27+
clusterIP: None # <3>
28+
ports: # <4>
29+
- protocol: TCP
30+
port: 1234
31+
targetPort: 1234
32+
----
33+
<1> The name of the service. This must match the `spec.subdomain` attribute in the `VirtualMachine` manifest file.
34+
<2> This service selector must match the `expose:me` label in the `VirtualMachine` manifest file.
35+
<3> Specifies a headless service.
36+
<4> The list of ports that are exposed by the service. You must define at least one port. This can be any arbitrary value as it does not affect the headless service.
37+
38+
. Save the `Service` manifest file.
39+
40+
. Create the service by running the following command:
41+
+
42+
[source,terminal]
43+
----
44+
$ oc create -f headless_service.yaml
45+
----
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/vm_networking/virt-accessing-vm-internal-fqdn.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="virt-discovering-vm-internal-fqdn_{context}"]
7+
= Mapping a virtual machine to a headless service by using the CLI
8+
9+
To connect to a virtual machine (VM) from within the cluster by using its internal fully qualified domain name (FQDN), you must first map the VM to a headless service. Set the `spec.hostname` and `spec.subdomain` parameters in the VM configuration file.
10+
11+
If a headless service exists with a name that matches the subdomain, a unique DNS A record is created for the VM in the form of `<vm.spec.hostname>.<vm.spec.subdomain>.<vm.metadata.namespace>.svc.cluster.local`.
12+
13+
.Procedure
14+
15+
. Edit the `VirtualMachine` manifest to add the service selector label and subdomain by running the following command:
16+
+
17+
[source,terminal]
18+
----
19+
$ oc edit vm <vm_name>
20+
----
21+
+
22+
.Example `VirtualMachine` manifest file
23+
[source,yaml]
24+
----
25+
apiVersion: kubevirt.io/v1
26+
kind: VirtualMachine
27+
metadata:
28+
name: vm-fedora
29+
spec:
30+
template:
31+
metadata:
32+
labels:
33+
expose: me # <1>
34+
spec:
35+
hostname: "myvm" # <2>
36+
subdomain: "mysubdomain" # <3>
37+
# ...
38+
----
39+
<1> The `expose:me` label must match the `spec.selector` attribute of the `Service` manifest that you previously created.
40+
<2> If this attribute is not specified, the resulting DNS A record takes the form of `<vm.metadata.name>.<vm.spec.subdomain>.<vm.metadata.namespace>.svc.cluster.local`.
41+
<3> The `spec.subdomain` attribute must match the `metadata.name` value of the `Service` object.
42+
43+
. Save your changes and exit the editor.
44+
45+
. Restart the VM to apply the changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
:_mod-docs-content-type: ASSEMBLY
2+
[id="virt-accessing-vm-internal-fqdn"]
3+
= Accessing a virtual machine by using its internal FQDN
4+
include::_attributes/common-attributes.adoc[]
5+
:context: virt-accessing-vm-internal-fqdn
6+
7+
toc::[]
8+
9+
You can access a virtual machine (VM) that is connected to the default internal pod network on a stable fully qualified domain name (FQDN) by using headless services.
10+
11+
A Kubernetes _headless service_ is a form of service that does not allocate a cluster IP address to represent a set of pods. Instead of providing a single virtual IP address for the service, a headless service creates a DNS record for each pod associated with the service. You can expose a VM through its FQDN without having to expose a specific TCP or UDP port.
12+
13+
[IMPORTANT]
14+
====
15+
If you created a VM by using the {product-title} web console, you can find its internal FQDN listed in the *Network* tile on the *Overview* tab of the *VirtualMachine details* page. For more information about connecting to the VM, see xref:../../virt/vm_networking/virt-accessing-vm-internal-fqdn.adoc#virt-connecting-vm-internal-fqdn_virt-accessing-vm-internal-fqdn[Connecting to a virtual machine by using its internal FQDN].
16+
====
17+
18+
19+
include::modules/virt-creating-headless-services.adoc[leveloffset=+1]
20+
21+
include::modules/virt-discovering-vm-internal-fqdn.adoc[leveloffset=+1]
22+
23+
include::modules/virt-connecting-vm-internal-fqdn.adoc[leveloffset=+1]
24+
25+
[role="_additional-resources"]
26+
[id="additional-resources_virt-accesing-vm-internal-fqdn"]
27+
== Additional resources
28+
29+
* xref:../../virt/vm_networking/virt-exposing-vm-with-service.adoc#virt-exposing-vm-with-service[Exposing a VM by using a service]

virt/vm_networking/virt-accessing-vm-secondary-network-fqdn.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
:_mod-docs-content-type: ASSEMBLY
22
[id="virt-accessing-vm-secondary-network-fqdn"]
3-
= Accessing a virtual machine by using the cluster FQDN
3+
= Accessing a virtual machine by using its external FQDN
44
include::_attributes/common-attributes.adoc[]
55
:context: virt-accessing-vm-secondary-network-fqdn
66

77
toc::[]
88

9-
You can access a virtual machine (VM) that is attached to a secondary network interface from outside the cluster by using the fully qualified domain name (FQDN) of the cluster.
9+
You can access a virtual machine (VM) that is attached to a secondary network interface from outside the cluster by using its fully qualified domain name (FQDN).
1010

11-
:FeatureName: Accessing VMs by using the cluster FQDN
11+
:FeatureName: Accessing a VM from outside the cluster by using its FQDN
1212
include::snippets/technology-preview.adoc[]
1313

1414
include::modules/virt-configuring-secondary-dns-server.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)