第 12 章 手动滚动部署 Elasticsearch

OpenShift Container Platform 支持 Elasticsearch 集群滚动重启。滚动重启可以在不需要 Elasticsearch 集群下线的情况下,将适用的更改应用到 Elasticsearch 集群(这需要已配置了三个 master)。Elasticsearch 集群保持联机和可运行状态,节点则逐一脱机。

12.1. 执行 Elasticsearch 集群滚动重启

在更改 elasticsearch ConfigMap 或任何 elasticsearch-* 部署配置时,执行滚动重启。

此外,如果运行 Elasticsearch Pod 的节点需要重启,则建议滚动重启。

先决条件

  • 必须安装 Cluster Logging 和 Elasticsearch。

流程

执行集群滚动重启:

  1. 进入 openshift-logging 项目:

    $ oc project openshift-logging
  2. 使用以下命令,从 Elasticsearch 提取 CA 证书并写入到 admin-ca 文件:

    $ oc extract secret/elasticsearch --to=. --keys=admin-ca
    
    admin-ca
  3. 执行分片同步刷新,确保在关机之前没有等待写入磁盘的待定操作:

    $ oc exec <any_es_pod_in_the_cluster> -c elasticsearch -- curl -s --cacert /etc/elasticsearch/secret/admin-ca --cert /etc/elasticsearch/secret/admin-cert --key /etc/elasticsearch/secret/admin-key -XPOST 'https://localhost:9200/_flush/synced'

    例如:

    oc exec -c elasticsearch-cdm-5ceex6ts-1-dcd6c4c7c-jpw6 -- curl -s --cacert /etc/elasticsearch/secret/admin-ca --cert /etc/elasticsearch/secret/admin-cert --key /etc/elasticsearch/secret/admin-key -XPOST 'https://localhost:9200/_flush/synced'
  4. 使用 OpenShift Container Platform es_util 工具防止在有意关闭节点时进行分片平衡:

    $ oc exec <any_es_pod_in_the_cluster> -c elasticsearch -- es_util --query=_cluster/settings -XPUT 'https://localhost:9200/_cluster/settings' -d '{ "transient": { "cluster.routing.allocation.enable" : "none" } }'

    例如:

    $ oc exec elasticsearch-cdm-5ceex6ts-1-dcd6c4c7c-jpw6 -c elasticsearch -- es_util --query=_cluster/settings?pretty=true -XPUT 'https://localhost:9200/_cluster/settings' -d '{ "transient": { "cluster.routing.allocation.enable" : "none" } }'
    
    {
      "acknowledged" : true,
      "persistent" : { },
      "transient" : {
        "cluster" : {
          "routing" : {
            "allocation" : {
              "enable" : "none"
            }
          }
        }
      }
  5. 完成后,会在每个部署中都有一个 ES 集群:

    1. 默认情况下,OpenShift Container Platform Elasticsearch 集群会阻止向其节点推出部署。使用以下命令来允许推出部署并允许 Pod 获取更改:

      $ oc rollout resume deployment/<deployment-name>

      例如:

      $ oc rollout resume deployment/elasticsearch-cdm-0-1
      deployment.extensions/elasticsearch-cdm-0-1 resumed

      部署了一个新 Pod。当 Pod 具有就绪的容器后,就能继续进行下一部署。

      $ oc get pods | grep elasticsearch-*
      
      NAME                                            READY   STATUS    RESTARTS   AGE
      elasticsearch-cdm-5ceex6ts-1-dcd6c4c7c-jpw6k    2/2     Running   0          22h
      elasticsearch-cdm-5ceex6ts-2-f799564cb-l9mj7    2/2     Running   0          22h
      elasticsearch-cdm-5ceex6ts-3-585968dc68-k7kjr   2/2     Running   0          22h
    2. 完成后,重置 Pod 以禁止推出部署:

      $ oc rollout pause deployment/<deployment-name>

      例如:

      $ oc rollout pause deployment/elasticsearch-cdm-0-1
      
      deployment.extensions/elasticsearch-cdm-0-1 paused
    3. 检查 Elasticsearch 集群是否处于 green 状态:

      $ oc exec <any_es_pod_in_the_cluster> -c elasticsearch -- es_util --query=_cluster/health?pretty=true
      注意

      如果您对先前命令中使用的 Elasticsearch Pod 执行了推出部署,该 Pod 将不再存在,并且此处需要使用新的 Pod 名称。

      例如:

      $ oc exec elasticsearch-cdm-5ceex6ts-1-dcd6c4c7c-jpw6 -c elasticsearch -- es_util --query=_cluster/health?pretty=true
      
      {
        "cluster_name" : "elasticsearch",
        "status" : "green", 1
        "timed_out" : false,
        "number_of_nodes" : 3,
        "number_of_data_nodes" : 3,
        "active_primary_shards" : 8,
        "active_shards" : 16,
        "relocating_shards" : 0,
        "initializing_shards" : 0,
        "unassigned_shards" : 1,
        "delayed_unassigned_shards" : 0,
        "number_of_pending_tasks" : 0,
        "number_of_in_flight_fetch" : 0,
        "task_max_waiting_in_queue_millis" : 0,
        "active_shards_percent_as_number" : 100.0
      }
      1
      在继续操作之前,请确保此参数为 green
  6. 如果更改了 Elasticsearch 配置映射,请对每个 Elasticsearch Pod 重复这些步骤。
  7. 推出集群的所有部署后,重新启用分片平衡:

    $ oc exec <any_es_pod_in_the_cluster> -c elasticsearch -- es_util --query=_cluster/settings -XPUT 'https://localhost:9200/_cluster/settings' -d '{ "transient": { "cluster.routing.allocation.enable" : "none" } }'

    例如:

    $ oc exec elasticsearch-cdm-5ceex6ts-1-dcd6c4c7c-jpw6 -c elasticsearch -- es_util --query=_cluster/settings?pretty=true -XPUT 'https://localhost:9200/_cluster/settings' -d '{ "transient": { "cluster.routing.allocation.enable" : "all" } }'
    
    {
      "acknowledged" : true,
      "persistent" : { },
      "transient" : {
        "cluster" : {
          "routing" : {
            "allocation" : {
              "enable" : "all"
            }
          }
        }
      }
    }