<p>I have installed k3s on a Cloud VM. (k3s is very similar to k8s. )</p>

<p>k3s server start as a master node. </p>

<p>And the master node's label shows internal-ip is 192.168.xxx.xxx. And the master node's annotations shows public-ip is also  192.168.xxx.xxx.</p>

<p>But the <strong>real public-ip of CloudVM is 49.xx.xx.xx.</strong> So agent from annother machine cannot connecting this master node.
Because agent always tries to connect proxy "wss://192.168.xxx.xxx:6443/...".</p>

<p><strong>If I run ifconfig on the Cloud VM, public-ip(49.xx.xx.xx) does not show. So k3s not find the right internal-ip or public-ip.</strong></p>

<p>I try to start k3s with --bind-address=49.xx.xx.xx , but start fail. I guess no NIC bind with this ip-address.  </p>

<p>How to resolve this problem, If I try to create a virtual netcard with address 49.xx.xx.xx ?</p>

alen
<p>The best option to connect Kubernetes master and nodes is using private network.</p>

<h2>How to setup K3S master and single node cluster:</h2>

<h3>Prerequisites:</h3>

<ul>
<li>All the machines need to be inside the same private network. For example 192.168.0.0/24 </li>
<li>All the machines need to communicate with each other. You can ping them with: <code>$ ping IP_ADDRESS</code></li>
</ul>

<p>In this example there are 2 virtual machines:</p>

<ul>
<li>Master node (k3s) with private ip of 10.156.0.13</li>
<li>Worker node (k3s-2) with private ip of 10.156.0.8 </li>
</ul>

<p><a href="https://i.stack.imgur.com/W9uiU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W9uiU.png" alt="enter image description here"></a></p>

<h3>Establish connection between VM's</h3>

<p>The most important thing is to check if the machines can connect with each other. As I said, the best way would be just to ping them.  </p>

<h3>Provision master node</h3>

<p>To install K3S on master node you need to invoke command from root user:</p>

<p><code>$ curl -sfL https://get.k3s.io | sh -</code></p>

<p>The output of this command should be like this:</p>

<pre><code>[INFO]  Finding latest release
[INFO]  Using v0.10.2 as release
[INFO]  Downloading hash https://github.com/rancher/k3s/releases/download/v0.10.2/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/rancher/k3s/releases/download/v0.10.2/k3s
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
[INFO]  Creating /usr/local/bin/ctr symlink to k3s
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
[INFO]  systemd: Enabling k3s unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.
[INFO]  systemd: Starting k3s
</code></pre>

<p>Check if master node is working: </p>

<p><code>$ kubectl get nodes</code></p>

<p>Output of above command should be like this: </p>

<pre><code>NAME   STATUS   ROLES    AGE     VERSION
k3s    Ready    master   2m14s   v1.16.2-k3s.1
</code></pre>

<p>Retrieve the <strong>IMPORTANT_TOKEN</strong> from master node with command:</p>

<p><code>$ cat /var/lib/rancher/k3s/server/node-token</code></p>

<p>This token will be used to connect agent node to master node. <strong>Copy it</strong></p>

<h3>Connect agent node to master node</h3>

<p>Ensure that node can communicate with master. 
After that you can invoke command from root user: </p>

<p><code>$ curl -sfL https://get.k3s.io | K3S_URL=https://MASTER_NODE_IP:6443 K3S_TOKEN=IMPORTANT_TOKEN sh -</code></p>

<p><strong>Paste your IMPORTANT_TOKEN into this command.</strong></p>

<p>In this case the MASTER_NODE_IP is the 10.156.0.13. </p>

<p>Output of this command should look like this: </p>

<pre><code>[INFO]  Finding latest release
[INFO]  Using v0.10.2 as release
[INFO]  Downloading hash https://github.com/rancher/k3s/releases/download/v0.10.2/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/rancher/k3s/releases/download/v0.10.2/k3s
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
[INFO]  Creating /usr/local/bin/ctr symlink to k3s
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-agent-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s-agent.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s-agent.service
[INFO]  systemd: Enabling k3s-agent unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s-agent.service → /etc/systemd/system/k3s-agent.service.
[INFO]  systemd: Starting k3s-agent
</code></pre>

<h3>Test</h3>

<p>Invoke command on master node to check if agent connected successfully: </p>

<p><code>$ kubectl get nodes</code> </p>

<p>Node which you added earlier should be visible here: </p>

<pre><code>NAME    STATUS   ROLES    AGE     VERSION
k3s     Ready    master   15m     v1.16.2-k3s.1
k3s-2   Ready    &lt;none&gt;   3m19s   v1.16.2-k3s.1
</code></pre>

<p>Above output concludes that the provisioning has happened correctly. </p>

<p>EDIT1: From this point you can deploy pods and expose them into public IP space. </p>

<h2>EDIT2:</h2>

<p>You can connect the K3S master and worker nodes on public IP network but there are some prerequisites. </p>

<h3>Prerequsities:</h3>

<ul>
<li>Master node need to have port 6443/TCP open</li>
<li>Ensure that master node has reserved static IP address </li>
<li>Ensure that firewall rules are configured to allow access only by IP address of worker nodes (static ip addresses for nodes can help with that) </li>
</ul>

<h3>Provisioning of master node</h3>

<p>The deployment of master node is the same as above. The only difference is that you need to get his public ip address. </p>

<p>Your master node does not need to show your public IP in commands like:</p>

<ul>
<li><code>$ ip a</code> </li>
<li><code>$ ifconfig</code></li>
</ul>

<h3>Provisioning worker nodes</h3>

<p>The deployment of worker nodes is different only in manner of changing IP address of master node from private one to public one. Invoke this command from root account:<br>
<code>curl -sfL https://get.k3s.io | K3S_URL=https://PUBLIC_IP_OF_MASTER_NODE:6443 K3S_TOKEN=IMPORTANT_TOKEN sh -</code></p>

<h3>Testing the cluster</h3>

<p>To ensure that nodes are connected properly you need to invoke command:</p>

<p><code>$ kubectl get nodes</code></p>

<p>The output should be something like this: </p>

<pre><code>NAME    STATUS   ROLES    AGE   VERSION
k3s-4   Ready    &lt;none&gt;   68m   v1.16.2-k3s.1
k3s-1   Ready    master   69m   v1.16.2-k3s.1
k3s-3   Ready    &lt;none&gt;   69m   v1.16.2-k3s.1
k3s-2   Ready    &lt;none&gt;   68m   v1.16.2-k3s.1
</code></pre>

<p>All of the nodes should be visible here. </p>
