How do I get the pod to expose the prometheus monitoring port in Flink application mode on Kubernetes?

6/22/2021

I'm running flink run-application targetting Kubernetes, using these options:

-Dmetrics.reporter.prom.class=org.apache.flink.metrics.prometheus.PrometheusReporter
-Dmetrics.reporter.prom.port=9249

I specify a container image which has the Prometheus plugin copied into /opt/flink/plugins. From within the job manager container I can download Prometheus metrics on port 9249. However, kubectl describe on the flink pod does not show that the Prometheus port is exposed. The ports line in the kubectl output is:

Ports: 8081/TCP, 6123/TCP, 6124/TCP

Therefore, I expect that nothing outside the container will be able to read the Prometheus metrics.

-- Dickon Reed
apache-flink
kubernetes
prometheus

1 Answer

6/22/2021

You are misunderstanding the concept of exposed ports.
When you expose a port in kubernetes with the ports option (the same apply with Docker and the EXPOSE tag), nothing is open on this port from the outside world.

It's basically just a hint for users of that image to tell them "Hey, you want to use this image ? Ok, you may want to have a look at this port on this container."

So if your port does not appear when you do kubectl describe, then it does not mean that you can't reach that port. You can still map it with a service targetting this port.

Furthermore, if you really want to make it appear with kubectl describe, then you just have to add it to your kubernetes descriptor file :

...
  containers:
  - ports:
      - name: prom-http
        containerPort: 9249
-- Marc ABOUCHACRA
Source: StackOverflow