我在Virtual Box之上的本地机器上创建了一个Minikube实例。我有几个复制控制器,为这两个控制器指定了资源限制。首先,我为每个复制控制器 A 和 B 创建了一个实例。然后我将 rc B 的复制计数增加到 6。一旦它被扩展,我可以看到 rc A 创建的 Pod 被 Kubernetes 杀死了。我只能在 kubeclt 日志中看到的日志是
/opt/app-server/bin/app-server.sh: line 159: 28 Killed $JAVA_HOME/bin/java -server $JVM_OPTS $XDEBUG $SERVER_OPTS -Djava.endorsed.dirs=$SERVER_ENDORSED -classpath $SERVER_CLASSPATH org.adroitlogic.appserver.AppServer
我不知道是什么原因导致这个豆荚被驱逐。我猜这与 Pod 的资源分配和 VM 上的有限资源有关。但我需要确认这一点。在哪里可以找到与此容器逐出原因相关的日志?我在journalctl -u localkube中搜索
Jan 09 11:00:55 minikube localkube[3421]: I0109 11:00:55.136114 3421 docker_manager.go:2524] checking backoff for container "ipsweb" in pod "ipsweb-m3234"
Jan 09 11:00:55 minikube localkube[3421]: I0109 11:00:55.136525 3421 docker_manager.go:2538] Back-off 5m0s restarting failed container=ipsweb pod=ipsweb-m3234_default(e6961157-d650-11e6-8bee-080027bc9720)
Jan 09 11:00:55 minikube localkube[3421]: E0109 11:00:55.136571 3421 pod_workers.go:184] Error syncing pod e6961157-d650-11e6-8bee-080027bc9720, skipping: failed to "StartContainer" for "ipsweb" with CrashLoopBackOff: "Back-off 5m0s restarting failed container=ipsweb pod=ipsweb-m3234_default(e6961157-d650-11e6-8bee-080027bc9720)"
Kubectl 描述 pod 给出以下事件
Events:
FirstSeen LastSeen Count From SubobjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
1h 1h 1 {kubelet minikube} spec.containers{ipsweb} Normal Started Started container with docker id 2ca5ccaa11a1
1h 1h 1 {kubelet minikube} spec.containers{ipsweb} Normal Created Created container with docker id 2ca5ccaa11a1; Security:[seccomp=unconfined]
1h 1h 1 {kubelet minikube} spec.containers{ipsweb} Normal Started Started container with docker id 86d4bdfa014e
1h 1h 1 {kubelet minikube} spec.containers{ipsweb} Normal Created Created container with docker id 86d4bdfa014e; Security:[seccomp=unconfined]
50m 50m 1 {kubelet minikube} spec.containers{ipsweb} Normal Started Started container with docker id a570e4f59e96
50m 50m 1 {kubelet minikube} spec.containers{ipsweb} Normal Created Created container with docker id a570e4f59e96; Security:[seccomp=unconfined]
1h 49m 2 {kubelet minikube} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "ipsweb" with CrashLoopBackOff: "Back-off 10s restarting failed container=ipsweb pod=ipsweb-m3234_default(e6961157-d650-11e6-8bee-080027bc9720)"
49m 49m 1 {kubelet minikube} spec.containers{ipsweb} Normal Started Started container with docker id b91cc20a8bb3
49m 49m 1 {kubelet minikube} spec.containers{ipsweb} Normal Created Created container with docker id b91cc20a8bb3; Security:[seccomp=unconfined]
1h 48m 4 {kubelet minikube} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "ipsweb" with CrashLoopBackOff: "Back-off 20s restarting failed container=ipsweb pod=ipsweb-m3234_default(e6961157-d650-11e6-8bee-080027bc9720)"
48m 48m 1 {kubelet minikube} spec.containers{ipsweb} Normal Started Started container with docker id cf24faa31718
48m 48m 1 {kubelet minikube} spec.containers{ipsweb} Normal Created Created container with docker id cf24faa31718; Security:[seccomp=unconfined]
1h 46m 7 {kubelet minikube} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "ipsweb" with CrashLoopBackOff: "Back-off 40s restarting failed container=ipsweb pod=ipsweb-m3234_default(e6961157-d650-11e6-8bee-080027bc9720)"
但以上都不是给我一个关于原因以及为什么会发生这种情况的提示。有什么建议吗?
所以我不知道正确的方法是什么,但当 k8s 无法给我足够的信息时,我会这样做。
最简单的方法是查看该豆荚的docker logs
。我看到某个 pod 一次又一次地失败。所以我会去迷你库贝机器并运行
docker ps -a | grep 'some_identifiable_name'
这是我获取容器 ID 的地方。一旦我有了它,我就会得到那个 pod 的日志。
docker logs <id_found_above>
这应该如此迅速地完成,因为 k8s 可能会在您执行上述所有步骤之前对容器进行垃圾回收。
要以简单的方式获取每个 pod 的日志,请运行以下命令,
$ minikube dashboard
然后kubernetes
仪表板将在您的浏览器中打开。 然后转到 Pods
,在"容器"选项卡下,将有选项View logs
,您可以从中实际查看容器内部发生了什么或失败的原因