kubernetes - 如何使用 kubectl 或 Web UI 登录 prometheus pod
问题描述
我正在使用 prometheus(v2.16.0) 来抓取指标数据,现在我想登录 prometheus pod 检查配置文件路径:
~/Library/Mobile Documents/com~apple~CloudDocs/Document/k8s/work/kubernetes/cluster/addons/prometheus ⌚ 20:29:57
$ kubectl exec -it prometheus-0 -n kube-system /bin/bash
Defaulting container name to prometheus-server-configmap-reload.
Use 'kubectl describe pod/prometheus-0 -n kube-system' to see all of the containers in this pod.
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown
command terminated with exit code 126
~/Library/Mobile Documents/com~apple~CloudDocs/Document/k8s/work/kubernetes/cluster/addons/prometheus ⌚ 20:30:10
$ kubectl exec -it prometheus-0 -n kube-system /bin/ash
Defaulting container name to prometheus-server-configmap-reload.
Use 'kubectl describe pod/prometheus-0 -n kube-system' to see all of the containers in this pod.
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"/bin/ash\": stat /bin/ash: no such file or directory": unknown
command terminated with exit code 126
~/Library/Mobile Documents/com~apple~CloudDocs/Document/k8s/work/kubernetes/cluster/addons/prometheus ⌚ 20:31:30
$ kubectl exec -it prometheus-0 -n kube-system /bash
Defaulting container name to prometheus-server-configmap-reload.
Use 'kubectl describe pod/prometheus-0 -n kube-system' to see all of the containers in this pod.
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"/bash\": stat /bash: no such file or directory": unknown
command terminated with exit code 126
显然我无法登录 prometheus pod,我正在尝试另一种使用 Web UI 登录的方式:
可以像这样登录pod吗?为什么我无法登录 prometheus pod?
解决方案
正如它在输出中所说:
Defaulting container name to prometheus-server-configmap-reload.
这意味着在 pod 中有多个容器,它会自动选择prometheus-server-configmap-reload
. 这可能不是我们想要访问的容器。
那么访问prometheus bash命令行的正确方法:
- 列出 pod 中的容器:
kubectl get pods prometheus-0 -n kube-system -o jsonpath='{.spec.containers[*].name}*
- 从上面的列表中执行到正确的容器中,使用:
kubectl exec --namespace <namespace> -it <pod_name> -c <container> /bin/ash
在某些情况下,命令之前还需要有双斜杠:
kubectl exec -it -n prometheus-0 -c prometheus //bin/bash
/bin/sh
如果//bin/sh
bash 在容器映像中不可用,您也可以尝试。
希望能帮助到你。
推荐阅读
- apache-spark-sql - 使用 oozie 操作执行 spark sql 作业的问题
- javascript - 切片数组的单列
- c++ - Arduino字符串解析问题
- node.js - 如何使用 amp-list、amp-mustache、amp-form 和 amp-bind 实现自动建议?
- ios - 容器视图的 collectionVC 被父级的 tapGesture 识别器阻止
- php - PHP构建带有id的html表
- r - 如何根据 R 中定义的列中缺失值的数量返回行值的总和?
- docker - MSBuild webdeploy 包输出 zip 文件不可访问
- karate - Overwrite path already set in Background
- mysql - 在 mysql 查询中包含批发字段