Deploy NetScaler CPX in a Mesos and Marathon Environment

In this deployment, you can use a Mesos and Marathon environment to launch and scale up or scale down your applications. Mesos enables resource isolation and sharing across distributed applications or frameworks. Marathon is an application orchestration framework that can launch and scale up or scale down your applications. For more information about Mesos and Marathon, see https://docs.mesosphere.com/gettingstarted/overview/.

To deploy NetScaler CPX in a Mesos and Marathon environment, you must complete the following tasks:

  1. Set up a Mesos and Marathon master-slave cluster. Every application and NetScaler CPX instance must be configured on an Ubuntu host and these hosts must be configured as Mesos slaves. You must configure an Ubuntu host as a Mesos master and install Marathon on the Mesos master. For more information, see https://open.mesosphere.com/getting-started/install/.
  2. You must store the images of your applications and NetScaler CPX instances on all the Mesos slaves.
  3. You can then launch your applications and NetScaler CPX instances by using either the Marathon CLI, or the Marathon GUI. Note that Marathon launches a NetScaler CPX instance as an application. For more information about running applications on Marathon, see https://mesosphere.github.io/marathon/docs/application-basics.html.

The following figure illustrates the deployment of NetScaler CPX in Mesos and Marathon environment.

localized image

In this example, UH1 is an Ubuntu host that is configured as a Mesos master. Ubuntu hosts UH2, UH3, and UH4 are configured as Mesos slaves. Marathon is installed on the Mesos master. App1 and App2 are the applications that you want your NetScaler CPX to load balance. To launch applications, the Mesos master allocates a Mesos slave and other resources to the applications, and then Marathon launches the applications on the allocated Mesos slaves. In this example, CPX, App1, and App2 are launched on Ubuntu hosts UH2, UH3, and UH4 respectively.

You can launch your applications and NetScaler CPX instances by using either the Marathon CLI, or the Marathon GUI.

Launching Applications and NetScaler CPX instances by using the Marathon CLI

To launch an application or a NetScaler CPX instance, you must write JSON scripts. The JSON scripts must include details such as ID, number of instances, container type, application image file names, port mappings, network, labels, and health check specifications. You must then run the JSON scripts on the Mesos master to launch the applications and NetScaler CPX instances.

To launch an application and NetScaler CPX instance:

  1. Write a JSON script for every application and NetScaler CPX instance you want to launch.

    For example, to launch an application, write a JSON script as shown in the following sample script:

        {
          "id": "web-backend",
          "cpus": 0.1,
          "mem": 100.0,
          "instances": 2,
          "container": {
            "type": "DOCKER",
            "docker": {
              "image": "nginx_backend:latest",
              "forcePullImage": false,
              "network": "BRIDGE",
              "portMappings": [
                { "containerPort": 80, "hostPort": 0, "servicePort": 20002, "protocol": "tcp" }
              ]
            }
          },
          "labels": {
                  "NETSCALER_GROUP":"BACKEND"
          },
          "healthChecks": [
            {
              "protocol": "HTTP",
              "portIndex": 0,
              "path": "/",
              "gracePeriodSeconds": 5,
              "intervalSeconds": 20,
              "maxConsecutiveFailures": 3
            }
          ]
        }
    

    Note

    Make sure that, for an application, you do not set the label as NETSCALER_CPX. If you set the label parameter to NETSCALER_CPX for an application, you cannot configure that application on your NetScaler CPX instance.

    For example, to launch a NetScaler CPX instance, write a JSON script as shown in the following sample script:

        {
          "id": "cpx",
          "cpus": 0.25,
          "mem": 512,
          "instances": 2,
          "container": {
            "type": "DOCKER",
            "docker": {
              "image": "cpx:10.5-53.535",
              "network": "HOST",
              "privileged": true,
              "parameters": [
                { "key": "tty", "value": "true" },
                { "key": "env", "value": "NS_NETMODE=HOST" },
                { "key": "env", "value": "NETSCALER_GROUP=BACKEND" },
                { "key": "env", "value": "marathon_url=http://10.102.103.222:8080" }
              ]
            }
          },
          "labels": {
                  "NETSCALER_AS_APP": "true"
          }
        }
    

    Note

    In a Mesos and Marathon environment, support is available to run the NetScaler CPX instance in only the host networking mode. Therefore, in the JSON script, you must set the value of the network parameter to HOST.

  2. On the Mesos master, run the following command to execute the JSON script:

    curl -X POST http://<Marathon_IP_Address>:<Marathon port>/v2/apps -d @<JSON_Script_Name>.json -H "Content-type: application/json"
    

    Alternatively, you can start the NetScaler CPX instance by using the following docker run command:

    docker run -dt --privileged=true --net=host -e NS_NETMODE="HOST" --ulimit core=-1 -e marathon_url=“http://<Marathon_IP_Address>:<Marathon port>" cpx:7
    

    If Marathon needs authentication, you can use the following docker run command:

    docker run -dt --privileged=true --net=host -e NS_NETMODE="HOST" --ulimit core=-1 marathon_url=“http://<Marathon_IP_Address>:<Marathon port>" –e marathon_user=abcd –e marathon_password=secret cpx:7
    

Launching Applications and NetScaler CPX instances by using the Marathon GUI

You can access the Marathon GUI by typing the Marathon IP address and port in a browser. By default, the Marathon port is 8080.

To launch an application and NetScaler CPX instance:

  1. Log on to the Marathon GUI.

  2. On the Applications tab, in the top-left pane, click Create.

  3. In the New Application screen, specify the parameters in the Docker container settings, Environment variables, Labels, Health checks, and Optional settings sections.

    Note

    In a Mesos and Marathon environment, support is available to run the NetScaler CPX instance in only the host networking mode. Therefore, if you are launching a NetScaler CPX instance, in the Docker container settings section, in the Network list, select Host.

    localized image

  4. Click + Create.

  5. The applications that you have launched are displayed under Applications.

    localized image