I've got a super simple Java Kubernetes Tomcat application running inside of Kubernetes that I instrumented with the JVM Jolokia agent running on minikube. I'm trying to configure my Kubernetes deployment so I can access the Jolokia endpoint outside of the container. When I try to access the endpoint at http://127.0.0.1/jolokia/version from outside the container on my minikube IP I get a connection refused.
I've set the Jolokia agent via the CATALINA_OPTS variable and set it run on port 8778 and exposed 8778 in my Dockerfile. I've logged into the container and can confirm I can access the Jolokia agent as long as I'm inside the container.
FROM tomcat:8.0-alpine
ADD sample.war /usr/local/tomcat/webapps/
#ADD jolokia.war /usr/local/tomcat/webapps/
RUN mkdir /home/jolokia/
ADD jolokia-jvm-1.7.1.jar /home/jolokia/javaagent.jar
ENV CATALINA_OPTS="$CATALINA_OPTS -javaagent:/home/jolokia/javaagent.jar=port=8778"
RUN apk --no-cache add curl
EXPOSE 8080
EXPOSE 8778
CMD ["catalina.sh", "run"]
Next in my Kube deployment I specify that I set a nodePort to map 8778 to port 30087 however; when I pull my minikube IP and access it via http://minikube-ip:30087/jolokia/version, I keep getting connections refused. Here's my deployment:
---
apiVersion: v1
kind: Service
metadata:
labels:
app: sample-tomcat
name: sample-tomcat
spec:
type: NodePort
ports:
- name: tomcat-port
port: 8080
nodePort: 30088
- name: jolokia-port
port: 8778
nodePort: 30087
selector:
app: sample-tomcat
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-tomcat
labels:
app: sample-tomcat
spec:
selector:
matchLabels:
app: sample-tomcat
replicas: 1
template:
metadata:
labels:
app: sample-tomcat
spec:
containers:
- name: sample-tomcat
image: <redacted>/sampleapp:latest
ports:
- containerPort: 8080
- containerPort: 8778
Jolokia agent works inside of my container, but how do I access it outside of the container?
I needed to set the Jolokia agent host to 0.0.0.0 as it wasn't using the right IP within the CATALINA_OPTS variable.
ENV CATALINA_OPTS="$CATALINA_OPTS javaagent:/home/jolokia/javaagent.jar=port=8778,host=0.0.0.0"