DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • What I Learned From Crawling 100+ Websites
  • Fun Is the Glue That Makes Everything Stick, Also the OCP
  • Integration Testing Tutorial: A Comprehensive Guide With Examples And Best Practices
  • Does the OCP Exam Still Make Sense?
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Debugging Microservices Running on Kubernetes

Debugging Microservices Running on Kubernetes

Learn how to debug microservices locally on Kubernetes.

Niklas Heidloff user avatar by
Niklas Heidloff
CORE ·
Mar. 22, 19 · Tutorial
Like (8)
Save
Tweet
Share
17.85K Views

Join the DZone community and get the full member experience.

Join For Free

in order to learn more about microservices, container orchestration, and service meshes, i’ve set up a local development environment with minikube, istio, and tools like kiali and created a sample application . in this article, i describe how to debug these services locally.

microservices can be developed in various languages and with multiple frameworks. for the different implementation types, there are specialized and established ides (integrated development environments) and tools to debug the single services.

the new challenge when debugging cloud-native applications is that applications often have many microservices and there is a lot of communication between them. testing and debugging only separate services is not sufficient.

requirements

here is a list of my debugging requirements. in the optimal case, i’d like to:

  • run and debug my code in my favorite ide locally (rather than using a slow remote debugger)
  • run the single service as part of the overall application, for example, invoke it from another service (rather than via unit tests and mock objects only)
  • run the code in the same container locally as in production (rather than installing application servers locally)
  • do changes in the code locally and test them immediately (rather than restarting containers)

telepresence

there are several different ways to debug microservices. one great solution is to use telepresence , which is an open-source tool for the “fast, local development for kubernetes and openshift microservices.”

here is an example. i’m using a simple application that just has two microservices so far. the bff (backend for frontend) ‘web-api’ microservice invokes another ‘articles’ microservice. i want to debug the ‘articles’ service locally and let the ‘web-api’ service invoke it, which runs in a kubernetes cluster.

i’ve implemented these services with javaee, openj9, open liberty , and microprofile within eclipse. there is a lot of documentation available how to debug open liberty in eclipse via the open liberty tools . you can import the ‘articles’ service as existing maven project. in order to run the service in the local open liberty server, you need to check ‘dynamic web module’ in the ‘project facets’ settings. after this, you can start the local open liberty server.

in order to run the ‘articles’ service on kubernetes, i’ve written a simple script to deploy it. here is the yaml file:

kind: service
apiversion: v1
metadata:
  name: articles
  labels:
    app: articles
spec:
  selector:
    app: articles
  ports:
    - port: 9080
      name: http
  type: nodeport
---

kind: deployment
apiversion: apps/v1beta1
metadata:
  name: articles
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: articles
        version: v1
    spec:
      containers:
      - name: articles
        image: articles:1
        ports:
        - containerport: 9080


now to the exciting part. telepresence allows you to swap a pod running in kubernetes with a service running locally. all requests to the pod in kubernetes are redirected to the local url and port.

after you have installed telepresense , the following command can be run:

debugging-istio-1

once the kubernetes remote port 9080 has been mapped to the local port 9080, the locally running service can be invoked from the ‘web-api’ service running in kubernetes. the best part is you can also use the eclipse debugger as if everything would run locally.

debugging-istio-4

calling from local services to kubernetes

with this easy setup, services in kubernetes can invoke local services. unfortunately, the other direction doesn’t work. for example, a locally running service ‘web-api’ cannot invoke the kubernetes service ‘articles’ via ‘ http://articles:9080 ’.

fortunately, telepresense comes with a mechanism to support this as well. essentially, you can run your code in a local docker container and debug it with a remote debugger. telepresense can replace the kubernetes pod with a two-way proxy that handles the traffic to your local docker container. there is even support for ‘hot code replace’ (see documentation).

i haven’t tried the two-way communication yet, but the functionality sounds very promising and would fulfill the requirements above!

if you want to give it a try, use the sample application , set up a local development environment , and follow the instructions above.

happy debugging!

Kubernetes microservice Web Service Docker (software) application

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • What I Learned From Crawling 100+ Websites
  • Fun Is the Glue That Makes Everything Stick, Also the OCP
  • Integration Testing Tutorial: A Comprehensive Guide With Examples And Best Practices
  • Does the OCP Exam Still Make Sense?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: