diff --git a/Monitoring/Grafana/grafana_datasource.yaml b/Monitoring/Grafana/grafana_datasource.yaml index 8f51337..11780b8 100644 --- a/Monitoring/Grafana/grafana_datasource.yaml +++ b/Monitoring/Grafana/grafana_datasource.yaml @@ -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 \ No newline at end of file diff --git a/Monitoring/Grafana/grafana_deployment.yaml b/Monitoring/Grafana/grafana_deployment.yaml index ab29861..2acbd02 100644 --- a/Monitoring/Grafana/grafana_deployment.yaml +++ b/Monitoring/Grafana/grafana_deployment.yaml @@ -22,6 +22,9 @@ spec: ports: - name: http containerPort: 3000 + envFrom: + - secretRef: + name: grafana-db-secret env: - name: GF_SECURITY_ADMIN_USER valueFrom: diff --git a/Monitoring/Prometheus/prometheus_configmap.yaml b/Monitoring/Prometheus/prometheus_configmap.yaml deleted file mode 100644 index c3aeadf..0000000 --- a/Monitoring/Prometheus/prometheus_configmap.yaml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Monitoring/Prometheus/prometheus_deployment.yaml b/Monitoring/Prometheus/prometheus_deployment.yaml deleted file mode 100644 index 06362d9..0000000 --- a/Monitoring/Prometheus/prometheus_deployment.yaml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Monitoring/Prometheus/prometheus_pvc.yaml b/Monitoring/Prometheus/prometheus_pvc.yaml deleted file mode 100644 index 77d12a3..0000000 --- a/Monitoring/Prometheus/prometheus_pvc.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: prometheus-data - namespace: monitoring -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 10Gi - storageClassName: hcloud-volumes \ No newline at end of file diff --git a/Monitoring/Prometheus/prometheus_rbac.yaml b/Monitoring/Prometheus/prometheus_rbac.yaml deleted file mode 100644 index b826ff9..0000000 --- a/Monitoring/Prometheus/prometheus_rbac.yaml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Monitoring/Prometheus/prometheus_service.yaml b/Monitoring/Prometheus/prometheus_service.yaml deleted file mode 100644 index 29f8370..0000000 --- a/Monitoring/Prometheus/prometheus_service.yaml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Monitoring/kube-prometheus-stack.values.yaml b/Monitoring/kube-prometheus-stack.values.yaml new file mode 100644 index 0000000..ef4f538 --- /dev/null +++ b/Monitoring/kube-prometheus-stack.values.yaml @@ -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. \ No newline at end of file diff --git a/Monitoring/monitoring_namespace.yaml b/Monitoring/monitoring_namespace.yaml new file mode 100644 index 0000000..3335b6a --- /dev/null +++ b/Monitoring/monitoring_namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: monitoring \ No newline at end of file diff --git a/README.md b/README.md index 5a9c9f3..a633034 100644 --- a/README.md +++ b/README.md @@ -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 ``` +## 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