how to check restart reason of stateful set in kubernetes cluster

3/4/2020

I am deploy a elasticsearch cluster in kubernetes,now the cluster pod restart for many times.For elasticsearch cluster stable,I want to find out why the cluster restart.Now I check the restart pods log it only shows the restarted log output,but the restarted log is no errors,I try to set the cluster not start automatic and I could see the error output on fail,It shows:

StatefulSet.apps "es-cluster" is invalid: spec.template.spec.restartPolicy: Unsupported value: "Never": supported values: "Always"

so which is the best way to find out why the pods restart?

enter image description here

-- Dolphin
elasticsearch
kubernetes

2 Answers

3/4/2020

To get a detailed view of the log snipper or immediate reasons for startup failures of a pod, run

kubectl describe pod <pod> -n <namespace>

Ideally you should run it as soon as a pod restarts (or you can force it by deleting the pod). This can/should be done in addition to the above comment that suggests tailing the logs, up to the moment when the pods fail to start. Be mindful that if there are multiple containers in a pod you may also need to

kubectl logs -f <pod> -n <namespace> -c <container name> --previous

Cheers

-- Andrei Dascalu
Source: StackOverflow

3/4/2020

To get the log of restarted pod run

kubectl logs -f <pod> -n <namespace> --previous

-- hoque
Source: StackOverflow