Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document a simple Job to initialize Elasticsearch with desired API calls #3159

Open
sebgl opened this issue May 28, 2020 · 2 comments
Open
Labels
>docs Documentation

Comments

@sebgl
Copy link
Contributor

sebgl commented May 28, 2020

As a stop-gap before more features can (maybe eventually) support declarative file-based configuration (ILM, SLM, etc.), we could document a very simple Kubernetes Job that:

  1. waits until Elasticsearch is available
  2. performs a bunch of API calls
  3. exit 0 (and never runs again)
@mkretz
Copy link

mkretz commented Jun 6, 2020

I recently hit the issue of the missing support for declarative configuration. Here's the Kubernetes Job I came up with. It waits for Elasticsearch to become ready and then configures an ILM policy and an index pattern which links to the policy. Feel free to use it as an example or let me know if I should directly insert it somewhere in the docs.

apiVersion: batch/v1
kind: Job
metadata:
  name: es-config-job
spec:
  parallelism: 1
  completions: 1
  template:
    metadata:
      name: es-config-job
    spec:
      restartPolicy: Never
      initContainers:
        - name: wait-for-elasticearch
          image: alpine
          command:
            [
              "sh",
              "-c",
              "for i in $(seq 1 300); do nc -zvw1 es-es-http 9200 && exit 0 || sleep 3; done; exit 1",
            ]
      containers:
        - name: es-config-job
          image: appropriate/curl
          env:
            - name: ELASTICSEARCH_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: es-es-elastic-user
                  key: elastic
          command:
            - /bin/sh
            - -c
            - |
              curl -v -k -u elastic:$ELASTICSEARCH_PASSWORD -X PUT https://es-es-http:9200/_ilm/policy/logstash-ilm-policy?pretty -H 'Content-Type: application/json' -d '
              {
                "policy": {
                  "phases": {
                    "hot": {
                      "actions": {
                        "rollover": {
                          "max_age": "3d"
                        }
                      }
                    },
                    "delete": {
                      "min_age": "0s",
                      "actions": {
                        "delete": {}
                      }
                    }
                  }
                }
              }
              '
              curl -v -k -u elastic:$ELASTICSEARCH_PASSWORD -X PUT https://es-es-http:9200/_template/logstash_index_template?pretty -H 'Content-Type: application/json' -d '
              {
                "index_patterns": ["logstash-*"],
                "settings": {
                  "number_of_shards": 1,
                  "number_of_replicas": 1,
                  "index.lifecycle.name": "logstash-ilm-policy",
                  "index.lifecycle.rollover_alias": "logstash"
                }
              }
              '

@jketcham
Copy link

It'd be great to see an example like the one @mkretz included above somewhere in the docs, I just did something similar to setup a Snapshot repository and SLM policy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>docs Documentation
Projects
None yet
Development

No branches or pull requests

3 participants