# Agent Configuration and Installation

This document helps to configure and install the Agent in the following two scenarios:

* **ISD and ArgoCd both are running in the same cluster.**&#x20;
* **ISD runs in one cluster and Argocd runs in a different cluster.**

## **ISD and ArgoCd both are running in the same cluster**

Follow the steps below to configure and install the Agent where ISD and ArgoCd both are running in the same cluster.

1. Connect to the cluster where you have installed ISD and ArgoCD applications.&#x20;

2. Run the below command to edit the controller config map and replace the URL as mentioned below.

   ```
   kubectl edit cm opsmx-controller-controller1 -n <NAMESPACE NAME>
   ```

   \
   Replace the URL in the config map under “**data**” section as mentioned below and save it.

   ```
   data:
     configFile: |
       serviceHostname: opsmx-controller-controller1
       agentHostname: agent-grpc.<NAMESPACE NAME>.svc.cluster.local
       remoteCommandHostname: agent-grpc.<NAMESPCAE NAME>.svc.cluster.local
       controlHostname: opsmx-controller-controller1
   ```

3. Restart controller pod in your application using the below command.

   ```
   kubectl rollout restart deploy opsmx-controller-controller1 -n <NAMESPACE NAME>
   ```

4. Login to the ISD application.

5. Create the Agent in “ISD for Argo'' UI and Download the manifest file to your local machine. For more information on how to create an Agent, refer [**here**](https://docs.opsmx.com/opsmx-intelligent-software-delivery-isd-platform-argo/user-guide/opsmx-agent/agent-creation).

6. Modify the below-mentioned details in the agent manifest file that you have downloaded and save it.\
   \
   Search with **namespace** in the Agent manifest file which is downloaded from the ISD UI and replace the “**namespace : default**” with **namespace** value where **Argocd** is running and save the file.

   ```
   subjects:
   - kind: ServiceAccount
     name: opsmx-agent-argocdhelm
     namespace: <namespace name>
   ```

   \
   Modify the replicas under spec section as per your requirements (by default it will have three).

   ```
   spec:
     replicas: 1
   ```

7. Create a new config map as shown below and modify the fields wherever mentioned.

   ```
   apiVersion: v1
   kind: ConfigMap
   metadata:
     name: opsmx-services-<Provide Agent name which is added in ISD UI>
     labels:
       agent.opsmx.com/name: <Provide Agent name which is added in ISD UI>
       agent.opsmx.com/role: agent
   data:
     services.yaml: |
       outgoingServices:
         - name: argocd
           type: argocd
           enabled: true
           config:
             url: http://<Provide ArgoCD service name here>:80
             insecure: true
             credentials:
               type: bearer
               token: <Provide base64 encoded Argo CD token here>
           annotations:
             description: argocd via agent
             uiUrl: https://<Provide your Argo CD url here>
   ```

8. You can generate the token in the Argo CD application. Follow the instructions below to generate the token.
   * Login to Argo CD application&#x20;
   * In the Application Dashboard, click on the “**Settings**” icon in the left-side navigation pane and then click on “**Accounts**”. Refer to the image below.<br>

     <figure><img src="https://lh5.googleusercontent.com/VsG2AyaGh_2_ofZ9Fbn3hwbeC47dYocnRf4J4ML7xlvbEdXou2eKMjWGbXIwRnCIXrjscrERgEzxII_M5cz1dVaPOLw-cf8SMOVu0JEHWBw2mnTZrXTOP7WKWhVFTuLM4jn-qYA17T4HSjZH2tfjmDzSPX8NS-pX7PVJhCF2Q_CGPrxeqRQ6_CQ4kw" alt=""><figcaption></figcaption></figure>
   * Select the user and click on “**Generate New**”. Refer to the image below.<br>

     <figure><img src="https://lh5.googleusercontent.com/MWOpN5NiUZyDO0KObVi_RIMaKQMuPgEzvOQYmaCjJvOmtDwUwPx94hflJJ6PutQNym1fFA5wI7QqgmsDnAxRpKvWZKAaLnAtgoACVvziWFg4-GK8sv00Ts0sEIGC715YYasM8vvZ4YZnWhul6pORpFr_AZdQUHMfpm5gneX6hCJ0vUjNs5-pw06jvg" alt=""><figcaption></figcaption></figure>
   * Now you will get a token. Copy that token, **encode it to base64 format**, and then provide it in the config map.

9. Apply the agent and config map files in your cluster using the below command.

   ```
   kubectl apply -f <agent file> -n <namespace name>
   kubectl apply -f <cm file> -n <namespace name>
   ```

10. Now go to the ISD UI and refresh it, you will see the Agent in healthy status, which means the agent is successfully connected to ISD. Refer to the image below.

    <figure><img src="https://lh4.googleusercontent.com/irdd7z8KAz0DvL8KU73pOqC_mKGbTJJ4yctwn1xOM-t0Y7VrUJmBSk3nIdYkOxWvu1DKyaYtv4G8NHOXGrkAF97wyaro9c1Waa987z4O4yJpIp9HWAS_z4sqLbmhW8dV_Gntm5A6O3tP3VS0b9kchW695qAEAffi0Cvj2MenmhHvr0YcxjLnlbWRAg" alt=""><figcaption></figcaption></figure>

### ISD and ArgoCd are running in two different clusters

Follow the steps below to configure and install the Agent where ISD is running in one cluster and ArgoCd is running in a different cluster.

{% hint style="info" %}
**Note:** If agent-grpc service external IP is already mapped to an agent host URL as part of Autopilot installation and updated in controller configmap, please ignore steps 1 to 5.
{% endhint %}

1. Prepare a URL for agent grpc IP mapping as per your agent host URL.
2. Map ISD agent-grpc external IP to agent host Url.
3. To get agent-grpc external IP, connect to Kubernetes cluster where you have installed the ISD application and run the below command in your cluster.

   ```
   kubectl get svc -n <ISD NAMESPACE-NAME> | grep grpc
   ```

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>Note:</strong> ISD namespace is the namespace where you have installed your ISD application.</p></div>
4. Edit the controller config map and replace the URL as mentioned below. To edit the config map run the below command.

   ```
   kubectl edit cm opsmx-controller-controller1 -n <ISD NAMESPACE-NAME>
   ```

   Replace the URL in the config map under “**data**” section as mentioned below and save it.

   <pre data-overflow="wrap"><code>data:
     configFile: |
       serviceHostname: opsmx-controller-controller1
       agentHostname: &#x3C;Provide your agent Host url here >
       remoteCommandHostname: &#x3C;Provide your agent Host url here>
       controlHostname: opsmx-controller-controller1
   </code></pre>
5. Restart the controller pod using the command below.

   <pre data-overflow="wrap"><code>kubectl rollout restart deploy opsmx-controller-controller1 -n &#x3C;ISD NAMESPACE-NAME>
   </code></pre>
6. Login to ISD application.&#x20;
7. Create the Agent in ISD UI and Download the manifest file to your local machine. For more information on how to create an Agent, refer [**here**](https://docs.opsmx.com/opsmx-intelligent-software-delivery-isd-platform-argo/user-guide/opsmx-agent/agent-creation).
8. Modify the following highlighted fields from the agent manifest file and save it.\
   \
   Search with **namespace** in the Agent manifest file which is downloaded from the ISD UI and replace the “**namespace : default**” with **namespace** value where **argocd** is running and save the file.

   <pre data-overflow="wrap"><code>subjects:
   - kind: ServiceAccount
     name: opsmx-agent-argocdhelm
     namespace: &#x3C;NAMESPACE-NAME>
   </code></pre>

   \
   Modify the replicas under spec section as per your requirements(by default it will have three)

   <pre data-overflow="wrap"><code>spec:
     replicas: 1
   </code></pre>
9. Create a new config map as shown below and modify the fields wherever mentioned.

   <pre data-overflow="wrap"><code>apiVersion: v1
   kind: ConfigMap
   metadata:
     name: opsmx-services-&#x3C;Provide Agent name which is added in ISD UI>
     labels:
       agent.opsmx.com/name: &#x3C;Provide Agent name which is added in ISD UI>
       agent.opsmx.com/role: agent
   data:
     services.yaml: |
       outgoingServices:
         - name: argocd
           type: argocd
           enabled: true
           config:
             url: http://&#x3C;Provide ArgoCD service name here>:80
             insecure: true
             credentials:
               type: bearer
               token: &#x3C;Provide base64 encoded Argo CD token here>
           annotations:
             description: argocd via agent
             uiUrl: https://&#x3C;Provide your Argo CD url here>
   </code></pre>
10. You can generate the token in the Argo CD application. Follow the instructions below to generate the token.
    * Login to ArgoCD application
    * In the Application Dashboard, click on the “**Settings**” icon in the left-side navigation pane and then click on “**Accounts**”. Refer to the image below.

      <figure><img src="https://lh4.googleusercontent.com/ECvcEYAJniEYv0llZCEOLNTPYzhIoqp7DwDGCZOUYc7CLenzph47NrzM1h8eVYzssZCbUbpqZbuvhgTRMYLlBC5sfWugZR4Jl8pVR8VkBqpxXMQ3YkPdZUoi7QfFCoLUqsbAxSuW-Y4i2JeYjGDBxXzn-9IlF9FFRlT8GlVDPH3pDu-zMX4ll8PiLA" alt=""><figcaption></figcaption></figure>
    * Select the user and click on “**Generate New**”. Refer to the image below.

      <figure><img src="https://lh4.googleusercontent.com/3FLbQeL3IJkVa_3WvzYEuwfHe76_iFhf00R6nBlG8UF6F9Q1fRr2LIbsVoDj0znVFIvqyhABRlCxubdv5Pf-H0Mt84xcrr15-yG3TQ0RldMj21SGTZLOpo8e3tflxd-extqJoMVf8rOq2DXNmldIAKMZTo_TY0-eE-SEOdiiwuCQyeqN4emwPHI0bw" alt=""><figcaption></figcaption></figure>
    * Now you will get a token. Copy that token and encode it to base64 format and then provide it in the config map.
11. Connect to Kubernetes cluster where you have installed Argo CD and Rollouts(Worker OEA install).
12. Apply agent file and config map file in your cluster using below command.

    <pre data-overflow="wrap"><code> kubectl apply -f &#x3C;cm file> -n &#x3C;NAMESPACE-NAME>           
     kubectl apply -f &#x3C;agent file> -n &#x3C;NAMESPACE-NAME> 
    </code></pre>
13. Now go to the ISD UI and refresh it, you will see the Agent in healthy status, which means the agent is successfully connected to ISD. Refer to the image below.<br>

    <figure><img src="https://lh3.googleusercontent.com/CiNXsjalSTflkp6348SJzFj9CRflkkHPCtnxb8HwwqcAp8UmgWsMcfQ5Bi9FIOhlfX3OHCWjYTKNdUPhs22g0FQWmqKo49EQFa16xH_hEv3cyhAbmurr-vK-E-7jyMzaGDAHUZLnPwOXI-9DKqhT9VxH2oGg-qr2zOGpAnY47RGOVfLGeLhAlY4VZA" alt=""><figcaption></figcaption></figure>
