DocsTelepresence
1.0
Go support
Go support
In this howto you'll learn how to use Telepresence with a Go program.
Because of the way Go is implemented you will need to use --method vpn-tcp
with telepresence
.
A Go program talking to Kubernetes
First, start a web server inside Kubernetes and expose it via a service:
Next, install a neat little Go program called wuzz, an interactive HTTP client.
Now we'll see how we can use wuzz to interact with a remote Kubernetes cluster.
telepresence
will create a new Deployment
inside Kubernetes that will act as a proxy, and then communication from the wuzz
subprocess it runs will be forwarded to the cluster:
Important: Go programs will not work with --method inject-tcp
option.
The wuzz
UI will appear with the URL http://hello-world:8000/
.
Hit Enter and you should see the "Hello, World!" response from the Kubernetes service.
You can also interact with the Kubernetes API - change the URL to https://kubernetes/
(but typically you'll have problems with the custom certificate authority.)
Kubernetes talks to a Go program
You can also run a Go program as a local server and have requests to your Kubernetes Deployment
forwarded to that process.
This is just the same as the example covered in the tutorial except that you use --method vpn-tcp
, and run a Go process instead of a Python process.
For example, if you have a Deployment
called myservice
running in Kubernetes and listening on port 8080, you can temporarily swap it out for a local process and have traffic forwarded to your laptop:
Now requests to that remote Deployment
will be routed to the yourgoserver
process running on your machine.
You can learn more about the differences between --new-deployment
and --swap-deployment
in the relevant reference documentation.