Replace manual Prometheus with kube-prometheus-stack Helm chart
This commit is contained in:
@@ -12,6 +12,6 @@ data:
|
||||
- name: Prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: http://prometheus.monitoring.svc.cluster.local:9090
|
||||
url: http://prometheus-operated.monitoring.svc.cluster.local:9090
|
||||
isDefault: true
|
||||
editable: true
|
||||
@@ -22,6 +22,9 @@ spec:
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 3000
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: grafana-db-secret
|
||||
env:
|
||||
- name: GF_SECURITY_ADMIN_USER
|
||||
valueFrom:
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: prometheus-config
|
||||
namespace: monitoring
|
||||
data:
|
||||
prometheus.yml: |
|
||||
global:
|
||||
scrape_interval: 15s
|
||||
evaluation_interval: 15s
|
||||
|
||||
rule_files:
|
||||
- /etc/prometheus/rules/*.yml
|
||||
|
||||
scrape_configs:
|
||||
- job_name: "prometheus"
|
||||
static_configs:
|
||||
- targets: ["localhost:9090"]
|
||||
|
||||
- job_name: "kubernetes-node-exporters"
|
||||
kubernetes_sd_configs:
|
||||
- role: endpoints
|
||||
relabel_configs:
|
||||
- source_labels: [__meta_kubernetes_endpoints_name]
|
||||
regex: ".*node-exporter.*"
|
||||
action: keep
|
||||
- source_labels: [__meta_kubernetes_endpoint_address_target_port]
|
||||
action: replace
|
||||
target_label: __port__
|
||||
- source_labels: [__address__]
|
||||
regex: "(.*):.*"
|
||||
replacement: "$1:9100"
|
||||
target_label: __address__
|
||||
|
||||
- job_name: "kubernetes-service-endpoints"
|
||||
kubernetes_sd_configs:
|
||||
- role: endpoints
|
||||
relabel_configs:
|
||||
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
|
||||
action: keep
|
||||
regex: "true"
|
||||
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
|
||||
action: replace
|
||||
target_label: __metrics_path__
|
||||
regex: (.+)
|
||||
- source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
|
||||
action: replace
|
||||
target_label: __address__
|
||||
regex: ([^:]+)(?::\d+)?;(\d+)
|
||||
replacement: $1:$2
|
||||
- source_labels: [__meta_kubernetes_namespace]
|
||||
action: replace
|
||||
target_label: namespace
|
||||
- source_labels: [__meta_kubernetes_service_name]
|
||||
action: replace
|
||||
target_label: service
|
||||
- source_labels: [__meta_kubernetes_pod_node_name]
|
||||
action: replace
|
||||
target_label: node
|
||||
|
||||
- job_name: "kubernetes-pods"
|
||||
kubernetes_sd_configs:
|
||||
- role: pod
|
||||
relabel_configs:
|
||||
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
|
||||
action: keep
|
||||
regex: "true"
|
||||
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
|
||||
action: replace
|
||||
target_label: __metrics_path__
|
||||
regex: (.+)
|
||||
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
|
||||
action: replace
|
||||
target_label: __address__
|
||||
regex: ([^:]+)(?::\d+)?;(\d+)
|
||||
replacement: $1:$2
|
||||
- source_labels: [__meta_kubernetes_namespace]
|
||||
action: replace
|
||||
target_label: namespace
|
||||
- source_labels: [__meta_kubernetes_pod_name]
|
||||
action: replace
|
||||
target_label: pod
|
||||
- source_labels: [__meta_kubernetes_pod_node_name]
|
||||
action: replace
|
||||
target_label: node
|
||||
|
||||
- job_name: "kubernetes-nodes"
|
||||
kubernetes_sd_configs:
|
||||
- role: node
|
||||
relabel_configs:
|
||||
- action: labelmap
|
||||
regex: __meta_kubernetes_node_label_(.+)
|
||||
- source_labels: [__meta_kubernetes_node_name]
|
||||
target_label: node
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
|
||||
insecure_skip_verify: true
|
||||
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
|
||||
|
||||
- job_name: "kubernetes-cadvisor"
|
||||
kubernetes_sd_configs:
|
||||
- role: node
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
|
||||
insecure_skip_verify: true
|
||||
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
|
||||
relabel_configs:
|
||||
- action: labelmap
|
||||
regex: __meta_kubernetes_node_label_(.+)
|
||||
- source_labels: [__meta_kubernetes_node_name]
|
||||
target_label: node
|
||||
metric_relabel_configs:
|
||||
- source_labels: [__name__]
|
||||
regex: "container_.*_seconds_total|container_cpu_load_average_10s|container_fs_reads_total|container_fs_writes_total|container_network_.*"
|
||||
action: keep
|
||||
@@ -1,43 +0,0 @@
|
||||
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
|
||||
securityContext:
|
||||
fsGroup: 65534
|
||||
containers:
|
||||
- name: prometheus
|
||||
image: docker.io/prom/prometheus:latest
|
||||
imagePullPolicy: IfNotPresent
|
||||
args:
|
||||
- "--config.file=/etc/prometheus/prometheus.yml"
|
||||
- "--storage.tsdb.path=/prometheus"
|
||||
- "--storage.tsdb.retention.time=15d"
|
||||
- "--web.enable-lifecycle"
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 9090
|
||||
volumeMounts:
|
||||
- name: prometheus-config
|
||||
mountPath: /etc/prometheus
|
||||
readOnly: true
|
||||
- name: prometheus-data
|
||||
mountPath: /prometheus
|
||||
volumes:
|
||||
- name: prometheus-config
|
||||
configMap:
|
||||
name: prometheus-config
|
||||
- name: prometheus-data
|
||||
persistentVolumeClaim:
|
||||
claimName: prometheus-data
|
||||
@@ -1,12 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: prometheus-data
|
||||
namespace: monitoring
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
||||
storageClassName: hcloud-volumes
|
||||
@@ -1,39 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: prometheus
|
||||
namespace: monitoring
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: prometheus
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources:
|
||||
- nodes
|
||||
- nodes/metrics
|
||||
- nodes/proxy
|
||||
- services
|
||||
- endpoints
|
||||
- pods
|
||||
verbs: ["get", "list", "watch"]
|
||||
- apiGroups: [""]
|
||||
resources:
|
||||
- configmaps
|
||||
verbs: ["get"]
|
||||
- nonResourceURLs: ["/metrics", "/metrics/cadvisor"]
|
||||
verbs: ["get"]
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: prometheus
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: prometheus
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: prometheus
|
||||
namespace: monitoring
|
||||
@@ -1,13 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: prometheus
|
||||
namespace: monitoring
|
||||
spec:
|
||||
selector:
|
||||
app: prometheus
|
||||
ports:
|
||||
- name: http
|
||||
protocol: TCP
|
||||
port: 9090
|
||||
targetPort: http
|
||||
@@ -0,0 +1,78 @@
|
||||
# kube-prometheus-stack Helm chart values
|
||||
# Installed via:
|
||||
# helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \
|
||||
# --namespace monitoring --version 87.3.0 -f Monitoring/kube-prometheus-stack.values.yaml
|
||||
#
|
||||
# Notes:
|
||||
# - Bundled Grafana is disabled; the hand-managed Grafana in Monitoring/Grafana/
|
||||
# is kept and pointed at the operator-managed Prometheus service
|
||||
# (prometheus-operated.monitoring.svc.cluster.local:9090).
|
||||
# - Node Exporter is provided by the chart's subchart; the previous hand-rolled
|
||||
# Monitoring/Prometheus/node_exporter_*.yaml manifests should be removed.
|
||||
# - Prometheus data lives on hcloud-volumes (Hetzner CSI), matching the old PVC.
|
||||
# - The operator picks up ServiceMonitors across all namespaces
|
||||
# (serviceMonitorSelector: {} -> nil -> selects all).
|
||||
|
||||
# Keep CRDs on helm uninstall so a re-install doesn't lose Prometheus CRs.
|
||||
crds:
|
||||
enabled: true
|
||||
|
||||
# ---- Alertmanager ----------------------------------------------------------
|
||||
alertmanager:
|
||||
enabled: false # not used by the homelab yet; flip to true when needed.
|
||||
|
||||
# ---- Prometheus ------------------------------------------------------------
|
||||
prometheus:
|
||||
enabled: true
|
||||
|
||||
ingress:
|
||||
enabled: false # use the existing Grafana ingress for UI; expose later if needed
|
||||
|
||||
prometheusSpec:
|
||||
# Match the previous manual deployment's retention.
|
||||
retention: 15d
|
||||
|
||||
# Hetzner CSI volume, same class as the old prometheus-data PVC.
|
||||
storageSpec:
|
||||
volumeClaimTemplate:
|
||||
spec:
|
||||
storageClassName: hcloud-volumes
|
||||
accessModes: ["ReadWriteOnce"]
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
||||
|
||||
# Select every ServiceMonitor in the cluster, regardless of labels.
|
||||
# (serviceMonitorSelectorNilUsesHelmValues must be false for {} to mean "all".)
|
||||
serviceMonitorSelectorNilUsesHelmValues: false
|
||||
serviceMonitorSelector: {}
|
||||
ruleSelectorNilUsesHelmValues: false
|
||||
ruleSelector: {}
|
||||
podMonitorSelectorNilUsesHelmValues: false
|
||||
podMonitorSelector: {}
|
||||
probeSelectorNilUsesHelmValues: false
|
||||
probeSelector: {}
|
||||
|
||||
# ---- Grafana (bundled) -----------------------------------------------------
|
||||
grafana:
|
||||
enabled: false # use the hand-managed Grafana in Monitoring/Grafana/
|
||||
|
||||
# Still render the operator's datasource/dashboards ConfigMaps so the
|
||||
# hand-managed Grafana can mount them if desired.
|
||||
forceDeployDatasources: false
|
||||
forceDeployDashboards: false
|
||||
defaultDashboardsEnabled: false
|
||||
|
||||
# ---- Node Exporter ---------------------------------------------------------
|
||||
# The chart ships prometheus-node-exporter as a subchart; a ServiceMonitor is
|
||||
# created automatically, so the old kubernetes-node-exporters scrape job in
|
||||
# prometheus_configmap.yaml becomes redundant once the operator is running.
|
||||
prometheus-node-exporter:
|
||||
enabled: true
|
||||
prometheus:
|
||||
monitor:
|
||||
enabled: true
|
||||
|
||||
# ---- kube-state-metrics ---------------------------------------------------
|
||||
# Enabled by default in the chart; provides cluster-state metrics
|
||||
# (deployments, pods, nodes, etc.). No overrides needed.
|
||||
@@ -0,0 +1,4 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: monitoring
|
||||
@@ -12,6 +12,7 @@ homelab cluster.
|
||||
| `DockerRegistry/`| Private Docker registry deployment, service, PVC and UI |
|
||||
| `Gitea/` | Gitea deployment, service, ingress, namespace, PVC, DB secret |
|
||||
| `Immich/` | Immich server, machine-learning, redis, config, secret |
|
||||
| `Monitoring/` | Prometheus Operator (kube-prometheus-stack Helm release) + hand-managed Grafana |
|
||||
| `PostgreSQL/` | PostgreSQL deployment, service, PVC, static endpoint, Hetzner volume variant |
|
||||
| `Secrets/` | Docker registry login credentials (gitignored) |
|
||||
| `volume/` | Persistent volume claim and SMB volume examples |
|
||||
@@ -24,6 +25,36 @@ Apply a manifest with:
|
||||
kubectl apply -f <path/to/manifest.yaml>
|
||||
```
|
||||
|
||||
## Monitoring stack
|
||||
|
||||
The `Monitoring/` directory runs the **kube-prometheus-stack** Helm chart
|
||||
(prometheus-operator + CRDs + node-exporter + kube-state-metrics) plus a
|
||||
hand-managed Grafana.
|
||||
|
||||
Install the chart once:
|
||||
|
||||
```bash
|
||||
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
|
||||
helm repo update
|
||||
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \
|
||||
--namespace monitoring --create-namespace \
|
||||
--version 87.3.0 \
|
||||
-f Monitoring/kube-prometheus-stack.values.yaml
|
||||
```
|
||||
|
||||
Upgrade after editing `Monitoring/kube-prometheus-stack.values.yaml`:
|
||||
|
||||
```bash
|
||||
helm upgrade kube-prometheus-stack prometheus-community/kube-prometheus-stack \
|
||||
--namespace monitoring --version 87.3.0 \
|
||||
-f Monitoring/kube-prometheus-stack.values.yaml
|
||||
```
|
||||
|
||||
Add scrape targets by creating `ServiceMonitor` / `PodMonitor` CRs in any
|
||||
namespace; the Prometheus CR selects all of them (`serviceMonitorSelector: {}`).
|
||||
Apply the Grafana manifests in `Monitoring/Grafana/` separately (its datasource
|
||||
points at `prometheus-operated.monitoring.svc.cluster.local:9090`).
|
||||
|
||||
## Notes
|
||||
|
||||
- Kubernetes `Secret` resources and the `Secrets/` directory are gitignored to
|
||||
|
||||
Reference in New Issue
Block a user