Debugging a single service with Telepresence
Debug Area
In the debug area you will see the list of all the microservices developed with the Developer Console.
At the first level you have the necessary information to understand the health of the service: whether it is active or not, and the memory levels used.
Although the real potential of the debug area is its connection with telepresence. Pressing the "Debug" button will in fact display a string to be pasted on your terminal that simulates the behavior of your microservice in a real context.
This will allow you to easily test and debug your micro-service without compromising the production environments
Introduction to Telepresence
Telepresence is an open source tool that lets you run a single service locally, while connecting that service to a remote Kubernetes cluster. This lets developers working on multi-service applications to:
Do fast local development of a single service, even if that service depends on other services in your cluster. Make a change to your service, save, and you can immediately see the new service in action.
Use any tool installed locally to test/debug/edit your service. For example, you can use a debugger or IDE!
Make your local development machine operate as if it's part of your Kubernetes cluster. If you've got an application on your machine that you want to run against a service in the cluster -- it's easy to do.
Telepresence works on both Mac OS X and Linux, with OS-native packages.
Installing Telepresence
OS X
On OS X you can install Telepresence by running the following:
brew cask install osxfuse
brew install datawire/blackbird/telepresence
Ubuntu 16.04 or later
Run the following to install Telepresence:
curl -s https://packagecloud.io/install/repositories/datawireio/telepresence/script.deb.sh | sudo bash
sudo apt install --no-install-recommends telepresence
If you are running another Debian-based distribution that has Python 3.5 installable as python3, you may be able to use the Ubuntu 16.04 (Xenial) packages. The following works on Linux Mint 18.2 (Sonya) and Debian 9 (Stretch) by forcing the PackageCloud installer to access Xenial packages.
curl -sO https://packagecloud.io/install/repositories/datawireio/telepresence/script.deb.sh
sudo env os=ubuntu dist=xenial bash script.deb.sh
sudo apt install --no-install-recommends telepresence
rm script.deb.sh
Connect to a Kubernetes Cluster and start debugging the microservice
Let's take an example on a test cluster
1. Connect to your cluster
gcloud container clusters get-credentials your-credential --zone your-zone --project your-project
If you don't have yet installed Google Cloud follow the steps at this link
2. Navigate in Kubernetes
kubens demo
Node
3a. Access to your local source directory
cd your-local-source-directory
4a. Run telepresence and start debugging your-service-node
telepresence --swap-deployment your-service-node --expose 3000 --run npm start
Java
3b. Access to your local source directory
cd your-local-source-directory
4b. Run telepresence and create env variables
telepresence --expose 3000 --swap-deployment your-service-java --env-json your-service-java.json