Skip to main content

Kubernetes Configuration for Valkyr Services

When it comes to scaling your stack, Kubernetes is the goto as a great, easy and approachable way to get scaled up (or down) for very little upfront cost.

Pros and Cons

Pros:

  • total deployment flexibility in the cloud and behind the firewall
  • incredible horizontal scalability of compute across many redundant processing nodes
  • pretty good vertical scaling on commodity hardware via object storage and replication strategies
  • awesome portability of applications across cloud and premise-based resources
  • application upgrades can be rolled out incredibly smoothly
  • load balancing and fail over provide great fault tolerance

Cons:

  • can get extremely complicated fast, requiring knowledge of operating systems as well as networking and programming to fully manage
  • bugs can be excruciating to eliminate as they may cross system domains, operating systems, languages, and often layers of the OSI stack
  • spinning up new clusters is a slow process vs. restarting a single server or even a set of load balanced servers
  • mistakes can be incredibly expensive in downtime or excessive uptime (cloud instance fees)

What are the setup steps to get this going?

  1. Set up a Kubernetes cluster: You can use a managed Kubernetes service like Amazon EKS, Google Kubernetes Engine (GKE), or Azure Kubernetes Service (AKS), or you can set up your own cluster using tools like kubeadm.
  2. Configure a database: Set up a MySQL or PostgreSQL database instance to store your application data.
  3. Deploy ValkyrAI: Deploy the ValkyrAI backend and frontend to your Kubernetes cluster.
  4. Configure networking: Configure networking rules to allow access to your ValkyrAI services.
  5. Monitor your deployment: Set up monitoring tools to track the health and performance of your ValkyrAI deployment.

Setting up Apache and ValkyrAI on the Instance

This section describes how to set up Apache to serve the front end and proxy the REST API.

  1. Configure Apache Virtual Host: Create a virtual host configuration file for your ValkyrAI application. This file will define the domain name, document root, and other settings for your application.

    <VirtualHost *:80>
    ServerName valkyrai.example.com
    DocumentRoot /var/www/valkyrai

    <Directory /var/www/valkyrai>
    AllowOverride All
    Require all granted
    </Directory>

    ProxyPass /api http://localhost:8080/api
    ProxyPassReverse /api http://localhost:8080/api
    </VirtualHost>

    This configuration assumes that your ValkyrAI backend is running on localhost:8080. Adjust the ProxyPass and ProxyPassReverse directives accordingly if your backend is running on a different host or port.

  2. Enable the Virtual Host: Enable the virtual host configuration by creating a symbolic link to it in the sites-enabled directory.

    sudo ln -s /etc/apache2/sites-available/valkyrai.conf /etc/apache2/sites-enabled/valkyrai.conf
  3. Restart Apache: After making the changes, restart Apache to apply the new configuration.

    sudo /opt/bitnami/ctlscript.sh restart apache

Setting up a System Service to Launch the Backend

This section describes how to set up a system service to launch the ValkyrAI backend automatically.

  1. Create a Systemd Service File: Create a systemd service file for your ValkyrAI backend. This file will define the service name, description, and execution parameters.

    sudo vi /etc/systemd/system/valkyrai.service

    Add the following content to the file:

    [Unit]
    Description=ValkyrAI v1 API
    After=network.target

    [Service]
    User=bitnami
    WorkingDirectory=/home/bitnami/ValkyrAI
    ExecStart=/usr/bin/java -jar /home/bitnami/ValkyrAI/valkyrai-api-1.0-SNAPSHOT.jar

    [Install]
    WantedBy=multi-user.target

    This configuration assumes that your ValkyrAI backend is located in /home/bitnami/ValkyrAI and that the executable JAR file is named valkyrai-api-1.0-SNAPSHOT.jar. Adjust the WorkingDirectory and ExecStart directives accordingly if your backend is located in a different directory or if the JAR file has a different name.

    Also, make sure to configure the database connection URL in the ExecStart line:

    ExecStart=/usr/bin/java -jar /home/bitnami/ValkyrAI/valkyrai-api-1.0-SNAPSHOT.jar --spring.datasource.url=jdbc:mysql://ls-8ee50fe55eacc4884310f11919fc27eabb42aee7.cjbdbnvzknle.us-west-2.rds.amazonaws.com:3306/jamroom
  2. Enable the Service: Enable the systemd service to start automatically at boot.

    sudo systemctl enable valkyrai.service
  3. Start the Service: Start the systemd service.

    sudo systemctl start valkyrai.service
  4. Check the Service Status: Get the status of the service to ensure that it is running correctly.

    sudo systemctl status valkyrai.service

    If the service is running correctly, you should see output similar to the following:

    ● valkyrai.service - ValkyrAI v1 API
    Loaded: loaded (/etc/systemd/system/valkyrai.service; disabled; preset: enabled)
    Active: active (running) since Tue 2024-10-08 21:49:01 UTC; 2s ago
    Main PID: 93169 (java)
    Tasks: 14 (limit: 1107)
    Memory: 56.9M
    CPU: 3.847s
    CGroup: /system.slice/valkyrai.service
    └─93169 /usr/bin/java -jar /home/bitnami/ValkyrAI/valkyrai-api-1.0-SNAPSHOT.jar

    Oct 08 21:49:01 valkyrlabs.com systemd[1]: Started valkyrai.service - ValkyrAI v1 API.