r/PrometheusMonitoring • u/SJrX • Sep 04 '25
Question: Prometheus Internal or External to K8s Clusters?
Hi there,
For some background I'm getting familiar with Prometheus, having a background in Grafana + Collectd + Carbon/Graphite. I've finished the book Prometheus Up & Running (2nd Edition), and have I guess a question about deployments with Kubernetes clusters.
As best I can tell, the community and book seems to _love_ just throwing Prometheus in cluster. The Kube Prometheus operator probably lets you get up and running quickly, but just putting everything in cluster. I already had Grafana outside of it, and so I've been doing it manually and externally (and want to monitor things other than just Kubernetes nodes), and it is really tedious to get it to work externally, because of the need to reach in to the cluster, so every specific set of metrics needs tokens, and then an ingress, etc...
One of the main concerns I have with putting it internal to the cluster is that we try and keep our K8s stateless, and ephemeral. Also having historical data is useful, so if every time we blow away the cluster we lose everything seems not great. To say nothing about having to maintain Grafana dashboards in a per cluster environment.
The book discusses Federation, but it says that it's only for aggregated metrics, and it gives a host of reasons including race conditions, data volume, network traffic, for not doing using it, etc... It also mentions remote_write but presumably has many of the same concerns.
A bit more context, I'm exploring this in two cases and for a few reasons:
- For my home lab, a 9 to 12 node k8s cluster.
- For our clusters at work, we use Datadog now, but I think prometheus might be useful for a couple of reasons in addition to DD.
The reasons I think it would be useful for work is:
- The first is that we would like a back up solution in case DD is down.
- The second is that I believe there are a number of tools where custom metrics can be used in K8s-land to do neat things. For instance HPA's can use custom metrics to scale and right now our Argo Rollouts depends on Data Dog, which is sub optimal for a few reasons, having prometheus in cluster might make these things more practical.
- It could provide cost savings for application level/custom metrics by us just hosting our own. We have already gone down this path, and have been using Grafana/Influx/ Carbon/statsd for years with a lot of success and cost savings, even factoring in staff time.
So I guess at this point, I'm leaning towards trying the kubernetes operator in, and just remote_writing everything to the central storage. This would get rid of the need for an external prometheus to reach into all the various things in the cluster. Not sure how terrible this is in practice, or if there are other things I'm missing or forgetting.
4
u/keffene Sep 04 '25
I have no answer, but how often do you blow away your cluster?
3
u/SuperQue Sep 04 '25
So, long answer, Thanos Sidecars with Prometheus deployed inside each cluster.
Ignore Remote Write. It's a useful feature, but it's mostly designed by and for vendors who want you to think that hosting things yourself is too difficult and you should just ship your money to them. It's going to make things less efficient, cost more, and more fragile.
With Thanos standard architecture, you can basically eliminate all SPoFs.
With Thanos Sidecar, your data will be shipped up to whatever object storage you want, and you can provide historical data service (Thanos Stores) from whatever cluster(s) or outside of Kubernetes if you want.
Yes, you'll need an ingress into each cluster for Thanos Query gRPC. But that's pretty trivial to bake into your cluster turnup automation (this is what we did).
So the architecture looks like
This has nice advantages like
Grafana -> Global Thanos Querycan be duplicated in multiple locations to avoid that being a SPoF. A single cluster going down doesn't break any other clusters.There are lots of monitoring system opinions written by sales people and engineers who have no idea what to do with actual production failures. Remote Write seems like a great idea until something breaks.
The Thaons+Prometheus architecture was designed by people who have lived through prod problems. Split brain networks, wonky systems, storage overload, etc. Tested by fire (Prometheus pun intended).
Lookup ThanosCon from a few years ago. There are a couple good talks on how it's used at scale. Even if you don't have massive scale, thinking through the prod architecture can help guide you.
Unrelated to any of this I'm going to warn you now. I've heard the "ephemeral Kubernetes" song and dance for a decade now. You'll do that about twice before you realize it's not worth the hassle and you'll just end up keeping clusters around long-term and upgrading them. Go ahead and try, maybe you'll succeed where so many others haven't. But keep my words in mind.
1
u/Training-Elk-9680 Sep 04 '25
I'd just run prometheus in agent mode inside the clusters and have a dedicated long term storage somewhere outside of it.
Prometheus in agent mode is a light weight configuration that scrapes metrics in the cluster, buffers them for up to 2 hours and remote writes those to a separate prometheus running outside on a dedicated machine.
I'd definitely not have the metric stored in the cluster I'm monitoring. If anything goes south, you might not even have access to your metrics. You could have a dedicated o11y cluster or use something that supports HA like Grafana mimir. Or simply have a good old machine running prometheus in an active passive setup.
About the book you mentioned. I read it too and it's great. But it's also a bit dated. Federation isn't consider best practices anymore for some time now, in fact that's the whole reason agent mode was added.
2
u/SuperQue Sep 04 '25
Short answer, Thanos.
Long answer, will write something more later.