kubernetes - 未成功初始化的 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
任何建议如何做到这一点?
解决方案
我认为您不能运行未初始化的 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,然后手动运行原始命令,看看会发生什么。
推荐阅读
- html - Angular - 异步服务器调用正在更新画布上下文,但画布视图未更新
- python - 如何在没有 root 权限的情况下设置我的机器人框架开发环境?
- azure - 将日志文件发送到 Azure Monitor
- scala - 如何在 Scala 中提供静态 HTML 文件?
- json - Django模板如何使用标签和模板过滤器从json dict中获取数据
- c# - 正确的值不是来自 web.config 文件
- javascript - 如何修复“CheckBoxData []类型上不存在属性'值'”?
- spring-boot - 如何为lamda表达式编写junits
- python-3.x - 使用 nunique 标记数据框中的重复值但出现错误
- amazon-web-services - 为什么 AWS Glue 工作有时似乎在工作中使用较少的执行者