DEV Community

Cover image for Kubernetes Debugging Made Easy with mirrord
Mihai Farcas
Mihai Farcas

Posted on

Kubernetes Debugging Made Easy with mirrord

Developing and debugging applications in a Kubernetes cluster can be complex. However, mirrord, an open-source project by MetalBear, offers a solution to simplify this process.

The Use Case

Imagine you're a software engineer working on a complex project involving multiple interconnected microservices. You encounter a bug that only occurs in the staging environment. Reproducing this bug locally is a nightmare for two main reasons:

  1. Running the application locally requires a complex setup with multiple microservices, making it difficult to replicate the staging environment accurately.

  2. The bug may be data-dependent, and you lack the specific data present in the staging environment. Downloading this data from the staging database is a convoluted process.

This is where mirrord comes in!

What is mirrord?

mirrord is an open-source tool designed to simplify the development and debugging of applications running in Kubernetes clusters. It achieves this by enabling developers to work on their code directly within the cluster, eliminating the need for extensive local setups or continuous deployments to staging environments.

How does it work?

mirrord operates as a "mirror" (hence the name) between your local development environment and the Kubernetes cluster. It intercepts requests destined for your application pods in the cluster and duplicates them, sending a copy to your local machine.  

This allows you to run and debug your code locally while interacting with real production data and services within the cluster. In essence, it's like having a magic portal that connects your local machine to the live Kubernetes environment without affecting actual users.

Example: Debugging a Production-Only Bug

The video demonstrates how mirrord can help debug an upper-environment-only bug. The application, written in Go, runs fine locally but displays an error in the production Kubernetes cluster. In the following video I show how to use the mirrord along with it's VS Code extension to debug the application. mirrord allows you to select a target to mirror (pod or deployment) and provides access to the same resources and environment variables as the remote application.

Keep in mind you have to have kubectl access to the Kubernetes cluster you want to target pods in.

Who is Mirrord for?

Developers Tired of the "Push-and-Pray" Development Cycle

If you're tired of the constant cycle of pushing code to a staging environment and praying it works, Mirrord is for you. With mirrord, you can see your code running in a near-production environment instantly, without waiting for deployments.

Teams Struggling with Complex Local Setups

Setting up a local environment that accurately mirrors a production Kubernetes cluster can be a real headache, especially in microservice architectures. mirrord eliminates this pain by allowing you to develop and debug directly in the cluster.

Developers Who Need to Debug with Production-Like Data

Debugging with real-world data is crucial for finding and fixing those tricky bugs that only show up in upper environments. mirrord lets you do this safely, without impacting your live application.

Anyone Facing Challenges in Reproducing and Fixing Environment-Specific Bugs

Some bugs just won't show up in your local environment, no matter how hard you try to replicate it. mirrord makes it easy to reproduce and fix these environment-specific bugs by giving you direct access to the target environment.

TLDR; mirrord is for any developer who wants to simplify Kubernetes development and debugging, improve their workflow, and ship higher-quality code faster.

For more details check out the documentation on the mirrord website along with the code repository I created to demonstrate mirrod's features.

About me

I'm Mihai Farcas, a software engineer with a few years of experience under my belt. I'm passionate about writing code and love sharing knowledge with fellow developers.

My YouTube channel, "Let's Talk Dev," is where I break down complex concepts, share my experiences (both the good and the face-palm moments).

Connect with me:

Website: https://mihai.ltd
YouTube: https://www.youtube.com/@letstalkdev
GitHub: https://github.com/mihailtd
LinkedIn: https://www.linkedin.com/in/mihai-farcas-ltd/

Top comments (0)