question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[elasticsearch] recommended method to automate an api call (e.g. ILM) post deployment?

See original GitHub issue

This is helm related so I am not asking in the ES forum.

I would like to automate the following api call:

PUT _template/my_template
{
  "index_patterns": [
    "logstash-*"
  ],
  "settings": {
    "number_of_shards": 8,
    "number_of_replicas": 1
  }
}

I am trying with these values in the helm chart, essentially the idea is to wait until the ES cluster has started (relies heavily on health check mechanism that creates the “start file”)… is this a recommended approach?

lifecycle:
  postStart:
    exec:
      command:
        - sh
        - -c
        - |
          #!/bin/sh
          # Add a template to adjust number of shards/replicas
          TEMPLATE_NAME=my_template
          START_FILE=/tmp/.es_start_file
          INDEX_PATTERN="logstash-*"
          SHARD_COUNT=8
          REPLICA_COUNT=1
          while [ ! -f ${START_FILE} ]; do
            sleep 1
          done
          curl -XPUT "http://localhost:9200/_template/$TEMPLATE_NAME" -H 'Content-Type: application/json' -d'{"index_patterns":['"$INDEX_PATTERN"'],"settings":{"number_of_shards":'$SHARD_COUNT',"number_of_replicas":'$REPLICA_COUNT'}}'

FWIW have not gotten it to work yet, pod remains in Initialization phase:

elasticsearch-master-2                   0/1     PodInitializing   0          12m8s

But let me know if I am on the right track please.

cc @jmlrt @Crazybus would love to get your input.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pbecottecommented, Jan 14, 2020

https://helm.sh/docs/topics/charts_hooks/

Helm hooks are the best way to do this IMO, but these helm charts dont have any extension point built in for it.

edit- sorry, didn’t realize you were running from the ES pod

In your wait loop, instead of waiting for that file, wait for the api to return a 200 before you issue the PUT command- I’d guess its a race condition.

https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/#discussion

0reactions
naseemkullahcommented, Jan 14, 2020

Thanks @pbecotte,

I like the idea of removing the dependency on that file, so I’ve tried:

lifecycle:
  postStart:
    exec:
      command:
        - bash
        - -c
        - |
          #!/bin/bash
          # Add a template to adjust number of shards/replicas
          TEMPLATE_NAME=my_template3
          INDEX_PATTERN="logstash3-*"
          SHARD_COUNT=8
          REPLICA_COUNT=1
          ES_URL=http://localhost:9200
          while [[ "$(curl -s -o /dev/null -w '%{http_code}\n' $ES_URL)" != "200" ]]; do sleep 1; done
          curl -XPUT "$ES_URL/_template/$TEMPLATE_NAME" -H 'Content-Type: application/json' -d'{"index_patterns":['\""$INDEX_PATTERN"\"'],"settings":{"number_of_shards":'$SHARD_COUNT',"number_of_replicas":'$REPLICA_COUNT'}}'

Which seems like a sufficient solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutorial: Automate rollover with ILM | Elasticsearch Guide [8.5]
To automate rollover and management of a data stream with ILM, you: ... For example, the following request creates the timeseries data stream...
Read more >
REST APIs | Elasticsearch Guide [8.5] | Elastic
Elasticsearch exposes REST APIs that are used by the UI components and can be called directly to configure and access Elasticsearch features.
Read more >
Create or update lifecycle policy API | Elasticsearch Guide [8.5]
ILM performs operations as the user who last updated the policy. ILM only has the roles assigned to the user at the time...
Read more >
API calls | Elastic Cloud Enterprise Reference [3.5]
You use these four request methods to communicate with the Elastic Cloud Enterprise RESTful API: To fetch information: GET; To add new information:...
Read more >
Rollover API | Elasticsearch Guide [master] | Elastic
We recommend using ILM's rollover action to automate rollovers. ... For example, if you roll over an alias with a current index of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found