在上一篇文章中(https://blog.51cto.com/luosea/4769771)我们配置了本地kubectl config, 现在我们来配置port-forward.
tips:
当我们使用helm upgrade 更新后,最后会有句类似下面的提示:
helm upgrade prometheus /opt/prometheus-monitoring-qa/prometheus --namespace monitoring
NOTES:
The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster:
prometheus-server.monitoring.svc.cluster.local
Get the Prometheus server URL by running these commands in the same shell:
export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace monitoring port-forward $POD_NAME 9090
现在我们来设置端口转发:
直接将这两行命令在本地执行
export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace monitoring port-forward $POD_NAME 9090
然后在浏览器上打开 http://localhost:9090/ 应该就可以看到对应的内容了
如果我们得到的提示如下:
➜ ~ kubectl --namespace monitoring port-forward $POD_NAME 9090
error: error upgrading connection:
那就估计是pod name的问题
使用kubectl get pods -n monitoring 查看对应的pods名字
➜ ~ kubectl get pods -n monitoring
NAME READY STATUS RESTARTS AGE
alertmanager-kube-prometheus-stack-alertmanager-0 2/2 Running 0 177d
kube-prometheus-stack-grafana-dfb76888d-mrlhg 2/2 Running 0 53d
kube-prometheus-stack-kube-state-metrics-66789f8885-5c5jt 1/1 Running 6 53d
kube-prometheus-stack-operator-866999d799-5658g 1/1 Running 0 177d
kube-prometheus-stack-prometheus-node-exporter-4qnm7 1/1 Running 3 180d
kube-prometheus-stack-prometheus-node-exporter-99zvf 1/1 Running 7 180d
kube-prometheus-stack-prometheus-node-exporter-c8xg2 1/1 Running 3 180d
kube-prometheus-stack-prometheus-node-exporter-v9f9f 1/1 Running 4 180d
kube-prometheus-stack-prometheus-node-exporter-zgq8t 1/1 Running 0 180d
prometheus-blackbox-exporter-9fd56958c-xqlkw 1/1 Running 56 418d
prometheus-kube-prometheus-stack-prometheus-0 2/2 Running 1 39h
prometheus-kube-state-metrics-c65b87574-fgq75 1/1 Running 1 177d
prometheus-mysql-exporter-msqa-666c944bbc-zlmjb 1/1 Running 0 53d
prometheus-mysql-exporter-qa-664d8d7fb6-22rpt 1/1 Running 0 356d
prometheus-server-786497558b-lg49q 0/2 Terminating 0 53d
prometheus-server-786497558b-wpzfd 2/2 Running 0 24h
victoria-metrics-single-server-0 1/1 Running 0 39h
➜ ~
然后输入正确的pods
kubectl --namespace monitoring port-forward prometheus-server-786497558b-wpzfd 9090