and set up
to use a Kubernetes cluster, preferably an empty test cluster. This
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. Download the latest binary (~50 MB):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
# Intel Macs# Install via brew:brew install datawire/blackbird/telepresence# OR install manually:# 1. Download the latest binary (~60 MB):sudo curl -fL https://app.getambassador.io/download/tel2/darwin/amd64/latest/telepresence -o /usr/local/bin/telepresence# 2. Make the binary executable:sudo chmod a+x /usr/local/bin/telepresence# Apple silicon Macs# Install via brew:brew install datawire/blackbird/telepresence-arm64# OR Install manually:# 1. Download the latest binary (~60 MB):sudo curl -fL https://app.getambassador.io/download/tel2/darwin/arm64/latest/telepresence -o /usr/local/bin/telepresence# 2. Make the binary executable:sudo chmod a+x /usr/local/bin/telepresence
# Windows is in Developer Preview, here is how you can install it:# Make sure you run the following from Powershell as Administrator# 1. Download the latest windows zip containing telepresence.exe and its dependencies (~50 MB):curl -fL https://app.getambassador.io/download/tel2/windows/amd64/latest/telepresence.zip -o telepresence.zip# 2. Unzip the zip file to a suitable directory + cleanup zipExpand-Archive -Path telepresence.zipRemove-Item 'telepresence.zip'cd telepresence# 3. Run the install-telepresence.ps1 to install telepresence's dependencies. It will install telepresence to# C:\telepresence by default, but you can specify a custom path $path with -Path $pathSet-ExecutionPolicy Bypass -Scope Process.\install-telepresence.ps1# 4. Remove the unzipped directorycd ..Remove-Item telepresence# 5. Close your current Powershell and open a new one. Telepresence should now be usable as telepresence.exe
Telepresence connects your local workstation to a remote Kubernetes cluster.
Connect to the cluster:
telepresence connectTerminal$ telepresence connectLaunching Telepresence Daemon...Connected to context default (https://<cluster-public-IP>)
Test that Telepresence is working properly by connecting to the Kubernetes API server:
curl -ik https://kubernetes.defaultTerminal$ curl -ik https://kubernetes.defaultHTTP/1.1 401 UnauthorizedCache-Control: no-cache, privateContent-Type: application/jsonWww-Authenticate: Basic realm="kubernetes-master"Date: Tue, 09 Feb 2021 23:21:51 GMTContent-Length: 165...
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-python-fastapi/main/k8s-config/edgey-corp-web-app-no-mapping.yamlTerminal$ kubectl apply -f https://raw.githubusercontent.com/datawire/edgey-corp-python-fastapi/main/k8s-config/edgey-corp-web-app-no-mapping.yamldeployment.apps/dataprocessingservice createdservice/dataprocessingservice created...
Give your cluster a few moments to deploy the sample application.
kubectl get podsto check the status of your pods:Terminal$ kubectl get podsNAME READY STATUS RESTARTS AGEverylargedatastore-855c8b8789-z8nhs 1/1 Running 0 78sverylargejavaservice-7dfddbc95c-696br 1/1 Running 0 78sdataprocessingservice-5f6bfdcf7b-qvd27 1/1 Running 0 79s
Once all the pods are in a
Runningstate, 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.
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-python-fastapi.gitTerminal$ git clone https://github.com/datawire/edgey-corp-python-fastapi.gitCloning into 'edgey-corp-python-fastapi'...remote: Enumerating objects: 441, done....
Change into the repo directory, then into DataProcessingService:
Install the dependencies and start the Python server. Python 2.x:
pip install fastapi uvicorn requests && python app.pyPython 3.x:
pip3 install fastapi uvicorn requests && python3 app.pyTerminal$ pip install fastapi uvicorn requests && python app.pyCollecting fastapi...Application startup complete.
In a new terminal window, curl the service running locally to confirm it’s set to blue:
curl localhost:3000/colorTerminal$ curl localhost:3000/color"blue"
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
interceptcommand, setting the service name and port:
telepresence intercept dataprocessingservice --port 3000Terminal$ telepresence intercept dataprocessingservice --port 3000Using Deployment dataprocessingserviceinterceptedIntercept name: dataprocessingserviceState : ACTIVEWorkload kind : DeploymentDestination : 127.0.0.1:3000Intercepting : all TCP connections
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.
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.
edgey-corp-python-fastapi/DataProcessingService/app.pyin your editor and change
DEFAULT_COLORon line 17 from
orange. Save the file and the Python server will auto reload.
Now, visit http://verylargejavaservice:8080 again in your browser. You will now see the orange elements in the application.
Create a personal intercept with a preview URL; meaning that 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:Terminal$ telepresence loginLaunching browser authentication flow...<web browser opens, log in and choose your organization>Login successful.
If you are in an environment where Telepresence cannot launch a local browser for you to interact with, you will need to pass the
Start the intercept again:
telepresence intercept dataprocessingservice --port 3000You will be asked for your ingress layer 3 address; specify the front end service:
verylargejavaservice.defaultThen when asked for the port, type
8080, for "use TLS", type
nand finally confirm the layer 5 hostname.shell$ telepresence intercept dataprocessingservice --port 3000To create a preview URL, telepresence needs to know how requests enteryour cluster. Please Select the ingress to use.1/4: What's your ingress' IP address?You may use an IP address or a DNS name (this is usually a"service.namespace" DNS name).[default: dataprocessingservice.default]: verylargejavaservice.default2/4: What's your ingress' TCP port number?[default: 80]: 80803/4: Does that TCP port on your ingress use TLS (as opposed to cleartext)?[default: n]:4/4: If required by your ingress, specify a different hostname(TLS-SNI, HTTP "Host" header) to be used in requests.[default: verylargejavaservice.default]:Using Deployment dataprocessingserviceinterceptedIntercept name : dataprocessingserviceState : ACTIVEWorkload kind : DeploymentDestination : 127.0.0.1:3000Intercepting : HTTP requests that match all of:header("x-telepresence-intercept-id") ~= regexp("86cb4a70-c7e1-1138-89c2-d8fed7a46cae:dataprocessingservice")Preview URL : https://<random-subdomain>.preview.edgestack.meLayer 5 Hostname: verylargejavaservice.default
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.
Go again to http://verylargejavaservice:8080 and 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!
Use preview URLS to collaborate with your colleagues and others outside of your organization.
While connected to the cluster, your laptop can interact with services as if it was another pod in the cluster.
Learn more about uses cases and the technical implementation of Telepresence.