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

Securing deployment

By default, Trains Server deploys as an open network. To restrict Trains Server access, follow the instructions in the Network and security section, on the "Configuring Trains Server" page.

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 Elasticsearch documentation and Daemon configuration file in the Docker documentation.

To modify Elasticsearch default values in your Docker configuration file:

  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. Elasticsearch 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:

  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/trains-server-k8s
    
  2. Create the trains namespace and deployments:

    kubectl apply -k overlays/current_version
    

    This installs the templates for the current trains-server version and update patch versions whenever the deployment is restarted (or reinstalled).

    To use use the latest version, which not recommended:

    kubectl apply -k base
    

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:

  1. Create domain records.

    • Create three records for the Trains Server web server, file server, and API access using the following rules:
      • app.<your domain name>
      • files.<your domain name>
      • api.<your domain name>

    For example:

    • app.trains.mydomainname.com
    • files.trains.mydomainname.com
    • api.trains.mydomainname.com
  2. Point the records you created to the load balancer.

  3. Configure the load balancer to redirect traffic coming from the records you created:

    • app.<your domain name> should be redirected to k8s cluster nodes on port 30080
    • files.<your domain name> should be redirected to k8s cluster nodes on port 30081
    • api.<your domain name> should be redirected to k8s cluster nodes on port 30008

Upgrading

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:

  1. If you previously deployed a Trains Server, you must first delete old deployments using the following command:

    kubectl delete -f .
    
  2. If you are upgrading from Trains Server version 0.15 or older, a data migration is required before you upgrade. First follow these data migration instructions, and then continue this upgrade.

  3. Edit the YAML file you want to update and then run following command:

    kubectl apply -f <file you edited>.yaml
    

Next Step