有没有办法将SSH(exec)连接到Kubernetes Jenkins从属pod中进行调试?



在我的 Jenkinsfile 中出错后,那个从属代理 pod 似乎总是死去并很快消失。有没有办法在我身处其中时执行它并保持它活着?我正在使用 Helm 在 Kubernetes 上运行 Jenkins

如果 pod 已经死了,则无法kubectl exec容器中。

但是,您可以直接通过 ssh 连接到运行 Pod 的节点,并直接检查(现已停止的(容器。(一旦它停止,你就无法docker exec它(

像这样:

# this pod will die pretty quickly
$ kubectl run --restart=Never --image=busybox deadpod -- sh -c "echo quick death | tee /artifact"
pod "deadpod" created
$ kubectl describe pod deadpod
Name:           deadpod
Namespace:      default
Node:           nodexxx/10.240.0.yyy
Containers:
deadpod:
Container ID: docker://zzzzzzzzz
[...]
$ ssh nodexxx

一旦你ssh进入节点,你有几个调试选项。

获取输出:

nodexxx:~# docker logs zzzz
quick death

检查文件系统:

nodexxx:~# mkdir debug; cd debug
nodexxx:~/debug# docker export zzz | tar xv
[...]
nodexxx:~/debug# ls -l; cat artifact
[...]
quick death

从容器创建映像,创建新容器并获取 shell:

nodexxx:~# docker commit zzzz debug
nodexxx:~# docker run -it zzzz sh
/ # cat /artifact
quick death

最新更新