# Minimal Prometheus: scrapes every pod labelled app=orders on /actuator/prometheus every 5 s and # keeps the namespace and pod as labels - prometheus-adapter needs both to map a series to a pod. apiVersion: v1 kind: Namespace metadata: {name: monitoring} --- apiVersion: v1 kind: ServiceAccount metadata: {name: prometheus, namespace: monitoring} --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: {name: prometheus-sd} rules: - apiGroups: [""] resources: [pods, endpoints, services] verbs: [get, list, watch] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: {name: prometheus-sd} roleRef: {apiGroup: rbac.authorization.k8s.io, kind: ClusterRole, name: prometheus-sd} subjects: [{kind: ServiceAccount, name: prometheus, namespace: monitoring}] --- apiVersion: v1 kind: ConfigMap metadata: {name: prometheus, namespace: monitoring} data: prometheus.yml: | global: scrape_interval: 5s scrape_configs: - job_name: orders metrics_path: /actuator/prometheus kubernetes_sd_configs: - role: pod namespaces: {names: [demo]} relabel_configs: - source_labels: [__meta_kubernetes_pod_label_app] regex: orders action: keep - source_labels: [__meta_kubernetes_pod_container_port_number] regex: "8080" action: keep - source_labels: [__meta_kubernetes_namespace] target_label: namespace - source_labels: [__meta_kubernetes_pod_name] target_label: pod --- apiVersion: apps/v1 kind: Deployment metadata: {name: prometheus, namespace: monitoring} spec: replicas: 1 selector: {matchLabels: {app: prometheus}} template: metadata: {labels: {app: prometheus}} spec: serviceAccountName: prometheus containers: - name: prometheus image: quay.io/prometheus/prometheus:v3.14.0 imagePullPolicy: Never args: ["--config.file=/etc/prometheus/prometheus.yml", "--storage.tsdb.retention.time=2h"] ports: [{containerPort: 9090}] resources: {requests: {cpu: 50m, memory: 128Mi}, limits: {memory: 512Mi}} volumeMounts: [{name: config, mountPath: /etc/prometheus}] volumes: [{name: config, configMap: {name: prometheus}}] --- apiVersion: v1 kind: Service metadata: {name: prometheus, namespace: monitoring} spec: selector: {app: prometheus} ports: [{port: 9090, targetPort: 9090}]