paint-brush
Beginner's Guide To Telepresence: Develop Your K8s Application Locally by@infracloud
130 reads

Beginner's Guide To Telepresence: Develop Your K8s Application Locally

by InfraCloud TechnologiesJanuary 8th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Telepresence is a lightweight development tool that can help you to debug and develop apps deployed to Kubernetes seamlessly. It replaces existing deployments with it’s own pod which runs a reverse-proxy that connects with our local system to forward and receive requests. This makes it possible for an app running locally to talk to other services which are running inside the Kubernees cluster. Devspace is a network proxy that connects your local system with your system to connect with your own cluster. The following tools provide a way for in-cluster development which syncs with your local files.

Company Mentioned

Mention Thumbnail
featured image - Beginner's Guide To Telepresence: Develop Your K8s Application Locally
InfraCloud Technologies HackerNoon profile picture

How do you develop apps in Kubernetes?

Kubernetes is great for operations but ideally speaking, it’s not something developers should concern themselves with. In reality, apps developed for Kubernetes are different because they interact with other services and could be stateful, both of which are tough to replicate in a local setup. Developers are used to the luxury of hot reloading and debugging to quickly test and improve the app.

When it comes to developing apps for Kubernetes, the developer needs to build and push the container image to the registry and then update Kubernetes pod. After all the time consuming tasks, developers still can’t hot-reload and debug their apps directly.

Over the time, there have been tools which help fasten the process of building the container image, automate the process of pushing to the registry and update Kubernetes with the change. While these tools can be a great addition, they’re quite inadequate from a developer’s perspective.

What is Telepresence?

Telepresence is a lightweight development tool that can help you to debug and develop apps deployed to Kubernetes seamlessly. Basically, you could have a process running on your local system (without necessarily having to build containers) and telepresence will proxy all the requests back and forth from the cluster to that process. How does it do it?

It replaces your existing deployments with it’s own pod which runs a reverse-proxy that connects with our local system to forward and receive requests. This makes it possible for an app running locally to talk to other services which are running inside the Kubernetes cluster. You can find instructions on how to install it here.

Demo!

Initially, there’s an existing deployment in the cluster which is running an API which returns “Hello World”. In this demo, I am going to replace the “Hello World” API deployed to Kubernetes with a process running locally that interacts with Kubernetes API to list the pods across namespaces with just one Telepresence command. Although I have interacted with Kubernetes API in this example, you could essentially interact with just about any other service.

As you can see, following the –run can be the command to run just about any binary on your local system which would run in context of Kubernetes, at least networking wise. In the demo, I had run the Uvicorn server.

Hopefully, this demonstrates how simple it can be to develop apps that need to interact with existing services deployed in Kubernetes. There might be times where you might want to forward requests to a container running locally, you can do that too with –docker-run instead of –run . Debugging and hot reloading apps in local containers can be done by VS Code’s Remote Development extension. You can also find language-specific extensions, here’s one for Go.

You can find the code used in the above demo here.

This looks too good, what’s the catch?

There are a couple of limitations as of now :

Currently, it can only swap Deployments. Work is being done to swap pods which would make it possible to replace any Kubernetes object that’s controlling pods (DaemonSets, Jobs, etc). Telepresence solves the issues of volumes too, but it’s not so elegant. In the best case, it requires to setup mock data on your local system which might not always be possible.

Other tools that are worth a mention:

The following tools provide a way for in-cluster development which syncs with your local files. By going where the app resides, this solves both networking and storage issues for development.

  • Okteto: This is an absolutely amazing project but only the enterprise version lets you connect with your Kubernetes cluster. Otherwise, you’re limited to a small instance on their cloud.
  • Devspace: Devspace allows you to connect with your own Kubernetes cluster. In most cases, both of these projects may require a bit of configuration to be written but that’s a one time effort which might be worth it.

Conclusion

Telepresence is a network proxy that connects with your local system to help develop apps in Kubernetes. A lot of projects are emerging in the space of development tools for Kubernetes. Telepresence is definitely on top of my list since it requires no configuration and simple to use. Please, drop a comment below to let us know which tools you have used and what you liked/disliked about them.

Previously published at https://www.infracloud.io/blogs/develop-your-kubernetes-apps-locally-telepresence/