Skip to content

Instantly share code, notes, and snippets.

@matiasah
Last active January 2, 2023 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matiasah/0a7821585226006f8d62cea31076d4f2 to your computer and use it in GitHub Desktop.
Save matiasah/0a7821585226006f8d62cea31076d4f2 to your computer and use it in GitHub Desktop.
Install Prometheus

Install Prometheus

Install Helm Chart

Install the Prometheus Helm Charts locally.

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

Deploy Prometheus

Deploy Prometheus without mounting root volume.

  • Root Host volume will be disabled
  • This will only detect PodMonitor objects in namespaces labeled with "istio-injection"="enabled"
  • You will have to label your application namespaces with "istio-injection":"enabled"
helm install prometheus prometheus-community/kube-prometheus-stack --namespace prometheus --create-namespace --set prometheus-node-exporter.hostRootFsMount.enabled=false --set prometheus.prometheusSpec.podMonitorNamespaceSelector.matchLabels.istio-injection=enabled --set prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues=false

Deploy VirtualService

If you want to expose the Prometheus UI through Istio, deploy a VirtualService pointing to the Prometheus service.

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: prometheus
  namespace: prometheus
spec:
  gateways:
  - gateway/istio-ingressgateway
  hosts:
  - localhost
  - host.docker.internal
  http:
  - match:
    - uri:
        prefix: /prometheus/
    name: http
    rewrite:
      uri: /
    route:
    - destination:
        host: prometheus-kube-prometheus-prometheus.prometheus.svc.cluster.local
        port:
          number: 9090
        subset: http
      weight: 100
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: prometheus
  namespace: prometheus
spec:
  host: prometheus-kube-prometheus-prometheus.prometheus.svc.cluster.local
  subsets:
  - labels:
      app.kubernetes.io/instance: prometheus-kube-prometheus-prometheus
      app.kubernetes.io/managed-by: prometheus-operator
      app.kubernetes.io/name: prometheus
      app.kubernetes.io/version: 2.40.5
    name: http
  trafficPolicy:
    tls:
      mode: DISABLE

Deploy PodMonitor

Deploy a PodMonitor for your pods. https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/getting-started.md

apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: ...
  namespace: ...
spec:
  podMetricsEndpoints:
  - interval: 15s
    path: /stats/prometheus
    port: http-envoy-prom
    scheme: http
  selector:
    matchLabels:
      ...

Test a query

Enter to your prometheus URL: https:///prometheus/graph and run a query:

rate(istio_requests_total[30s])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment