# Platform9 Hostagent

The Platform9 HostAgent is used to securely connect your infrastructure to your Platform9 SaaS Management Plane. The HostAgent can be installed using the [Platform9 CLI](https://github.com/platform9/pcd-docs-gitbook/blob/main/other-docs/pmk/5.14/nodes/learn/platform9-cli/README.md) or by manually downloading the HostAgent from the SaaS Management Plane and installing it on each node. The HostAgent is specific to each SaaS Managment Plane and cannot be used across different SaaS Managment Planes.

{% hint style="info" %}
**Important**

The Platform9 CLI is the recommended way of installing the host agent and related PMK components and should be sufficient for most supported linux environments.

Only follow the manual mechanism to download and install the hostagent if specifically directed by Platform9 support or if the Platform9 CLI is running into issues on your linux environment.
{% endhint %}

## Install HostAgent

To install the HostAgent follow the steps below:

1. Navigate to the Infrastructure dashboard Nodes tab
2. Click the + Onboard a Node button
3. On the add Node page click the Advanced tab
4. From here select the target OS and download the HostAgent Binary
5. Copy the HostAgent to the target node and install the HostAgent
6. Run`./platform9-install-debian.sh`to install the HostAgent

Example: HostAgent Installation

{% tabs %}
{% tab title="Bash" %}

```bash
./platform9-install-debian.sh --controller=<<saas_management_plane_fqdn>> --username=<<user_email>> --password=<<account_password>>  --project-name=<<tenant_to_attach>>
{% endtab %}
{% tab language="bash" title="Example" %}
// Click to edit code./platform9-install-debian.sh --controller=pmkft-demo-18238.platform9.io --username=user@gmai.com --password=MyGreatPassword  --project-name=service
```

{% endtab %}
{% endtabs %}

Once the installer starts you will need to answer two configuration questions.

{% tabs %}
{% tab title="Bash" %}

```bash
Extracting Platform9 installer

Do you want to configure proxy settings (yes/no)? no
Platform9 recommends using NTPD to keep the time in sync.
Do you want to install and configure this now (yes/no)? yes
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
**Warning**

All OS prerequisites must be completed manually to successfully install the HostAgent and create a cluster.

To automate prerequisites and installation of the HostAgent use the [Platform9 CLI](https://github.com/platform9/pcd-docs-gitbook/blob/main/other-docs/pmk/5.14/nodes/learn/platform9-cli/README.md)
{% endhint %}

## Uninstall HostAgent

In certain scenarios the Platform9 Host Agent will need to be uninstalled for a node to be successfully reused. This includes:

* Cloning a VM that has Host Agent installed
* Deauthorizing a node and re-running prep-node
* Host Agent installation was interrupted causing the installation to fail
* Node authorization fails due to network connectivity

To remove the Host Agent follow the steps below.

### Step 1 Detach Node From Cluster

To completely reuse a node the node must be first detached from a cluster by using the Scale Workers or Scale Master command on the Infrastructure ‘Clusters’ dashboard or using the CLI. Once the node has been removed from the cluster it needs to be deauthorized form the Platform9 SaaS Management Plane. This can be done on the Infrastructure ‘Nodes’ dashboard by selecting the node and clicking the ‘Deauthorize Node’ table action. Once this command has been completed the node is detached and no longer under management.

The alternate approach is to delete the cluster and deauthorize all nodes.

### Step 2 Make Sure HostAgent Is Not Running

Ensure the Host Agent process is not running by running the command:

{% tabs %}
{% tab title="Bash" %}

```bash
ps -ef | grep hostagent
```

{% endtab %}
{% endtabs %}

If the Host Agent is running stop the Host Agent process on the Node by running:

{% tabs %}
{% tab title="Bash" %}

```bash
sudo systemctl stop pf9-hostagent
```

{% endtab %}
{% endtabs %}

Stopping HostAgent should stop all other services. Run the commands below to ensure all services are stopped.

{% tabs %}
{% tab title="Bash" %}

```bash
sudo systemctl stop pf9-nodeletd 
sudo systemctl stop pf9-kubelet
```

{% endtab %}
{% endtabs %}

### Step 3 Remove Host Agent

Remove the Host Agent by running

{% tabs %}
{% tab title="Ubuntu" %}

```bash
sudo apt-get purge pf9-hostagent
{% endtab %}
{% tab language="bash" title="CentOS" %}
sudo yum erase -y pf9-hostagent
```

{% endtab %}
{% endtabs %}

### Example Host Agent Removal

{% tabs %}
{% tab title="Bash" %}

```bash
sudo apt-get purge pf9-hostagent 
[sudo] password for pf9admin: 
Reading package lists... Done 
Building dependency tree Reading state information... Done 
The following packages were automatically installed and are no longer required: cgroup-tools ipvsadm keepalived libcgroup1 libnl-route-3-200 socat 
Use 'sudo apt autoremove' to remove them. 
The following packages will be REMOVED: 
pf9-comms* pf9-hostagent* pf9-muster* 
0 upgraded, 0 newly installed, 3 to remove and 2 not upgraded. 
After this operation, 211 MB disk space will be freed. 
Do you want to continue? [Y/n] y 
(Reading database ... 154452 files and directories currently installed.) 
Removing pf9-comms (4.5.0-770.6874f04) ... 
Removing pf9-muster (4.5.0-343) ... 
Removing pf9-hostagent (4.5.0-409.5192397) ... 
Processing triggers for systemd (237-3ubuntu10.42) ... 
Processing triggers for ureadahead (0.100.0-21) ... 
(Reading database ... 141699 files and directories currently installed.) 
Purging configuration files for pf9-comms (4.5.0-770.6874f04) ... 
Purging configuration files for pf9-hostagent (4.5.0-409.5192397) ... 
dpkg: warning: while removing pf9-hostagent, directory '/var/opt/pf9' not empty so not removed 
dpkg: warning: while removing pf9-hostagent, directory '/var/log/pf9' not empty so not removed 
dpkg: warning: while removing pf9-hostagent, directory '/opt/pf9/python/lib/python3.6/__pycache__' not empty so not removed 
dpkg: warning: while removing pf9-hostagent, directory '/etc/pf9/certs' not empty so not removed
```

{% endtab %}
{% endtabs %}

### Clean up logs

Remove the existing logs

{% tabs %}
{% tab title="Bash" %}

```bash
sudo rm -fr  /var/log/pf9
```

{% endtab %}
{% endtabs %}
