Deploying Trains Server: Kubernetes

This page describes the prerequisites and procedures for deploying Trains Server to Kubernetes clusters using manual instructions, as well accessing Trains Server, upgrading, and port mappings.

To deploy Trains Server to Kubernetes using Helm, see Deploying Trains Server: Kubernetes Using Helm.

Prerequisites

  • A Kubernetes cluster.
  • kubectl is installed and configured (see Install and Set Up kubectl in the Kubernetes documentation).
  • One node labeled app=trains.

Trains Server deployment uses node storage.

If more than one node is labeled as app=trains and you redeploy or update later, then Trains Server may not locate all your data.

Deploying

Step 1: Modify Elasticsearch default values in the Docker configuration file

Before deploying Trains Server in a Kubernetes cluster, you must modify several Elasticsearch settings in the Docker configuration. For more information, see Install Elasticsearch with Docker in the Elastic documentation and Daemon configuration file in the Docker documentation.

To modify Elasticsearch default values in your Docker configuration file, do the following:

  1. Connect to the node in the Kubernetes cluster that you labeled app=trains.
  2. If your system contains a /etc/sysconfig/docker Docker configuration file, then edit it and add the options in quotes to the available arguments in the OPTIONS section:
    OPTIONS="--default-ulimit nofile=1024:65536 --default-ulimit memlock=-1:-1"
  3. If your system does not contain a /etc/sysconfig/docker Docker configuration file, then create or edit a /etc/docker/daemon.json file and add or modify the defaults-ulimits section as the following example shows:
    {
        "default-ulimits": {
            "nofile": {
                "name": "nofile",
                "hard": 65536,
                "soft": 1024
            },
            "memlock":
            {
                "name": "memlock",
                "soft": -1,
                "hard": -1
            }
        }
    }
  4. Elastic requires that the vm.max_map_count kernel setting, which is the maximum number of memory map areas a process can use, is set to at least 262144.

    For CentOS 7, Ubuntu 16.04, Mint 18.3, Ubuntu 18.04 and Mint 19.x, we tested the following commands to set vm.max_map_count:
    echo "vm.max_map_count=262144" > /tmp/99-trains.conf
    sudo mv /tmp/99-trains.conf /etc/sysctl.d/99-trains.conf
    sudo sysctl -w vm.max_map_count=262144
  5. Restart docker:
    sudo service docker restart

Step 2. Deploy Trains Server in the Kubernetes Cluster

After modifying several Elasticsearch settings in your Docker configuration (see Step 1), you can deploy Trains Server.

To deploy Trains Server in your Kubernetes Clusters, do the following:

  1. Clone the trains-server-k8s repository and change to the new trains-server-k8s directory:
    git clone https://github.com/allegroai/trains-server-k8s.git && cd trains-server-k8s
  2. Create the trains namespace (all deployment is in trains namespace):
    kubectl apply -f trains-namespace.yaml
  3. Create all the deployments:
    kubectl apply -f .

Port Mapping

After deploying Trains Server, the services expose the following node ports:

  • API server on 30008.
  • Web server on 30080.
  • File server on 30081.

Accessing Trains Server

To access your Trains Server, do the following:

  • Create a load balancer and domain with records pointing to Trains Server using the following rules which Trains uses to translate domain names:
    • The record to access the Trains Web-App:
      *app.<your domain name>.*
      For example, trainsapp.mydomainname.com points to your node on port 30080.
    • The record to access the Trains API:
      *api.<your domain name>.*
      For example, trainsapi.mydomainname.com points to your node on port 30008.
    • The record to access the Trains file server:
      *files.<your domain name>.*
      For example, trainsfiles.mydomainname.com points to your node on port 30081.

Upgrading

Use the current release

We strongly encourage you to keep your Trains Server up to date, by upgrading to the current release.

To update your deployment, you must edit the yaml file you want to update and then run following command:

To update your Trains Server in Kubernetes clusters, do the following:

  1. If you previously deployed a Trains Server, you must first delete old deployments using the following command:
    kubectl delete -f .
  2. Edit the YAML file you want to update and then run following command:
    kubectl apply -f <file you edited>.yaml

Next Step