Applying a new deployment configuration: Upgrade

edit

Applying a new deployment configuration: Upgrade

edit

One of the many useful aspects of an API is that you can automate changes across a large number of deployments. Let’s say you have many deployments that are at a specific version of the Elastic Stack that need to get upgraded to the next minor release, here from version 6.5.4 to 6.6.0. You can either surreptitiously change the version of each deployments in the Cloud UI or you can automate finding all the deployments at the specific version level and upgrading them through a script.

Before you begin

edit

This example requires a deployment with an Elasticsearch cluster to work with that is not being used for anything important. If you don’t already have one, you can follow our My First Deployment example to create one.

Each version of ECE ships with some versions of the Elastic Stack, but you can add new versions as they become available. If you need to add versions before trying out this example, see Manage Elastic Stack Versions.

You can search for clusters that are at a specific version through the RESTful API or you can iterate over the JSON output from the API to get the list you need, similar to what Step 1 shows.

Steps

edit

To upgrade a cluster:

  1. Use the _search endpoint to get a list of the deployments which have Elasticsearch resources that need upgrading, here My First Deployment:

    curl -k -X POST -H "Authorization: ApiKey $ECE_API_KEY" https://$COORDINATOR_HOST:12443/api/v1/deployments/_search -H 'content-type: application/json' -d '{
    "query": {
        "nested" : {
            "path" : "resources.elasticsearch",
            "query" : {
                "bool" : {
                    "must" : [{
                        "match" : {"resources.elasticsearch.info.plan_info.current.plan.elasticsearch.version" : { "query" : "6.8.6"}}
                    }]
                }
            }
        }
     },
     "size": 100,
     "sort": [{"metadata.last_modified": { "order": "desc"}}]
    }
    '
    {
      "return_count": 1,
      "match_count": 1,
      "deployments" : [
          {
            "id" : "$DEPLOYMENT_ID",
            "name" : "My First Deployment",
            "resources" : {
    
        ...
    
              "elasticsearch": {
                "version": "6.8.6"
              },
    
        ...
    
    }
  2. For each of the deployments that you want to upgrade, make a PUT request updating the version:

    curl -k -X PUT -H "Authorization: ApiKey $ECE_API_KEY" https://$COORDINATOR_HOST:12443/api/v1/deployments/$DEPLOYMENT_ID -H 'content-type: application/json' -d '{
        "prune_orphans" : false,
        "resources":{
           "elasticsearch": [{
              "region": "ece-region",
              "ref_id": "main-elasticsearch",
              "plan":{
                  "cluster_topology": [{
                      "node_type": {
                          "master": true,
                          "data": true,
                          "ingest": true
                      },
                      "instance_configuration_id": "data.default",
                      "zone_count": 3,
                      "size": {
                          "resource": "memory",
                          "value": 4096
                      }
                  }],
                  "elasticsearch":{
                      "version": "7.5.1"
                  },
                  "deployment_template":{
                      "id": "default"
                  }
              }
          }]
       }
    }'
    DEPLOYMENT_ID
    The deployment ID for My First Deployment

    After the upgrade operation completes, the Elasticsearch resource will be at version 7.5.1.

  3. Optional: Repeat Step 1 to verify that there are no more deployments with Elasticsearch resources at the old version that need to be upgraded:

    {
      "return_count": 0,
      "match_count": 0,
      "deployments": []
    }