Java remote debugging of applications running on Kubernetes

Article by the only cloud technology translation, if reproduced, must be marked reproduced from the "only cloud technology"

preface
Kubernetes1.2 version has just recently released to become a container (Docker, Rocket, Hyper, etc., the fact that the cluster management path. Here are some interesting features on the 1.2 version:
Clusters can now scale to 30,000 containers A cluster of elegant closed nodes, transition to other nodes running in the cluster Customize the specified indicators as the basis for automatic expansion of dynamic configuration management When you develop micro services on top of the local notebook, you You can use Kubernetes to run your local Docker container and get a similar process such as developer / QA / production process when you configure your application.
For Java developers, there is one thing that will happen: how you look at the log, do remote debugging, and how to track the protocol stack. The following article is a few tips:

Track logs for your pod

In some cluster management systems, you basically have to find the application's local IP (if it is running in the container), in any case to ssh to it, and then find the log and track it. With Kubernetes, you do not have to do anything above. In addition to the machine you are running (that is where you run Kubernetes client), you can follow the following:

List the following pods in your cluster

屏幕快照_2016-04-06_下午5.19_.43_.png

Tracking the log <br /> Now select the log you want to track and run it!

屏幕快照_2016-04-06_下午5.20_.55_.png

If necessary, connect through the shell

If you have to log in to the pod for some reason (look at the file system, see other configuration files, etc.)

屏幕快照_2016-04-06_下午5.22_.27_.png

The virtual machine remotely debugs your application

In this case, it would be convenient to see what happened to your application. In order to do this, you just do the same thing as you do today. When you bootstrap your JVM, you should have a way to start JVM debugging. For example, the HawtApp Maven plugin is a simple mvn plugin that makes Java Main an executable, simple, and flexible bootrtrap bin / run.sh script (or windows batch file) that allows you to control paths and pass environment variables debugging

Bootstrap Java can be exposed to the debug port

such as:

屏幕快照_2016-04-06_下午5.24_.23_.png

Define the debug port in the docker container via the Kubernetes key list

Now you need to expose port 5005 (in this example) in your Docker container via your Kubernetes key list (json / yaml)

屏幕快照_2016-04-06_下午5.25_.30_.png

Note that we have added an env variable to the Kubernetes key list file to control whether we want to remotely debug open or close (true / false). The Bootstrap script (described above) checks the env variable, and you can control it via the kube key list (now Kube1.2 has ConfigMap, or OpenShift templates).

The last step is to proxy the service port to your local machine. If you run kubectlclient locally, it will be very easy:

List the pods in the cluster

屏幕快照_2016-04-06_下午5.32_.45_.png

Proxy pod to a special port

屏幕快照_2016-04-06_下午5.33_.34_.png

The above code will be forwarded from your local environment (5005) port to pod port 5005. Now you can attach your remote debugger to localhost: 5005.
Hope this post can help you debug your Java apps!

Repeat it, the article by the cloud technology translation, if reproduced, must be marked reproduced from the "only cloud technology"
Original link: http://blog.christianposta.com … 1bb5f

To find out more about Kubernetes, please pay attention to the Caicloud public platform

图片_1副本.png

    Heads up! This alert needs your attention, but it's not super important.