Bug 1644523 - The description of virtctl expose is not accurate enough in the Doc
Summary: The description of virtctl expose is not accurate enough in the Doc
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Container Native Virtualization (CNV)
Classification: Red Hat
Component: Documentation
Version: 1.2
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
: 1.3
Assignee: Pan Ousley
QA Contact: Irina Gulina
URL:
Whiteboard:
Depends On: 1648651
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-10-31 04:52 UTC by Yan Du
Modified: 2019-01-15 14:05 UTC (History)
7 users (show)

Fixed In Version: 1.3
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-01-15 14:05:53 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Yan Du 2018-10-31 04:52:21 UTC
Document URL:  https://access.redhat.com/articles/3500741

Section Number and Name: 

Access the virtual machine
The virtctl expose command forwards a virtual machine instance port to a node port and creates a service for enabled access. The following example creates the fedora-vm-ssh service which forwards port 22 of the fedora-vm virtual machine to port 20022 on the node:

virtctl expose vm fedora-vm --port=20022 --target-port=22 --name=fedora-vm-ssh

After the service has been created, you can access the virtual machine instance via SSH using the ipAddress of the node.

Login to the virtual machine instance:

ssh username@<node IP> -p 20022


Describe the issue: 

I think the above part for virtctl expose is not accurate enough.


Suggestions for improvement: 

1. It is better to update the cmd to 
virtctl expose vm fedora-vm --port=20022 --target-port=22 --node-port=30001 --name=fedora-vm-ssh --type=NodePort 

--port 20022 --> this port is just for accessing the vm via ClusterIP/LoadBalancer type

--node-port 30001 --> this port is the one for accessing the vm via NodePort

2. The NodePort range is 30000-32767, so we the port 20022 is out of the range if we want to set it as a nodeport, or we can add a note for the nodeport range.


Maybe we can update to:

Access the virtual machine
The virtctl expose command forwards a virtual machine instance port to a node port and creates a service for enabled access. The following example creates the fedora-vm-ssh service which forwards port 22 of the fedora-vm virtual machine to port 30001 on the node:

**Note:** NodePorts are in the 30000-32767 range by default

virtctl expose vm fedora-vm --port=20022 --target-port=22 --node-port=30001 --name=fedora-vm-ssh --type=NodePort 

After the service has been created, you can access the virtual machine instance via SSH using the ipAddress of the node.

Login to the virtual machine instance:

ssh username@<node IP> -p 30001


Additional information:

Comment 1 Jean-Francois Saucier 2018-11-02 17:38:32 UTC
On my environment, after running the following command :

virtctl expose vm fedora-vm --port=20022 --target-port=22 --node-port=30001 --name=fedora-vm-ssh --type=NodePort

I still need to ssh to port 20022 with this command instead of 30001 :

ssh username@<node IP> -p 20022

Comment 2 Yan Du 2018-11-05 02:24:58 UTC
Hi, Jean-Francois Saucier
Seems I can't reproduce the issue you mentioned. Only port 30001 works for nodeIP.
$ oc get svc
NAME            TYPE           CLUSTER-IP      EXTERNAL-IP               PORT(S)           AGE
fedora-svc     NodePort       172.30.72.181   <none>                    20022:30001/TCP   3s

$ ssh fedora.246.58 -p 20022  
ssh: connect to host 10.8.246.58 port 20022: No route to host

$ ssh fedora.246.58 -p 30001
The authenticity of host '[10.8.246.58]:30001 ([10.8.246.58]:30001)' can't be established.
ECDSA key fingerprint is SHA256:5jlzvgFNwHvgZZtZHoB5vpQ2UBuxL+TiBBv2DlrZlzg.
ECDSA key fingerprint is MD5:db:f4:cb:12:e5:91:55:96:f8:f4:58:d5:8e:a5:d6:ab.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[10.8.246.58]:30001' (ECDSA) to the list of known hosts.
fedora.246.58's password: 
[fedora@vmi-fedora ~]$ 

Could you please kindly check that you are using the correct NodeIP? If the port 20022 works, I think maybe you are using the clusterIP instread of nodeIP.

Comment 3 Jean-Francois Saucier 2018-11-05 14:17:26 UTC
Hi Yan,

You are absolutely right, I was using the ClusterIP in my previous comment, you can disregard it.

Using the correct NodeIP, the port is effectively 30001.

Comment 4 Pan Ousley 2018-11-07 22:56:05 UTC
Hi, thanks for raising the bug. Please check my revision to make sure it is correct:

https://github.com/openshift/openshift-docs/blob/f6f36503f3d94b8fbc8f8db3ac2564d930e17b0a/modules/cnv_accessing_vmi_ssh.adoc

Comment 5 Yan Du 2018-11-08 02:53:13 UTC
Hi, The doc LGTM. Thanks

Comment 6 Roman Mohr 2018-11-08 11:32:35 UTC
I think that `--node-port` should be removed immediately. That was for sure an unintended diversion from `kubectl expose`. `kubectl` uses --port in combination with --type=NodePort. `--node-port` does not exist there. We want it to work the same way.

Comment 7 Pan Ousley 2018-11-08 14:05:37 UTC
Roman -

>>>> Do I understand correctly that this:

$ virtctl expose vm fedora-vm --port=20022 --target-port=22 --node-port=30001 --name=fedora-vm-ssh --type=NodePort

$ ssh username@<node IP> -p 30001

>>>> should be changed to this:

$ virtctl expose vm fedora-vm --port=20022 --target-port=22 --name=fedora-vm-ssh --type=NodePort

$ ssh username@<node IP> -p 30001

>>>> ?

Comment 8 Yan Du 2018-11-09 09:25:15 UTC
@Roman @Pan
--node-port is not a required parameter here, a random nodeport will be assigned to the service (30000-32767) when remove the --type=NodePort in the cmd, if we do that, then I think we need explain why we use the random port for "ssh username@<node IP> -p $RandomPort"

Comment 9 Roman Mohr 2018-11-09 09:31:20 UTC
So what I am trying to say is this, that on kubectl it works like this:

 $ kubectl expose pod mypod --port=20022 --target-port=22 --name=myservice --type=NodePort

whereas for virtctl you would have to do:

 $ kubectl expose pod mypod --node-port=20022 --target-port=22 --name=myservice --type=NodePort


We did not want to introduce a different syntax for virtctl than for kubectl. We have a bug here in virtctl.

Comment 10 Pan Ousley 2018-11-09 14:50:35 UTC
Ok, so if the bug is in virtctl then IIUC, I should keep the current syntax (from my commit in Comment 4) until that bug is fixed. Correct me if I am wrong, but I'll move this to ON_QA in the meantime.

Comment 11 Yan Du 2018-11-11 11:51:16 UTC
I will open another bug for tracking the --node-port problem since this bug is a Doc bug.

@Pan, IMO, I think you could update the doc as Roman suggested. As I said in #Comment8, --node-port is not a required parameter, you could remove --node-port in the doc and add a line to explain how we can get the random node port the service acquired. WDYT?

Comment 12 Fabian Deutsch 2018-11-15 12:45:17 UTC
I think this is targeted for 1.3

Comment 13 Pan Ousley 2018-11-15 21:22:16 UTC
Yan, unfortunately I'm not sure I understand. Are you saying that I should remove both "--node-port" and "--type=NodePort"?  This is based on Comment #8 where you mention both arguments. Or should I just remove "--node-port"? 

And is this basically the workaround we're discussing?:

1. run virtctl command (no --node-port)
2. run command to figure out what port virtctl acquired (this seems clunky to me, if so). something like "grep virtctl /etc/services"? Not sure what the preferred command is.
3. ssh username@<node IP> -p <port from step 2>

Thanks :)

Comment 14 Yan Du 2018-11-16 06:50:31 UTC
Hi, Pan

I think you almost get it. Removing the "--node-port" is enough, we need to keep the "--type=NodePort" since we are exposing a NodePort type service. 

Hope below can help you to understand it:

Access the virtual machine
The virtctl expose command forwards a virtual machine instance port to a node port and creates a service for enabled access. The following example creates the fedora-vm-ssh service which forwards port 22 of the fedora-vm virtual machine to a node port on the nodes:

virtctl expose vm fedora-vm --port=20022 --target-port=22 --name=fedora-vm-ssh --type=NodePort 

After the service has been created, you can check the service and access the virtual machine instance via SSH using the ipAddress of the node.

oc get svc
NAME            TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
fedora-vm-ssh   NodePort   172.30.117.206   <none>        22:32551/TCP   6s

Login to the virtual machine instance:

ssh username@<node IP> -p 32551

Comment 15 Yan Du 2018-11-16 06:54:14 UTC
Above part should update to:

oc get svc
NAME            TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)           AGE
fedora-vm-ssh   NodePort   172.30.99.22   <none>        20022:32551/TCP   6s

Comment 16 Roman Mohr 2018-11-16 09:56:26 UTC
Hi,

I created a pull request against master (https://github.com/kubevirt/kubevirt/pull/1716) which should remove the differences between `kubectl expose` and `virtctl expose`. @Fabin would we want to backport this? It is not the first time that people have issues with node-port exposure because it works different than on `kubectl expose`.

Comment 17 Fabian Deutsch 2018-11-16 13:34:00 UTC
No backport was requested.
For now it's just documentation.

Comment 18 Pan Ousley 2018-11-19 23:04:33 UTC
Hi Yan, thanks for the explanation. I just made the following commit, can you please review it? Thank you.

https://github.com/openshift/openshift-docs/pull/12518/commits/bd4cff849c78c0db3f9e253f735a133ab03bac75

Comment 19 Yan Du 2018-11-20 02:45:26 UTC
@Pan, PR LGTM, thanks!

Comment 20 Pan Ousley 2018-11-20 14:59:09 UTC
Thanks Yan. Moving back to ON_QA

Comment 21 Nelly Credi 2018-11-26 13:15:44 UTC
@yan can we mark it as verified?

Comment 22 Yan Du 2018-11-27 01:52:45 UTC
@Nelly I'm ready to verify it after the code merged.

Comment 23 Nelly Credi 2018-12-02 12:22:59 UTC
@pan, when can we expect to see this merged?

Comment 24 Pan Ousley 2018-12-03 16:12:12 UTC
@Yan, @Nelly

The PR in question is the entire documentation setup for CNV :) The PR will be merged when we publish the docs. Does that clarify things?

Here is the docs preview as it currently stands: https://cnv_setup--ocpdocs.netlify.com/openshift-enterprise/latest/cnv_users_guide/cnv_users_guide.html#accessvmissh

...unless you meant you were waiting for Roman's PR to be merged?

Comment 25 Nelly Credi 2018-12-04 08:33:31 UTC
no, thats good, 
we only had the PR from comment#18, 
so thought we need to wait for it,
but if its in the guide, we can verify

Comment 26 Yan Du 2018-12-04 09:48:31 UTC
The guide of access vmi by ssh looks good. Move to verified. Thanks @Pan


Note You need to log in before you can comment on or make changes to this bug.