Over a million developers have joined DZone.

Rapid Development of Kubernetes Services With Telepresence

DZone's Guide to

Rapid Development of Kubernetes Services With Telepresence

Telepresence is an open source tool that simplifies the development of multi-container applications running on Kubernetes.

· Cloud Zone ·
Free Resource

Get the Metrics Collection and Monitoring Essentials tutorial collection. A 4-part tutorial series from DigitalOcean.

Imagine you're developing a new Kubernetes service. Typically, the way you'd test is by changing the code, rebuilding the image, pushing the image to a Docker registry, and then redeploying the Kubernetes Deployment. This can be slow.

Or, you can use Telepresence. Telepresence will proxy a remote Deployment to a process running on your machine. That means you can develop locally, editing code as you go, but test your service inside the Kubernetes cluster.

Let's say you're working on the following minimal server, helloworld.py:

#!/usr/bin/env python3

from http.server import BaseHTTPRequestHandler, HTTPServer

class RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_header('Content-type', 'text/plain')
        self.wfile.write(b"Hello, world!\n")

httpd = HTTPServer(('', 8080), RequestHandler)

You start a proxy inside your Kubernetes cluster that will forward requests from the cluster to your local process, and in the resulting shell you start the web server:

localhost$ telepresence --new-deployment hello-world --expose 8080
localhost$ python3 helloworld.py

This will create a new Deployment and Service named hello-world, which will listen on port 8080 and forward traffic to the process on your machine on port 8080.

You can see this if you start a container inside the Kubernetes cluster and connect to that Service. In a new terminal run:

localhost$ kubectl --restart=Never run -i -t --image=alpine console /bin/sh
kubernetes# wget -O - -q http://hello-world:8080/
Hello, world!

Now, switch back to the other terminal, kill helloworld.py and edit it so it returns a different string. For example:

python3 helloworld.py
localhost$ sed s/Hello/Goodbye/g -i helloworld.py
localhost$ grep Goodbye helloworld.py
        self.wfile.write(b"Goodbye, world!\n")
localhost$ python3 helloworld.py

Now that we've restarted our local process with new code, we can send it another query from the other terminal where we have a shell running inside a Kubernetes pod:

kubernetes# wget -O - -q http://hello-world:8080/
Goodbye, world!
kubernetes# exit

And there you have it: You edit your code locally, and changes are reflected immediately to clients inside the Kubernetes cluster without having to redeploy, create Docker images, and so on.

Additional Resources

If you're interested in trying Telepresence on your own you can install locally with Homebrew, apt, or dnf.

Or check out these other tutorials:

Have questions? Ask in the Telepresence Gitter chatroom or file an issue on GitHub.

Getting Started with Kubernetes: A Webinar Series brought to you by DigitalOcean

kubernetes ,open source ,container application ,telepresence ,cloud ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}