# Offline Installation

Before starting the installation, make sure the [requirements](https://docs.akamas.io/akamas-docs/3.2.0/installing-akamas/kubernetes/prerequisites) are met.

## Configure the registry

If your cluster is in an air-gapped network or is unable to reach the default repository, you need to mirror the required images on a private repository.

The procedure described here leverages your local environment to upload the images, so it requires that Docker is installed and configured to interact with the private registry.

### Obtain the Docker images

Get in contact with Akamas Customer Services to get the latest versions of the Akamas artifacts. This will include:

* `images.tar.gz`: a tarball containing the Akamas images.
* `akamas`: the binary file of the Akamas CLI that will be used to verify the installation.

### Upload the Docker images <a href="#offlineinstallation-importdockerimages" id="offlineinstallation-importdockerimages"></a>

The offline installation mode requires importing the shipped Docker images into your local environment. Run the following command in the same directory where the tar file is stored:

```bash
cd '<IMAGES_ARCHIVE_LOCATION>'
docker image load -i images.tar.gz
```

Once the import is complete, you need to re-tag and upload the images. Run the following snippet, replacing `<REGISTRY_URL>` with the actual URL of the private registry:

```sh
REGISTRY='<REGISTRY_URL>'
for image in `docker images | awk '/485790562880.dkr.ecr.us-east-2.amazonaws.com/ {print $1 ":" $2}'`; do
  newImage="${image/485790562880.dkr.ecr.us-east-2.amazonaws.com/${REGISTRY}}"
  docker tag ${image} ${newImage}
  docker push ${newImage}
done
```

Once the upload is complete, you can proceed with the next steps.

## Create the configuration file

Akamas on Kubernetes is provided as a set of templates packaged in a chart archive managed by [Helm](https://helm.sh/).

To proceed with the installation, you need to create a file, called `akamas.yaml` in this guide, containing the mandatory configuration values required to customize your application. The following template contains the minimal set of values required to install Akamas:

```yaml
# Akamas customer name. Must match the value in the license (required)
akamasCustomer: <CUSTOMER_NAME>

# Akamas administrator password. If not set a random password will be generated
akamasAdminPassword: <ADMIN_PASSWORD>

registry: <REGISTRY_URL>
postgresql:
  image:
    registry: <REGISTRY_URL>
elasticsearch:
  image: <REGISTRY_URL>/elasticsearch
kibana:
  image: <REGISTRY_URL>/kibana
```

This minimal configuration is enough to have Akamas up and running on your cluster, even though the endpoint will only be accessible through Kubectl's [port forwarding](https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/).

The page [Accessing Akamas](https://docs.akamas.io/akamas-docs/3.2.0/installing-akamas/kubernetes/accessing-akamas) provides some configuration examples using different types of services: edit the `akamas.yaml` file using the strategy that better suits your needs, or continue directly with the sections and configure the endpoints at a later time.

## Configure the authentication

This section describes how to configure the authentication to your private registry. If your registry does not require any authentication, skip directly to the [installation section](#start-the-installation).

To authenticate to your private registry, you must manually create the *Secret* required to pull the images. If the registry uses basic authentication, you can create the credentials in the namespace by running the following command:

```bash
kubectl create secret docker-registry registry-token \
  --namespace akamas \
  --docker-server=<REGISTRY_URL> \
  --docker-username=<USER> \
  --docker-password=<PASSWORD>
```

Otherwise, you can leverage any credential already configured on your machine by running the following command:

```bash
kubectl create secret docker-registry registry-token \
  --namespace akamas \
  --from-file=.dockerconfigjson=<PATH/TO/.docker/config.json>
```

## Start the installation

Add the Akamas' repository to the Helm client with the following command:

```bash
helm repo add akamas http://helm.dev.akamas.io/charts
```

If you wish to see the values that will be used by helm to install Akamas and override some of them, you may execute the following commands (where akamas-\<version>.tgz is the filename downloaded by helm pull):

```bash
helm pull akamas/akamas
helm show values akamas-<version>.tgz
```

Now, with the configuration file you just created (and the new variables you added to override the defaults), you can start the installation with the following command:

```bash
helm upgrade --install \
  --create-namespace --namespace akamas \
  -f akamas.yaml \
  akamas akamas/akamas
```

This command will create the Akamas resources within the specified namespace. You can define a different namespace by changing the argument `--namespace <your-namespace>`

An example output of a successful installation is the following:

```
Release "akamas" does not exist. Installing it now.
NAME: akamas
LAST DEPLOYED: Wed Apr  5 11:40:19 2023
NAMESPACE: akamas
STATUS: deployed
REVISION: 1
NOTES:
Akamas has been installed

NOTES:
Akamas has been installed

To get the initial password use the following command:

kubectl get secret akamas-admin-credentials -o go-template='{{ .data.password | base64decode }}'
```

## Check the installation

To monitor the application startup, run the command `kubectl get pods`. After a few minutes, the expected output should be similar to the following:

```
NAME                           READY   STATUS    RESTARTS   AGE
airflow-6ffbbf46d8-dqf8m       3/3     Running   0          5m
analyzer-67cf968b48-jhxvd      1/1     Running   0          5m
campaign-666c5db96-xvl2z       1/1     Running   0          5m
database-0                     1/1     Running   0          5m
elasticsearch-master-0         1/1     Running   0          5m
keycloak-66f748d54-7l6wb       1/1     Running   0          5m
kibana-6d86b8cbf5-6nz9v        1/1     Running   0          5m
kong-7d6fdd97cf-c2xc9          1/1     Running   0          5m
license-54ff5cc5d8-tr64l       1/1     Running   0          5m
log-5974b5c86b-4q7lj           1/1     Running   0          5m
logstash-8697dd69f8-9bkts      1/1     Running   0          5m
metrics-577fb6bf8d-j7cl2       1/1     Running   0          5m
optimizer-5b7576c6bb-96w8n     1/1     Running   0          5m
orchestrator-95c57fd45-lh4m6   1/1     Running   0          5m
store-5489dd65f4-lsk62         1/1     Running   0          5m
system-5877d4c89b-h8s6v        1/1     Running   0          5m
telemetry-8cf448bf4-x68tr      1/1     Running   0          5m
ui-7f7f4c4f44-55lv5            1/1     Running   0          5m
users-966f8f78-wv4zj           1/1     Running   0          5m
```

At this point, you should be able to access the Akamas UI on `http://localhost:8000` and the Akamas CLI `http://localhost:8000/akapi` by running Kubectl's port forwarding command:

```bash
kubectl port-forward service/ui 8000:http
```

Mind that, before logging in, you need to [configure the Akamas CLI](https://docs.akamas.io/akamas-docs/3.2.0/installing-akamas/install-the-akamas-cli/initialize-akamas-cli) and [install a valid license](https://docs.akamas.io/akamas-docs/3.2.0/installing-akamas/install-the-akamas-license).

If you haven't already, you can update your configuration file to use a different type of service to expose Akamas' endpoints. To do so, pick from the [Accessing Akamas](https://docs.akamas.io/akamas-docs/3.2.0/installing-akamas/kubernetes/accessing-akamas) the configuration snippet for the service type of your choice, add it to the `akamas.yaml` file, and re-run the installation command to update your Helm release.
