Join us on June 5th for a Tech Talk with Bill Doerrfeld and Kenn Hussey as we discuss the future of open source. Register now
.
Back to blog
KUBERNETES, LOCAL KUBERNETES

Local Kubernetes Development: A Comprehensive Guide for Improved Efficiency

October 24, 2023 | 8 min read

Kubernetes has become the standard for deploying and managing containerized applications at scale. However, developing on Kubernetes poses challenges for developers. Creating accurate local dev environments that mirror production is complex, time-consuming, and delays testing. Developers face a trade-off between velocity and accuracy when developing locally with Kubernetes.

One of the biggest challenges individual developers and development teams face when building applications on Kubernetes is balancing rapid iteration with production-representative testing. Creating disposable development environments that resemble production environments is complex, time-consuming, and costly. This is where local development with Kubernetes makes a major impact.


How to Accelerate Local Development with Kubernetes & Telepresence

Telepresence provides a solution for local development with Kubernetes without sacrificing accuracy. It sets up a network proxy between your machine and the remote cluster, allowing you to preview code changes locally while leveraging production services and dependencies. This makes it easier to develop and test Kubernetes applications by providing a local environment that is closely aligned with the production environment.

It provides a fast and iterative developer experience for teams building microservices on Kubernetes and enables developers to run services locally while seamlessly interacting with remote Kubernetes clusters.


The Benefits of Local Development with Kubernetes Using Telepresence

  • It improves your developer experience: Telepresence eliminates infrastructure hassles, thereby enabling developers to focus on writing code instead of complex setup and maintenance. This creates a more consistent experience across teams.
  • It speeds up Kubernetes development: Developers save time on Kubernetes development tasks, such as setting up and maintaining development clusters. It can also streamline development and stakeholder review cycles.
  • You’ll now have a quicker feedback loop: With Telepresence, you’ll get immediate feedback on code changes without waiting for the time-consuming process of building, containerizing, and deploying. This allows developers to iterate on their code more quickly.
  • You can now catch bugs before production: Developers test their code against real dependencies in production, which can help to catch bugs before they make it to production. This can improve the quality of applications and reduce the risk of outages.

Telepresence Addresses Common Kubernetes Development Pain Points:

  1. It eliminates the need for container rebuilds and redeploys, which significantly improve feedback loops.
  2. It allows developers to test their code against actual dependencies in production, which addresses the limitations of mocking services.
  3. It makes it easier to attach debuggers and inspect code running remotely, which addresses the challenges of debugging Kubernetes applications.

With Telepresence, code changes are reflected instantly without redeployments. Developers can debug services locally while leveraging the real services and dependencies running in production. This unlocks developer productivity by providing fast iterations and realistic testing against remote Kubernetes clusters.

Setup and Configuration

Let's assume you have a simple "hello world" Node.js application named app1 that you want to debug or test the changes you’ve made against its dependencies in a cluster using Telepresence.

Prerequisites


Step 1: Deploy app1 to Kubernetes

First, deploy xapp to your Kubernetes cluster in the dev namespace:


# Docker build and push app1 image
...
# Apply Kubernetes deploy manifests
kubectl apply -f app1.yaml --namespace dev

Verify xapp is running on Kubernetes:

kubectl get pods -n dev

You should see the app1 pod.

Step 2: Install Telepresence

Install the Telepresence CLI on your local machine. Telepresence has binaries available for the major operating systems - Linux, Mac, and Windows. To install on Mac via Homebrew, run the following commands:

# Apple silicon Macs
# Install via brew:
brew install datawire/blackbird/telepresence-arm64

For Linux and Windows, please check the official documentation for Telepresence.


Next, initialize Telepresence on your Kubernetes cluster:

# Install agent on Kubernetes
telepresence init

This installs the Telepresence daemon set on your cluster.

Step 3: Connect Telepresence

Now you can proxy the remote Kubernetes cluster to your local machine:

# Connect to Kubernetes cluster
telepresence connect

Step 4: Intercept Traffic to app1

Now intercept traffic to app1 and direct it to your local instance:

# Start intercepting app1
telepresence intercept app1 --port 8080

This will redirect traffic from the Kubernetes app1 to your local app1 on port 8080.

Operational Features of Telepresence

Telepresence provides a seamless development environment that accurately mirrors real-world Kubernetes clusters and services. Here are some of its key features:


  • Service simulation: Telepresence can intercept and simulate the behavior of any service in a Kubernetes cluster, including databases, queues, object stores, etc. This enables local development against real dependencies in a cluster.
  • Network management: Telepresence handles complex network routing like port forwarding, traffic redirection, and DNS rewriting out-of-the-box.
  • Volume mounting: Any remote storage like PVCs can be efficiently to your local filesystem. This provides access to live data volumes.
  • Container overrides: The containers running in a Kubernetes pod can be selectively overridden to use local docker images instead. Hot reloading is supported.
  • Injection modes: Telepresence supports multiple traffic injection modes like global traffic redirect and header-based filtering to adapt to different scenarios.

Performance Benefits

Telepresence can help you iterate and debug against a remote Kubernetes cluster with a roundtrip latency of <20ms. Here are some key performance benefits:


  • Low latency: Traffic is routed directly between your local machine and the remote cluster's ingress. This reduces roundtrip latency.
  • Fast file sync: Code changes sync quickly to pods via volume mounts, so you don't have to rebuild or redeploy images.
  • Live debugging: You can attach debuggers and other tools to your application's local process to identify and fix bugs more quickly.
  • Rapid iterations: The changes you make are reflected immediately, and this enables you to iterate on your application faster.

Comparison with Other Local Kubernetes Tools

Telepresence has many advantages over other local Kubernetes tools, including its ease of use, integration capabilities, and simulation accuracy. Let’s look at these advantages:


  • Ease of use: Telepresence is very easy to use. You can get started in minutes, even if you are not familiar with Kubernetes. Other tools can be more complex and time-consuming to set up and use.
  • Integration capabilities: Telepresence integrates with various development tools, including IDEs, debuggers, and CI/CD pipelines. This makes it easy to use Telepresence in your existing development workflow. Other tools may not integrate as well with your existing tools.
  • Accuracy of simulation: Telepresence provides a high degree of accuracy in simulating the behavior of real Kubernetes clusters. This is important for ensuring your code works the same way locally as it does in production. Other tools may not be as accurate in their simulation, leading to unexpected errors in your code.

Here is a table that summarizes the key differences between Telepresence and other local Kubernetes tools:


Get Started with Telepresence