Now you can just attach your remote debugger to localhost:5005.Sometimes your app works, but you want to increase performance by boosting its throughput or reducing latency. The above will port-forward from your local environment (5005) to the pod’s port 5005. If you run the kubectl client locally, this is easy: List the pods in your cluster (~ ) $ kubectl get podįile-ingress-events-3artj 1/1 Running 1 13h Proxy the pod to a specific port (~ ) $ kubectl port-forward file-ingress-events-3artj 5005:5005 The last step is to proxy the debug port to your local machine. The bootstrap scripts (above) will check that env variable and you can control it via the kube manifest (now with ConfigMap in Kube 1.2, or OpenShift templates). Note, we’ve also added an env variable in the kubernetes manifest file to be able to control whether we want remote debugging on or off (true/false). Now you need to expose port 5005 (in this example) in your Docker containers via your Kubernetes manifest (json/yaml) file: spec : containers : - args : command : env : - name : " JAVA_ENABLE_DEBUG" value : " true" - name : " OUTGOING_FILE_PATH" value : " /deployments/camel/outgoing" - name : " INCOMING_FILE_PATH" value : " /deployments/camel/incoming" - name : " KUBERNETES_NAMESPACE" valueFrom : fieldRef : fieldPath : " metadata.namespace" image : " fabric8/file-ingress-events:1.0-SNAPSHOT" name : " file-ingress-events" ports : - containerPort : 5005 name : " jvm-debug" - containerPort : 8778 name : " jolokia" Bootstrap Java app to be able to expose remote debug portĮxample: # Set debug options if required if [ x " $ " fi Define debug port in docker container via kubernetes manifest For example, for the HawtApp Maven plugin which is a simple mvn plugin that assigns a Java Main as the executable and a simple, flexible bootstrap bin/run.sh script (or batch file for windows) that allows you to control classpath and debugging via environment variables. When you bootstrap your JVM, you should have a way to enable JVM debug. To do this, you don’t really do anything different from what you do today. This becomes really handy to see exactly what’s going on in your application. If you must log into the pod for some reason (poke around the file system, grok other config files, etc): (~ ) $ kubectl exec -it file-ingress-events-3artj bash JVM Remote debug your application Now pick the pod you want to stream the logs from and go! (~ ) $ kubectl logs -f file-ingress-events-3artj Connect via Shell if you must Regardless of which machine you’re running on (ie, where you run the kubernetes client), you can do the following: List the pods in your cluster (~ ) $ kubectl get podįile-ingress-events-3artj 1/1 Running 1 13h Tail the logs With Kubernetes, you don’t have to do any of that. On some cluster management systems, you have to basically look up the local IP of your application (if running in a container), ssh into it somehow, and then find the log and tail it. Here are a few tips: Tailing logs for your pod One thing for Java Developers that comes up is how do you view logs, do remote debug, and take stack traces. For example, you get process isolation, port-space isolation, network/storage, etc so things don’t collide on your local developer laptop. When you’re developing microservices on your local laptop, you can use something like Kubernetes to run you docker containers locally and get developer/QA/production likeness in how you deploy your applications.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |