Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prometheus with multi-container pod on kubernetes

I have a multi-container pod in my kubernetes deployment:

  • java
  • redis
  • nginx

For every of those containers, there's a container with Prometheus exporter as well.

The question is how can I expose those ports to Prometheus if annotations section supports only one port per pod?

annotations:
  prometheus.io/scrape: 'true'
  prometheus.io/port: 'xxxx'

but I need something like this:

annotations:
  prometheus.io/scrape: 'true'
  prometheus.io/port_1: 'xxxx'
  prometheus.io/port_2: 'yyyy'
  prometheus.io/port_3: 'zzzz'

Maybe there's some other method to scrape all metrics from my multi-container pods? Thanks in advance for any kind of help.

like image 262
cardinal-gray Avatar asked Mar 30 '17 14:03

cardinal-gray


People also ask

Can Kubernetes pod run multiple containers?

Pods that run multiple containers that need to work together. A Pod can encapsulate an application composed of multiple co-located containers that are tightly coupled and need to share resources.

Can Prometheus monitor Kubernetes?

Prometheus is a high-scalable open-source monitoring framework. It provides out-of-the-box monitoring capabilities for the Kubernetes container orchestration platform. Also, In the observability space, it is gaining huge popularity as it helps with metrics and alerts.

How many containers a pod can run in Kubernetes?

No more than 300000 total containers.

How many containers a Kubernetes pod should contain?

No more than 300000 total containers.


1 Answers

Here's an example job for Prometheus. Put it in your own config.

Next, add:

annotations:
   prometheus.io/scrape: 'true'

to your pod metadata.

And on every container, which provides /metrics to prom, create an appropriate port, named metrics.

That's it. Prometheus would scrape only those ports, and there would be no situation, like when your redis instance would get http requests on its 6379 port.

like image 95
cardinal-gray Avatar answered Oct 05 '22 23:10

cardinal-gray