DocsTelepresence
2.3
Telepresence Quick Start - Go
Telepresence Quick Start - Go
Contents
Prerequisites
You’ll need kubectl
or oc
installed
and set up
(Linux /
macOS /
Windows)
to use a Kubernetes cluster, preferably an empty test cluster. This
document uses kubectl
in all example commands, but OpenShift
users should have no problem substituting in the oc
command instead.
If you have used Telepresence previously, please first reset your Telepresence deployment with:
telepresence uninstall --everything
.
1. Install the Telepresence CLI
GNU/Linux
macOS
2. Test Telepresence
Telepresence connects your local workstation to a remote Kubernetes cluster.
Connect to the cluster:
telepresence connect
Test that Telepresence is working properly by connecting to the Kubernetes API server:
curl -ik https://kubernetes.default
3. Install a sample Go application
Your local workstation may not have the compute or memory resources necessary to run all the services in a multi-service application. In this example, we’ll show you how Telepresence can give you a fast development loop, even in this situation.
Start by installing a sample application that consists of multiple services:
kubectl apply -f https://raw.githubusercontent.com/datawire/edgey-corp-go/main/k8s-config/edgey-corp-web-app-no-mapping.yaml
Give your cluster a few moments to deploy the sample application.
Use
kubectl get pods
to check the status of your pods:Once all the pods are in a
Running
state, go to the frontend service in your browser at http://verylargejavaservice.default:8080.You should see the EdgyCorp WebApp with a green title and green pod in the diagram.
4. Set up a local development environment
You will now download the repo containing the services' code and run the DataProcessingService service locally. This version of the code has the UI color set to blue instead of green.
Clone the web app’s GitHub repo:
git clone https://github.com/datawire/edgey-corp-go.git
Change into the repo directory, then into DataProcessingService:
cd edgey-corp-go/DataProcessingService/
You will use Fresh to support auto reloading of the Go server, which we'll use later. Confirm it is installed by running:
go get github.com/pilu/fresh
Then start the Go server:$GOPATH/bin/fresh
In a new terminal window, curl the service running locally to confirm it’s set to blue:
curl localhost:3000/color
5. Intercept all traffic to the service
Next, we’ll create an intercept. An intercept is a rule that tells Telepresence where to send traffic. In this example, we will send all traffic destined for the DataProcessingService to the version of the DataProcessingService running locally instead:
Start the intercept with the
intercept
command, setting the service name and port:telepresence intercept dataprocessingservice --port 3000
Go to the frontend service again in your browser. Since the service is now intercepted it can be reached directly by its service name at http://verylargejavaservice:8080. You will now see the blue elements in the app.
6. Make a code change
We’ve now set up a local development environment for the DataProcessingService, and we’ve created an intercept that sends traffic in the cluster to our local environment. We can now combine these two concepts to show how we can quickly make and test changes.
Open
edgey-corp-go/DataProcessingService/main.go
in your editor and changevar color string
fromblue
toorange
. Save the file and the Go server will auto reload.Now, visit http://verylargejavaservice:8080 again in your browser. You will now see the orange elements in the application.
7. Create a Preview URL
Create preview URLs to do selective intercepts, meaning only traffic coming from the preview URL will be intercepted, so you can easily share the services you’re working on with your teammates.
Clean up your previous intercept by removing it:
telepresence leave dataprocessingservice
Log in to Ambassador Cloud, a web interface for managing and sharing preview URLs:
If you are in an environment where Telepresence cannot launch a local browser for you to interact with, you will need to pass the
--apikey
flag totelepresence login
.Start the intercept again:
telepresence intercept dataprocessingservice --port 3000
You will be asked for your ingress layer 3 address; specify the front end service:verylargejavaservice.default
Then when asked for the port, type8080
, for "use TLS", typen
and finally confirm the layer 5 hostname.Wait a moment for the intercept to start; it will also output a preview URL. Go to this URL in your browser, it will be the orange version of the app.
Now go again to http://verylargejavaservice:8080, it’s still green.
Normal traffic coming to your app gets the green cluster service, but traffic coming from the preview URL goes to your laptop and gets the orange local service!
What's Next?
Collaborating
Use personal intercepts to get specific requests when working with colleagues.
Outbound Sessions
Control what your laptop can reach in the cluster while connected.
Telepresence for Docker Compose
Develop in a hybrid local/cluster environment using Telepresence for Docker Compose.