我在 google 容器引擎中有一个单节点 kubernetes 集群可以玩。
现在,我托管的一个小型个人网站已经离线了几分钟。当我查看容器的日志时,我看到最近完成的正常启动序列,因此我假设一个容器死亡(或被杀死?)并重新启动。
我怎样才能弄清楚发生这种情况的方式和原因?
有没有办法在容器意外启动/停止时收到警报?
小智 13
我按照以下步骤来定义失败的原因:
# print out a pod logs (https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#logs)
kubectl logs {name_of_pod} -n {namespace} --since=2h --timestamps
# print the logs for the _previous_ instance of the container in a pod if it exists
kubectl logs -p {name_of_pod} -n {namespace} --previous
# check events (https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#describe)
kubectl describe pod {pod_name} -n {namespace}
# look at the 'Events' at the end of the output
# ..
# Events:
# Type Reason Age From Message
# ---- ------ ---- ---- -------
# Warning BackOff 40m kubelet, gke-xx Back-off restarting failed container
# ..
# observe all events (https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#get)
kubectl get events -n {namespace} --sort-by=.metadata.creationTimestamp
# check logs, etc. in pod container (https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec)
kubectl exec -it {pod_name} -n {namespace} -- sh
Run Code Online (Sandbox Code Playgroud)
小智 8
kubectl get pods 实际上会列出容器的任何重新启动,而且 describe 命令可能会有所帮助,因为它会列出与 pod 相关的所有事件。
此外,钩子可以配置为在容器生命周期中的特定时间点在容器中使用 检查here
https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
归档时间: |
|
查看次数: |
54707 次 |
最近记录: |