Giter Site home page Giter Site logo

k8_restart_elasticsearch's Introduction

k8_restart_elasticsearch

Perform rolling restart elasticsearch cluster

Description

This implements as an automated script for the following : https://www.elastic.co/guide/en/elasticsearch/reference/current/restart-cluster.html in a kubernetes cluster. This allows for automation of the following steps:

  • check health before starting rolling restart
  • disable sharding
  • stops indexing and forces sync
  • stops node
  • checks restart
  • if mode is resize. Restart will resize the persisent volume
  • check node back in cluster
  • re-enable sharding
  • checks cluster health
  • move on to the next node and repeats the above stops

The steps ensure that the cluster is healthy at each node restart preventing corrupting the cluster ( data loss )

Requirements

Installation

The utility makes the assumption that the cluster has 2 types of nodes:

  • master
  • data

These nodes types are deployed via a statefulset es-master and es-data.

If you are enabling xpack with basic realm password and transport/http security, add 'elastic' user password in secret/currrent/secret ( elasticsearch-setup-passwords ).

vi secret/current/secret
auth_pass: xxxxxx

I automated extracting elastic password to write to secret file so it will remove the last character, so it may not work if you just add the password to the secret file.

change

auth="-u ${auth_user}:${auth_pass::${#auth_pass}-1}"
to
auth="-u ${auth_user}:${auth_pass}"
  • Copy es-util.sh to your computer
  • Edit these settings:
  initial_host=es-master-0
  master_regex='^es-master-'
  data_regex='^es-data-'
  default_regex='^es-'
  master_pvc=50Gi
  data_pvc=100Gi
  • if you desire to resize persistent volume, update and deploy the statefulset first before running utility with the updated volumeclaim size. The pattern for this is:
    • delete statefulset
    • deploy new statefulset
    • run resize script

You do not want to run 'kubectl rollout status' after 'kubectl apply' The rollout restart will not give enough time for the cluster to become healthy causing cluster corruption. Please refer the the sample wrapper script to the restart/resize script called: install-es.sh

  volumeClaimTemplates:
  - metadata:
      name: storage
    spec:
      storageClassName: encrypted-gp2
      accessModes: [ ReadWriteOnce ]
      resources:
        requests:
          storage: 50Gi

Run utility

 sh es-util.sh -m [mode] -n [namespace] -t [type: master|data] -s [http|https]
 mode: restart|enable_shard|disable_shard|get_nodes|node_status|health|resize

Note: default is https ( xpack security enabled )

examples

# restart all
sh es-util.sh -m restart -n default

# resize data
sh es-util.sh -m resize -n default -t data

# enable sharding
sh es-util.sh -m enable_shard -n default

# check health
sh es-util.sh -m health -n default

# show node status
sh es-util.sh -m node_status -n default

If the script exits abnormally, The cluster maybe unhealthy ( yellow ). Just run 'enable_shard' and give it some time to sync.

Normally it will take about 5 cycles for 'Waiting for ${pod} running status ...'. If it seems to be stuck, this maybe due to 'timeout expired waiting for volumes to attach or mount for pod'. Wait about 15 minutes, the volumeMount will eventually reset.

k8_restart_elasticsearch's People

Contributors

zippycup avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.