This guide demonstrates Kubernetes cluster configuration using k3s. However, ale can be used with clusters configured through other methods such as kubeadm, kubespray, etc.


K3s Setup & Agent Install

1

After SSH connecting to EC2, run the following command to install k3s.

curl -sfL https://get.k3s.io | sh -s - server \
 --bind-address=0.0.0.0 \
 --advertise-address=[EC2 Public IP Address] \
 --tls-san=[EC2 Public IP Address] \
 --node-external-ip=[EC2 Public IP Address] \
 --disable=traefik \
 --docker
2

To use kubectl as a non-root user, run the following commands.

mkdir -p ~/.kube && \
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config && \
sudo chown $(whoami):$(whoami) ~/.kube/config && \
chmod 600 ~/.kube/config && \
echo "export KUBECONFIG=~/.kube/config" >> ~/.bashrc && \
exec -l $SHELL
3

Verify that the cluster is functioning properly by running the following command.

kubectl get nodes
# Verify that STATUS is Ready
NAME              STATUS   ROLES                  AGE     VERSION
ip-172-31-14-74   Ready    control-plane,master   6d21h   v1.31.3+k3s1
4

Run the following commands to install the ale agent.

kubectl apply -f https://raw.githubusercontent.com/ale-run/ale/refs/heads/main/k8s/dist/latest/agent.yaml

Kubernetes Metrics Server

The K3s installed according to this guide includes Metrics Server by default, so installation is not necessary. For clusters without Metrics Server, check the command below to install it.

Verify that resource usage is being displayed correctly through Metrics Server using the following command:

kubectl top nodes

Nginx Ingress Controller

1

Run the following commands to install Nginx Ingress Controller.

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx \
 --version 4.11.2 \
 --namespace ingress-nginx --create-namespace \
 --set controller.service.type=LoadBalancer \
 --set controller.allowSnippetAnnotations=true \
 --set controller.admissionWebhooks.enabled=false
2

Run the following command to verify that the External IP of the Kubernetes service matches the Elastic IP attached to EC2.

kubectl get svc -n ingress-nginx
NAME                       TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)                      AGE
ingress-nginx-controller   LoadBalancer   10.43.158.249   [External IP]    80:32119/TCP,443:31694/TCP   6d21h

Install and Run ale

1

Enter the following commands to install the `ale-run` package.

mkdir ale-run
cd ale-run
npm i @ale-run/runtime@latest
2

Enter the following command to run `ale` in production mode.

pm2 start "npx aled run -c [Kubernetes Cluster Name]" --name "ale-run" --watch

If no specific Kubernetes cluster name was specified, it is typically created with the name default and can be checked using the kubectl config current-context command.

3

The setup is complete when the logs from pm2 display the following.

pm2 log ale-run
...
[INFO] [plugin:loader] searching plugins at /home/ubuntu/ale-run/node_modules/@ale-run/runtime/dist
[INFO] [plugin:loader] 2 plugin detected in /home/ubuntu/ale-run/node_modules/@ale-run/runtime/dist
[INFO] [plugin:loader] plugin @ale-run/plugin-essentials has been added
[INFO] [plugin:loader] plugin @ale-run/plugin-file-store has been added
[INFO] [plugin:loader] searching plugins at /home/ubuntu/ale-run/node_modules
[INFO] [plugin:loader] 1 plugin detected in /home/ubuntu/ale-run/node_modules
[INFO] [plugin:loader] plugin @ale-run/plugin-ai-assistant has been added
[INFO] [plugin:essentials] plugin @ale-run/plugin-essentials is installed {}
[INFO] [plugin:essentials] plugin @ale-run/plugin-essentials is activate {}
[INFO] [plugin:file-store] plugin @ale-run/plugin-file-store is activate {}
[INFO] [plugin:file-store] working dir is /home/ubuntu/.ale
[INFO] [plugin:file-store] storage type is direct
[INFO] [plugin:file-store] upload dir is /home/ubuntu/.ale/files
[INFO] [plugin:file-store] temp dir is /home/ubuntu/.ale/temp
[INFO] [plugin:file-store] endpoint is (none)
[INFO] [plugin:file-store] max file size is 10MB
[INFO] [plugin:ai-assistant] plugin @ale-run/plugin-ai-assistant is activate {}
[WARN] [plugin] [@ale-run/plugin-ai-assistant] activate failed: The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' }).
[INFO] [runtime:init] api server listening on 0.0.0.0:9009

If you encounter database conflicts during execution or want to reset settings, delete existing ale data using the following command and restart:

rm -r ~/.ale