Skip to main content

Rancher Version before 2.0

This procedure covers integrating Elastigroup with Rancher. Once completed Elastigroup will communicate with the Rancher primary to scale and manage the underlying cluster nodes.

Prerequisites

Before you start using this integration, please make sure to have:

  • An active Spot account.
  • A Rancher account with 'rancher/server:v0.46.0-rc1' version or above.

Step 1: Create an API Key Within Rancher

Rancher 1.2 or Later

  1. Spot expects an Environment API Key (and not an Account API Key). Perform the following steps to create it.
  2. Store it in a secure location.

Rancher before 1.2

  1. Login to Rancher UI.

  2. Choose API Keys from the drop-down menu on the top right corner.

  3. Create a new key and store it in a secure location.

  4. Navigate to the Infrastructure tab and click on Hosts.

  5. Add a new Host from the Custom Hosts type.

  6. Generate a command for registering a node.

  7. Follow the instructions and copy the host registration command.

Step 2: Modify the User Data

  1. Use the registration command that was generated by Rancher. It should look something like:

    sudo docker run -d --privileged -v /var/run/docker.sock:/var/run/docker.sock rancher/agent:v0.8.2 http://rancher.spotinst.com/v1/scripts/1F68A2DE49C324F22ABE:1447257600000:v4W9vNzpG3GYr0mF6o4
  2. Add this flag to label your Rancher host:

    -e CATTLE_HOST_LABELS="spotinst.instanceId=`curl http://169.254.169.254/latest/meta-data/instance-id`"

    Optionally, you can use the code below to add multiple tags to the host:

    #! /bin/bash
    sudo docker run -e CATTLE_HOST_LABELS="spotinst.instanceId=`curl http://169.254.169.254/latest/meta-data/instance-id`&tagkey=name&tagkey2=names" -d --privileged -v /var/run/docker.sock:/var/run/docker.sock rancher/agent:v0.8.2 http://rancher.domain.com:8080/v1/scripts/[token]

    If you are using RancherOS, you should use the following cloud-init script:

    #cloud-config
    write_files:
    - path: /etc/rc.local
    permissions: "0755"
    owner: root
    content: |
    #!/bin/bash
    for i in {1..20}
    do
    docker info && break
    sleep 1
    done
    #Starting the Rancher Agent
    # Setting a CATTLE_HOST_LABELS of "spotinst.instanceId" which is REQUIRED for the Spot integration to work.
    sudo docker run -d -e CATTLE_HOST_LABELS="spotinst.instanceId=`wget -qO- http://169.254.169.254/latest/meta-data/instance-id`" --privileged -v /var/run/docker.sock:/var/run/docker.sock rancher/agent:v0.8.2 http://rancher.domain.com:8080/v1/scripts/[token]

Step 3: Create an Elastigroup

  1. Create a new Elastigroup. Insert the modified script (from the previous step) to the User Data section under the compute tab.
  2. If your Amazon Image does not contain docker, add a command for installing Docker.
  3. In the 3rd party section select Rancher and enter the following:
    1. Rancher primary – Your rancher url (e.g. http://myRancher.myDomain:8080/v1)
    2. Access Key & Secret key (which you just created in the previous step above -> in Step 1)
    3. When the instances are launched you should see that they are labeled with spotinst.instanceId:
tip

For security reasons, make sure that the Rancher Primary Security-Group is open specifically for the permit-listed Spot server IP addresses.

Whenever Spot performs an instance replacement, it will automatically communicate with Rancher API to:

  • Relocate the running containers to different hosts.
  • Delete and Purge the failed hosts.