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, MICROSERVICES

Go & Kubernetes: Rapidly Developing Golang Microservices

Jake Beck
April 9, 2024 | 7 min read

Build a cloud development environment with Telepresence & Golang

Kubernetes is a container orchestration platform that enables its users to deploy and scale their microservice applications at any scale, from one service to thousands of services. However, unleashing the power of Kubernetes is often more complicated than it may initially seem; the learning curve for application developers is particularly steep. Knowing what to do is just half the battle; then, you have to choose the best tools for the job. So, how do Go developers create a development workflow on Kubernetes that is fast and effective?

Build a cloud development environment with Golang & Telepresence


Application developers face two unique challenges when trying to create productive development workflows on Kubernetes:

  1. Most development workflows are optimized for local development, whereas Kubernetes applications are designed to be cloud-native.
  2. As Kubernetes applications evolve into complex microservice architectures, the development environments also become more complex. Every microservice adds additional dependencies, and these services quickly start to require more resources than are typically available in a local development environment.

In this tutorial, we’ll set up a development environment for Kubernetes and make a change to a Golang microservice. Normally, to develop locally, we’d have to wait for a container build, push it to a registry, and deploy it to see the effect of our code change. Instead, we’ll use Telepresence to see the results of our change instantly.

Step 1: Deploy a Sample Microservices Application

For our example, we'll make code changes to a Go service that operates between a resource-intensive Java service and a large datastore. We'll begin by deploying a sample microservice application consisting of 3 services:

  • VeryLargeJavaService: A memory-intensive service written in Java, responsible for generating the front-end graphics and web pages for our application.
  • DataProcessingService: A Golang service that manages requests for information between the VeryLargeJavaService and the VeryLargeDataStore.
  • VeryLargeDataStore: A large datastore service that contains the sample data for our Edgey Corp store.

Note: The 'VeryLarge' descriptor is used to emphasize that your local environment may not have sufficient CPU and RAM to handle these services, or you may prefer not to incur the additional overhead costs for every developer.

Go & Kubernetes

In this architecture diagram, you'll notice that requests from users are routed through an ingress controller to our services. For simplicity's sake, in this tutorial, we'll skip deploying an ingress controller. If you're ready to use Telepresence in your own setup and are looking for a simple way to set up an ingress controller, we recommend checking out the Edge Stack API Gateway.


Let’s deploy the sample application to your Kubernetes cluster:

kubectl apply -f

Step 2: Set up your local Go development environment

We’ll need a local development environment so that we can edit the `DataProcessingService` service. As you can see in the architecture diagram above, the `DataProcessingService` is dependent on both the `VeryLargeJavaService` and the `VeryLargeDataStore`, so in order to make a change to this service, we’ll have to interact with these other services as well. Let’s get started!

1. Clone the repository for this application from GitHub.

git clone https://github.com/datawire/edgey-corp-go.git

2. Change directories into the DataProcessingService

cd edgey-corp-go/DataProcessingService

3. Start the Go server:

go build main.go && ./main

4. See your service running!

10:23:41 app | Welcome to the DataProcessingGoService!

5. In another terminal window, curl localhost:3000/color to see that the service is returning blue.

$ curl localhost:3000/color

“Blue”

Step 3: Rapid Development with Telepresence

Instead of waiting for a container image to be built, pushed to a repository, and deployed to our Kubernetes cluster, we are going to use Telepresence. Telepresence creates a bidirectional network connection between your local development environment and the Kubernetes cluster to enable fast, efficient development.

1. Install Telepresence

# Mac OS X
sudo curl -fL https://app.getambassador.io/download/tel2/darwin/amd64/latest/telepresence -o /usr/local/bin/telepresence
#Linux
sudo curl -fL https://app.getambassador.io/download/tel2/linux/amd64/latest/telepresence -o /usr/local/bin/telepresence

2. Make the binary executable

$ sudo chmod a+x /usr/local/bin/telepresence

3. Test Telepresence by connecting to the remote cluster

$ telepresence connect

4. Send a request to the Kubernetes API server:

$ curl -ik https://kubernetes.default.svc.cluster.local
HTTP/1.1 401 Unauthorized
Cache-Control: no-cache, private
Content-Type: application/json
Www-Authenticate: Basic realm="kubernetes-master"
Date: Tue, 09 Feb 2021 23:21:51 GMT

Great! You’ve successfully configured Telepresence. Right now, Telepresence is intercepting the request you’re making to the Kubernetes API server, and routing over its direct connection to the cluster instead of over the Internet.

Step 4: Intercept Your Golang Service

An intercept is a routing rule for Telepresence. By creating an intercept, we can route traffic intended for the DataProcessingService in the cluster to the local version of the DataProcessingService running on port 3000 instead.

  1. Create the intercept
    telepresence intercept dataprocessingservice — port 3000
  2. Access the application directly with Telepresence. Visit http://verylargejavaservice:8080. Again, Telepresence is intercepting requests from your browser and routing them directly to the Kubernetes cluster.
  3. Now, we’ll make a code change. Open edgey-corp-go/DataProcessingService/main.go and change the value of the color variable from blue to orange. Save the file, stop the previous server instance and start it again with go build main.go && ./main.
  4. Reload the page in your browser and see how the color has changed from blue to orange!

That’s it! With Telepresence, we've seen how quickly we can transition from editing a local service to observing how these changes integrate with the larger application. Compared to the original process of building and deploying a container after every change, the time savings become increasingly apparent, especially as we make more complex changes or manage even larger services.

Learn More about Telepresence

Today, we’ve explored using Telepresence to rapidly iterate on a Golang microservice running in Kubernetes. Now, instead of being bogged down by slow local development processes, we can iterate swiftly, benefiting from an instant feedback loop and a productive cloud-native development environment.