首页 > 解决方案 > 未成功初始化的 SSH kubernetes pod

问题描述

我正在尝试调试未初始化的 jenkins kubernetes pod。pod 处于初始化状态。

一旦我跑kubectl get pods --all-namespaces | grep jenkins

我正进入(状态

infrastructure jenkins-fdfc9cf6c-2tvvm 0/1 Init:0/1 0 4m

我可以使用提取日志

kubectl logs jenkins-fdfc9cf6c-2tvvm -c copy-default-config -n infrastructure

有什么方法可以让我真正通过 SSH 连接到这个 pod?

我试过kubectl -n infrastructure exec -it jenkins-fdfc9cf6c-2tvvm /bin/bash了,但我得到了错误error: unable to upgrade connection: container not found ("jenkins")

这就是我的容器状态的样子

  containerStatuses:
  - image: jenkins/jenkins:lts
    imageID: ""
    lastState: {}
    name: jenkins
    ready: false
    restartCount: 0
    state:
      waiting:
        reason: PodInitializing

任何建议如何做到这一点?

标签: kubernetes

解决方案


我认为您不能运行未初始化的 pod 的 bash。但是您可以先使用sleep命令启动 pod,然后运行kubectl exec命令来运行该 pod 的 bash。

apiVersion: v1
kind: Pod
...
spec:
  containers:
  - name: ***
    image: ***
    command: ["sleep 3600"]

通过这样做,pod 将不会真正运行 docker 的命令,而是会正确初始化。然后您可以运行kubectl exec -it -n infrastructure jenkins-fdfc9cf6c-2tvvm /bin/bash以访问该 pod 的 bash,然后手动运行原始命令,看看会发生什么。


推荐阅读