I would like to monitor applications running in a single Kubernetes namespace, which includes:
prometheus metrics endpoints
pod logs ( written to the container’s stdout )
opentelemetry traces
Looking at the Helm chart ( k8s-monitoring 0.2.2 · grafana/grafana ) I don’t see any changes that I can make to configure the metrics scraping/log gathering to be confined to a single namespace. I guess gathering traces is a push mechanism so this is not an issue.
What options do I have for confining log gathering/metrics scraping to a single Kubernetes namespace?
Thanks a lot @petewall , this looks good! I tried deploying the k8s-monitoring helm chart to my target cluster but there is a CRD conflict with the kube-prometheus stack which I was not able to immediately solve. I am using FluxCD which may complicate things a bit.
This seems to work, but I see in the logs that it tries to scrape metrics from outside the configured namespace. I guess this is expected, as the extraMetricRelabelingRules parameter is not taken into account here.
So, instead of putting a rule in the prometheus.scrape component, you’ll need to add a discovery.relabel component with that rule. Also, the namespace label wont be set, so you’ll use the __meta_kubernetes_namespace label. You can see all of the meta labels that are set by discovery.kubernetes.pods from here: discovery.kubernetes | Grafana Agent documentation.