Swap public IP between environments

Shifting workloads between different environments – e.g. blue-green deployment – can be a painful process if you lack the right tools for the job. Thankfully Jelastic makes it easy for you to migrate a public IP, completely eliminating any DNS propagation effects and reducing downtime for this process to just a few seconds.
This feature is intended to be used by advanced users, such as within a CI/CD workflow. Therefore it is currently only available via the CLI tool or API commands:

Jelastic CLI

layershift-jelastic-cli-javaSkills required: Java-jitsu

Jelastic provides a CLI tool to simplify interacting with your account and environments.

The tool is relatively easy to use and you can install it on your local machine.

Prepare your machine

Before installing the CLI tool, you need to ensure a few things are present on your system.

If you haven’t already, install Java 1.7 or higher on your local machine. Please refer to Java installation guides for instructions on how to get Java.

If you are a Windows user, you also need Cygwin to provide you with a Unix-like environment. Mac and Linux users should skip this step.

Installing Jelastic CLI tool

To install CLI tool run the following on your command line / terminal:

curl -s ftp://ftp.jelastic.com/pub/cli/jelastic-cli-installer.sh | bash

The tool will be installed in your home directory with all commands placed in a dedicated jelastic directory.

On your first run you will be asked to provide your account details as well as Platform URL: app.j.layershift.co.uk.

More detailed information on the CLI tool is available in the Jelastic documentation.

Swap the IP

Once the CLI tool is installed, you can use it to swap the public IPs used by any nodes within or between any environments on your account.

NOTE: The swap itself is fast and should only cause a few seconds interruption to traffic, but a service restart is triggered for the following nodes:

  • GlassFish
  • PHP (Apache or Nginx)
  • Ruby (Apache or Nginx)

This command takes three parameters:

  • {env_name} – source environment name
  • {source_node_id} – node ID that you wish to move the public IP from
  • {target_node_id} – node ID that you wish to move the public IP to (can belong to a different environment)

If the target node already has a public IP, it will be moved to the source node at the same time. I.e. the public IPs of the source and target nodes will be swapped.

Private / internal IP addresses are statically assigned to a node and cannot be swapped.

NOTE: You can find node IDs in your dashboard; example marked below:

layershift-jelastic-cli-swap_ip

Once you have the details of the nodes you want to move public IP(s) between, you can do the swap using the command below:

~/jelastic/environment/control/swapextips --envName {env_name} \
    --srcnodeid {source_node_id} \
    --dstnodeid {target_node_id}

layershift-jelastic-cli-swapped_ip

You may verify the IP swap was successful by reviewing the response output, or checking the public IP assignments for each node as shown within the Jelastic dashboard.

Docker container

layershift-jelastic-cli-dockerSkills required: Inception

If you would rather not install Java on your local machine but still wish to use the Jelastic CLI tool, you can make use of Docker. Our engineers at Layershift have prepared a lightweight docker image that has java and the CLI tool pre-installed. All you have to do is to pass some variables to the image and you can use the CLI tool straight away.

To run the container, specify the following variables:

  • J_LOGIN – your Jelastic login
  • J_PASSWORD – your Jelastic password
  • J_PLATFORM – your Jelastic provider Platform URL (app.j.layershift.co.uk)

Run the image:

docker run -it --rm \
 -e "J_LOGIN=you@domain.com" \
 -e "J_PASSWORD=password" \
 -e "J_PLATFORM=hoster.url" layershift/jelastic-cli

You will enter bash shell where you will be able to use the CLI commands.

NOTE: This Docker image is intended to be run locally (not deployed onto Jelastic).

Jelastic API

layershift-jelastic-cli-api-godmodeSkills: God mode

If you are brave enough not to install Java or don’t have a way or feel the need to install Docker, you may still swap IPs using a curl command, or in fact a few API commands issued from any programming language of your choice.

NOTE: Windows users may need to install curl executable. It can be obtained from here. In the ‘Select operating system’ box, choose Win32 or Win64, depending on your architecture.

The swap IP API call is described in Jelastic API documentation.

Remember to change [hoster-api-host] to app.j.layershift.co.uk.

The method takes the following parameters:

  • session – your session key, created with signin API method.
  • envname – source environment name
  • srcnodeid – node ID that you wish to move the public IP from
  • dstnodeid – node ID that you wish to move the public IP to (can belong to a different environment)

52
2736

Need More Help?

If you're still having problems, get in touch with our 24/7 support team! We'll be more than happy to help.