|
6 | 6 | [id="virt-accessing-rdp-console_{context}"]
|
7 | 7 | = Connecting to a Windows virtual machine with an RDP console
|
8 | 8 |
|
9 |
| -The Remote Desktop Protocol (RDP) provides a better console experience for |
10 |
| -connecting to Windows virtual machines. |
11 |
| - |
12 |
| -To connect to a Windows virtual machine with RDP, specify the IP address of the |
13 |
| -attached L2 NIC to your RDP client. |
| 9 | +Create a Kubernetes `Service` object to connect to a Windows virtual machine (VM) by using your local Remote Desktop Protocol (RDP) client. |
14 | 10 |
|
15 | 11 | .Prerequisites
|
16 | 12 |
|
17 |
| -* A running Windows virtual machine with the QEMU guest agent installed. The |
18 |
| -`qemu-guest-agent` is included in the VirtIO drivers. |
19 |
| -* A layer 2 NIC attached to the virtual machine. |
20 |
| -* An RDP client installed on a machine on the same network as the |
21 |
| -Windows virtual machine. |
| 13 | +* A running Windows virtual machine with the QEMU guest agent installed. The `qemu-guest-agent` object is included in the VirtIO drivers. |
| 14 | +* An RDP client installed on your local machine. |
22 | 15 |
|
23 | 16 | .Procedure
|
24 | 17 |
|
25 |
| -. Log in to the {VirtProductName} cluster through the `oc` CLI tool as a user with |
26 |
| -an access token. |
| 18 | +. Edit the `VirtualMachine` manifest to add the label for service creation: |
| 19 | ++ |
| 20 | +[source,yaml] |
| 21 | +---- |
| 22 | +apiVersion: kubevirt.io/v1 |
| 23 | +kind: VirtualMachine |
| 24 | +metadata: |
| 25 | + name: vm-ephemeral |
| 26 | + namespace: example-namespace |
| 27 | +spec: |
| 28 | + running: false |
| 29 | + template: |
| 30 | + metadata: |
| 31 | + labels: |
| 32 | + special: key <1> |
| 33 | +# ... |
| 34 | +---- |
| 35 | +<1> Add the label `special: key` in the `spec.template.metadata.labels` section. |
| 36 | ++ |
| 37 | + |
| 38 | +[NOTE] |
| 39 | +==== |
| 40 | +Labels on a virtual machine are passed through to the pod. The `special: key` label must match the label in the `spec.selector` attribute of the `Service` manifest. |
| 41 | +==== |
| 42 | + |
| 43 | +. Save the `VirtualMachine` manifest file to apply your changes. |
| 44 | +. Create a `Service` manifest to expose the VM: |
| 45 | ++ |
| 46 | +[source,yaml] |
| 47 | +---- |
| 48 | +apiVersion: v1 |
| 49 | +kind: Service |
| 50 | +metadata: |
| 51 | + name: rdpservice <1> |
| 52 | + namespace: example-namespace <2> |
| 53 | +spec: |
| 54 | + ports: |
| 55 | + - targetPort: 3389 <3> |
| 56 | + protocol: TCP |
| 57 | + selector: |
| 58 | + special: key <4> |
| 59 | + type: NodePort <5> |
| 60 | +# ... |
| 61 | +---- |
| 62 | +<1> The name of the `Service` object. |
| 63 | +<2> The namespace where the `Service` object resides. This must match the `metadata.namespace` field of the `VirtualMachine` manifest. |
| 64 | +<3> The VM port to be exposed by the service. It must reference an open port if a port list is defined in the VM manifest. |
| 65 | +<4> The reference to the label that you added in the `spec.template.metadata.labels` stanza of the `VirtualMachine` manifest. |
| 66 | +<5> The type of service. |
| 67 | + |
| 68 | +. Save the `Service` manifest file. |
| 69 | +. Create the service by running the following command: |
27 | 70 | +
|
28 | 71 | [source,terminal]
|
29 | 72 | ----
|
30 |
| -$ oc login -u <user> https://<cluster.example.com>:8443 |
| 73 | +$ oc create -f <service_name>.yaml |
31 | 74 | ----
|
32 | 75 |
|
33 |
| -. Use `oc describe vmi` to display the configuration of the running |
34 |
| -Windows virtual machine. |
| 76 | +. Start the VM. If the VM is already running, restart it. |
| 77 | +. Query the `Service` object to verify that it is available: |
35 | 78 | +
|
| 79 | +[source, terminal] |
| 80 | +---- |
| 81 | +$ oc get service -n example-namespace |
| 82 | +---- |
| 83 | ++ |
| 84 | +.Example output for `NodePort` service |
36 | 85 | [source,terminal]
|
37 | 86 | ----
|
38 |
| -$ oc describe vmi <windows-vmi-name> |
| 87 | +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 88 | +rdpservice NodePort 172.30.232.73 <none> 3389:30000/TCP 5m |
| 89 | +---- |
| 90 | + |
| 91 | +. Run the following command to obtain the IP address for the node: |
| 92 | ++ |
| 93 | +[source,terminal] |
| 94 | +---- |
| 95 | +$ oc get node <node_name> -o wide |
39 | 96 | ----
|
40 | 97 | +
|
41 | 98 | .Example output
|
42 |
| -[source,yaml] |
| 99 | +[source,terminal] |
43 | 100 | ----
|
44 |
| -... |
45 |
| -spec: |
46 |
| - networks: |
47 |
| - - name: default |
48 |
| - pod: {} |
49 |
| - - multus: |
50 |
| - networkName: cnv-bridge |
51 |
| - name: bridge-net |
52 |
| -... |
53 |
| -status: |
54 |
| - interfaces: |
55 |
| - - interfaceName: eth0 |
56 |
| - ipAddress: 198.51.100.0/24 |
57 |
| - ipAddresses: |
58 |
| - 198.51.100.0/24 |
59 |
| - mac: a0:36:9f:0f:b1:70 |
60 |
| - name: default |
61 |
| - - interfaceName: eth1 |
62 |
| - ipAddress: 192.0.2.0/24 |
63 |
| - ipAddresses: |
64 |
| - 192.0.2.0/24 |
65 |
| - 2001:db8::/32 |
66 |
| - mac: 00:17:a4:77:77:25 |
67 |
| - name: bridge-net |
68 |
| -... |
| 101 | +NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP |
| 102 | +node01 Ready worker 6d22h v1.24.0 192.168.55.101 <none> |
69 | 103 | ----
|
70 | 104 |
|
71 |
| -. Identify and copy the IP address of the layer 2 network interface. This is |
72 |
| -`192.0.2.0` in the above example, or `2001:db8::` if you prefer IPv6. |
73 |
| -. Open an RDP client and use the IP address copied in the previous step for the |
74 |
| -connection. |
75 |
| -. Enter the *Administrator* user name and password to connect to the |
76 |
| -Windows virtual machine. |
| 105 | +. Specify the node IP address and the assigned port in your preferred RDP client. |
| 106 | +. Enter the user name and password to connect to the Windows virtual machine. |
0 commit comments