1. 程式人生 > >[Istio] 外部訪問Istio自帶的Prometheus和Grafana

[Istio] 外部訪問Istio自帶的Prometheus和Grafana

Isitio目前自帶Prometheus和Grafana,但無法從外部訪問,使用port forward只能從本地訪問。執行下面的命令:

kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 &

可以從本地curl到Prometheus的UI(curl localost:9090/graph):
curl localhost:9090/graph
想從外部瀏覽器訪問到,需要將istio-demo.yaml檔案中Prometheus和Grafana的Service改成NodePort型別,然後選擇合適的nodePort:

# Source: istio/charts/prometheus/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: prometheus
  namespace: istio-system
  annotations:
    prometheus.io/scrape: 'true'
  labels:
    name: prometheus
spec:
  type: NodePort #原來是ClusterIP,改成NodePort
  selector:
    app: prometheus
  ports
: - name: http-prometheus protocol: TCP port: 9090 nodePort: 32339 #外部訪問埠 --- # Source: istio/charts/grafana/templates/service.yaml apiVersion: v1 kind: Service metadata: name: grafana namespace: istio-system annotations: auth.istio.io/3000: NONE labels: app: grafana chart: grafana-
0.1.0 release: RELEASE-NAME heritage: Tiller spec: type: NodePort #原來是沒有type的,加上 ports: - port: 3000 targetPort: 3000 protocol: TCP name: http nodePort: 32333 #加上外部訪問埠 selector: app: grafana

* nodePort要在30000到32767之間!!!!否則會報錯:

The Service "grafana" is invalid: spec.ports[0].nodePort: Invalid value: 33333: provided port is not in the valid range. The range of valid ports is 30000-32767

重新部署istio-demo.yaml檔案後、訪問對應url,就會出現Prometheus(IP:32339/graph)和Grafana(IP:32333)的UI了。
Prometheus: status/service-discovery

Prometheus: status/targets

Grafana Dashboard
UI好看是好看,就是有點卡~~主要是效能指標的監控,從k8s的Mixer拿資料。