kubernetes
I can expose services with service
. This is fine.
Adding to https://stackoverflow.com/a/39927197/1387184, I wanted to monitor all instances of the same pod at once, since we are hardcoding the port as 1099, it was difficult as I can do only one portforward to one pod with that port.
I used Shell Script to dynamically assign pod when running the docker
Dockerfile
CMD /run.sh
run.sh
JMX_PORT=$(((RANDOM % 20)+1099))
echo "Running JMX on Port $JMX_PORT"
java ``eval echo $JAVA_OPTS`` ...
deployment.yml
env:
- name: JAVA_OPTS
value: "-Xms256m -Xmx6144m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=$JMX_PORT -Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT -Djava.rmi.server.hostname=127.0.0.1"
the eval will evaluate the JMX_PORT to bash value, each pod when starts will likely to get different pod. I