How can I restart Elasticsearch K8S deployment

12/21/2021

I deploy a Elasticsearch cluster to EKS, below is the spec

apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: elk
spec:
  version: 7.15.2
  serviceAccountName: docker-sa
  http:
    tls:
      selfSignedCertificate:
        disabled: true
  nodeSets:
  - name: node
    count: 3
    config:
  ...

I can see it has been deployed correctly and all pods are running.

$ kubectl get pods
NAME                         READY   STATUS    RESTARTS   AGE
elk-es-node-0                1/1     Running   0          19h
elk-es-node-1                1/1     Running   0          19h
elk-es-node-2                1/1     Running   0          11h

But I can't restart the deployment Elasticsearch,

$ kubectl rollout restart Elasticsearch elk-es-node
Error from server (NotFound): elasticsearches.elasticsearch.k8s.elastic.co "elk-es-node" not found

The Elasticsearch is using statefulset so I tried to restart statefulset,

$ kubectl rollout restart statefulset elk-es-node
statefulset.apps/elk-es-node restarted

the above command says restarted, but the actual pods are not restarting.

what is the right way to restart a custom kind in K8S?

-- Joey Yi Zhao
elasticsearch
kubernetes

2 Answers

12/22/2021

With ECK as the operator, you do not need to use rollout restart. Apply your updated Elasticsearch spec and the operator will perform rolling update for you. If for any reason you need to restart a pod, you use kubectl delete pod <es pod> -n <your es namespace> to remove the pod and the operator will spin up new one for you.

-- gohm&#39;c
Source: StackOverflow

12/22/2021

Use - kubectl get all

To identify if the resource created is a deployment or a statefulset - use -n <namespace"> along with the above command, if you are working in a specific namespace.

Assuming, you are using a statefulset, the issue below command to understand the properties in which it is configured.

kubectl get statefulset <statefulset-name"> -o yaml > statefulsetContent.yaml

  • this will create a yaml file names statefulsetContent.yaml in same directory.
  • you can use it to explore different options configured in the statefulset.

Check for .spec.updateStrategy in the yaml file. Based on this we can identify its update strategy.

Below is from the official documentation

There are two possible values:

  • OnDelete

When a StatefulSet's .spec.updateStrategy.type is set to OnDelete, the StatefulSet controller will not automatically update the Pods in a StatefulSet. Users must manually delete Pods to cause the controller to create new Pods that reflect modifications made to a StatefulSet's .spec.template.

  • RollingUpdate

The RollingUpdate update strategy implements automated, rolling update for the Pods in a StatefulSet. This is the default update strategy.

As a work around, you can try to scale down/up the statefulset.

kubectl scale sts <statefulset-name"> --replicas=<count">

-- sridhar
Source: StackOverflow