Kubernetes 如何使用kubectl或web UI登录普罗米修斯吊舱

Kubernetes 如何使用kubectl或web UI登录普罗米修斯吊舱,kubernetes,Kubernetes,我正在使用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 con

我正在使用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
显然,我无法登录到普罗米修斯吊舱,我正在尝试另一种使用Web UI登录的方式:


可以这样登录pod吗?为什么我不能登录普罗米修斯吊舱

如输出中所述:

Defaulting container name to prometheus-server-configmap-reload.
这意味着pod中有多个容器,它会自动选择prometheus服务器configmap reload。这可能不是我们想要访问的容器


因此,访问prometheus bash命令行的正确方法是:

  • 列出pod中的容器:
  • 使用以下命令将Exec从上面的列表中插入到正确的容器中:
  • 如果bash在容器映像中不可用,您也可以尝试
    /bin/sh
    /bin/sh

    希望能有帮助

    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