简体   繁体   English

GCP GKE:查看终止的作业/窗格的日志

[英]GCP GKE: View logs of terminated jobs/pods

I have a few cron jobs on GKE. 我在GKE上有一些职位。

One of the pods did terminate and now I am trying to access the logs. 其中一个Pod确实终止了,现在我正在尝试访问日志。

➣ $ kubectl get events
LAST SEEN   TYPE      REASON             KIND      MESSAGE
23m         Normal    SuccessfulCreate   Job       Created pod: virulent-angelfish-cronjob-netsuite-proservices-15622200008gc42
22m         Normal    SuccessfulDelete   Job       Deleted pod: virulent-angelfish-cronjob-netsuite-proservices-15622200008gc42
22m         Warning   DeadlineExceeded   Job       Job was active longer than specified deadline
23m         Normal    Scheduled          Pod       Successfully assigned default/virulent-angelfish-cronjob-netsuite-proservices-15622200008gc42 to staging-cluster-default-pool-4b4827bf-rpnl
23m         Normal    Pulling            Pod       pulling image "gcr.io/my-repo/myimage:v8"
23m         Normal    Pulled             Pod       Successfully pulled image "gcr.io/my-repo/my-image:v8"
23m         Normal    Created            Pod       Created container
23m         Normal    Started            Pod       Started container
22m         Normal    Killing            Pod       Killing container with id docker://virulent-angelfish-cronjob:Need to kill Pod
23m         Normal    SuccessfulCreate   CronJob   Created job virulent-angelfish-cronjob-netsuite-proservices-1562220000
22m         Normal    SawCompletedJob    CronJob   Saw completed job: virulent-angelfish-cronjob-netsuite-proservices-1562220000

So at least one CJ run. 因此,至少要进行一次CJ运行。

I would like to see the pod's logs, but there is nothing there 我想看豆荚的日志,但是那里什么也没有

➣ $ kubectl get pods
No resources found.

Given that in my cj definition, I have: 鉴于在我的cj定义中,我有:

failedJobsHistoryLimit: 1
successfulJobsHistoryLimit: 3

shouldn't at least one pod be there for me to do forensics? 我不应该至少有一个豆荚进行取证吗?

You can use the --previous flag to get the logs for the previous pod. 您可以使用--previous标志获取前一个容器的日志。

So, you can use: 因此,您可以使用:

kubectl logs --previous virulent-angelfish-cronjob-netsuite-proservices-15622200008gc42

to get the logs for the pod that was there before this one. 获取该容器之前的容器的日志。

Your pod is crashing or otherwise unhealthy 您的广告连拍崩溃或不健康

First, take a look at the logs of the current container: 首先,查看当前容器的日志:

kubectl logs ${POD_NAME} ${CONTAINER_NAME}

If your container has previously crashed, you can access the previous container's crash log with: 如果您的容器以前曾崩溃过,则可以使用以下命令访问先前容器的崩溃日志:

kubectl logs --previous ${POD_NAME} ${CONTAINER_NAME}

Alternately, you can run commands inside that container with exec: 或者,您可以使用exec在该容器内运行命令:

kubectl exec ${POD_NAME} -c ${CONTAINER_NAME} -- ${CMD} ${ARG1} ${ARG2} ... ${ARGN}

Note: -c ${CONTAINER_NAME} is optional. 注意: -c ${CONTAINER_NAME}是可选的。 You can omit it for pods that only contain a single container. 您可以为仅包含一个容器的Pod忽略它。

As an example, to look at the logs from a running Cassandra pod, you might run: 例如,要查看正在运行的Cassandra容器中的日志,可以运行:

kubectl exec cassandra -- cat /var/log/cassandra/system.log

If none of these approaches work, you can find the host machine that the pod is running on and SSH into that host. 如果这些方法都不起作用,则可以找到运行Pod的主机,并通过SSH进入该主机。

Finaly, check Logging on Google StackDriver. 最后,选中“在Google StackDriver上登录”。

Debugging Pods 调试豆荚

The first step in debugging a pod is taking a look at it. 调试Pod的第一步就是看一下它。 Check the current state of the pod and recent events with the following command: 使用以下命令检查窗格的当前状态和最近的事件:

kubectl describe pods ${POD_NAME}

Look at the state of the containers in the pod. 查看容器中容器的状态。 Are they all Running? 他们都在跑步吗? Have there been recent restarts? 最近有重新启动吗?

Continue debugging depending on the state of the pods. 根据Pod的状态继续调试。

Debugging ReplicationControllers 调试ReplicationController

ReplicationControllers are fairly straightforward. ReplicationControllers非常简单。 They can either create pods or they can't. 他们可以创建吊舱,也不能创建吊舱。 If they can't create pods, then please refer to the instructions above to debug your pods. 如果他们无法创建Pod,请参考上面的说明调试Pod。

You can also use kubectl describe rc ${CONTROLLER_NAME} to inspect events related to the replication controller. 您还可以使用kubectl describe rc ${CONTROLLER_NAME}来检查与复制控制器相关的事件。

Hope it helps you to find exactly problem. 希望它可以帮助您找到确切的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM