Sometimes you may want to run monit inside a Kubernetes cluster just to validate what you’re getting from your standard monitoring solution with a second monitor that does not require that much configuration or tinkering. In such cases the Dockerfile bellow might come handy:
FROM ubuntu:bionic RUN apt-get update RUN apt-get install monit bind9-host netcat fping -y RUN ln -f -s /dev/fd/1 /var/log/monit.log COPY monitrc /etc/monit RUN chmod 0600 /etc/monit/monitrc EXPOSE 2812 ENTRYPOINT [ "/usr/bin/monit" ] CMD [ "-I", "-c", "/etc/monit/monitrc" ]
I connected to it via
kubectl -n monit-test port-forward --address=0.0.0.0 pod/monit-XXXX-YYYY 2812:2812. Most people do not need
--address=0.0.0.0, but I run
kubectl inside a VM for some degree of compartmentalization. Stringent, I know…
Why would you need something like this you ask? Well imagine the case where you have multiple pods running, no restarts, everything fine, but randomly you get connection timeouts to the clusterIP address:port pair. If you have no way of reproducing this, don’t you want an alert the exact moment it happens? That was the case for me.
And also the fun of using a tool in an unforeseen way.