Home Debugging Kubernetes Services with Telepresence
Post
Cancel

Debugging Kubernetes Services with Telepresence

Setting Up and Using Telepresence for Local Development

When working in cloud systems, it’s often difficult to debug, or even get to the idea of debugging because the requests come into service endpoints which the pod(controllers) will run. For CR(custom resources), you can scale down the pods and attach to your ide, say vscode, locally. But what about Kubernetes services?

Telepresence is a powerful tool for developers working with Kubernetes clusters, especially when you need to debug or test code locally as if it were running in the cluster. In this post, I’ll walk you through the installation and basic usage of Telepresence, focusing on how to connect, check services, and set up intercepts.

Step 1: Install Telepresence

To install Telepresence, you can use Homebrew on macOS. Simply run:

1
brew install datawire/blackbird/telepresence

Step 2: Connect Telepresence to Your Kubernetes Namespace

Once installed, you’ll need to connect Telepresence to the namespace where your service is running. Use the following command, specifying your namespace (in this case, example-ns):

1
telepresence connect --namespace example-ns

Step 3: Install Traffic Manager (if Needed)

If Traffic Manager isn’t already installed, Telepresence will prompt you to install it. You can do so with:

1
telepresence helm install

In some cases, you might encounter a timeout error during installation. You can resolve this by modifying Telepresence’s configuration file. Open the configuration file located at:

1
vi /Users/<username>/Library/Application Support/telepresence/config.yml

Adjust the timeout settings as needed, and retry the installation.

Step 4: Verify Services with Telepresence

After connecting, list all services to ensure your target service is available:

1
telepresence list

You should see your service in the list if everything is set up correctly.

Step 5: Intercept a Service Locally

Now, let’s intercept a specific service. In this example, I’ll intercept the example-ns service and redirect traffic to my local port 8080. You’ll also want to specify any environment variables needed for debugging by providing an .env file.

Run this command in the directory where you want the service intercept:

1
telepresence intercept exampe-ns --port=8080 --env-file=go-debug.env

At this point, traffic to exampe-ns in the Kubernetes cluster will be routed to your local setup, enabling you to debug and test as if you were running within the cluster.

That’s it! You now have Telepresence set up to help with debugging and testing Kubernetes services locally. This setup streamlines development workflows by letting you work on your services as if they were live in your cluster, saving time and resources.

This post is licensed under CC BY 4.0 by the author.

Query Optimization in Databases: Translating, Planning, and Cost Estimation in Databases

Early vs. Late Materialization in Databases: How Timing Affects Query Performance