Docsright arrowTelepresenceright arrow2.3right arrowTelepresence Quick Start - React

7 min • read

Telepresence Quick Start - React

Contents

In this guide we'll give you everything you need in a preconfigured demo cluster: the Telepresence CLI, a config file for connecting to your demo cluster, and code to run a cluster service locally.

1. Download the demo cluster archive

  1. Sign in to Ambassador Cloud to download your demo cluster archive. The archive contains all the tools and configurations you need to complete this guide.
  2. Extract the archive file, open the ambassador-demo-cluster folder, and run the installer script (the commands below might vary based on where your browser saves downloaded files).

  3. Confirm that your kubectl is configured to use the demo cluster by getting the status of the cluster nodes, you should see a single node named tpdemo-prod-...: kubectl get nodes

  4. Confirm that the Telepresence CLI is now installed (we expect to see the daemons are not running yet): telepresence status

2. Test Telepresence

Telepresence connects your local workstation to a remote Kubernetes cluster.

  1. Connect to the cluster (this requires root privileges and will ask for your password): telepresence connect

  2. Test that Telepresence is working properly by connecting to the Kubernetes API server: curl -ik https://kubernetes.default

3. Set up the sample 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.

  1. Clone the emojivoto app: git clone https://github.com/datawire/emojivoto.git

  2. Deploy the app to your cluster: kubectl apply -k emojivoto/kustomize/deployment

  3. Change the kubectl namespace: kubectl config set-context --current --namespace=emojivoto

  4. List the Services: kubectl get svc

  5. Since you’ve already connected Telepresence to your cluster, you can access the frontend service in your browser at http://web-app.emojivoto. This is the namespace qualified DNS name in the form of service.namespace.

4. Test app

  1. Vote for some emojis and see how the leaderboard changes.

  2. There is one emoji that causes an error when you vote for it. Vote for 🍩 and the leaderboard does not actually update. Also an error is shown on the browser dev console: GET http://web-svc.emojivoto:8080/api/vote?choice=:doughnut: 500 (Internal Server Error)

The error is on a backend service, so we can add an error page to notify the user while the bug is fixed.

5. Run a service on your laptop

Now start up the web-app service on your laptop. We'll then make a code change and intercept this service so that we can see the immediate results of a code change to the service.

  1. In a new terminal window, change into the repo directory and build the application:

    cd <cloned repo location>/emojivoto make web-app-local

  2. Change into the service's code directory and start the server:

    cd emojivoto-web-app yarn webpack serve

  3. Access the application at http://localhost:8080 and see how voting for the 🍩 is generating the same error as the application deployed in the cluster.

6. Make a code change

We’ve now set up a local development environment for the app. Next we'll make and locally test a code change to the app to improve the issue with voting for 🍩.

  1. In the terminal running webpack, stop the server with Ctrl+c.

  2. In your preferred editor open the file emojivoto/emojivoto-web-app/js/components/Vote.jsx and replace the render() function (lines 83 to the end) with this highlighted code snippet.

  3. Run webpack to fully recompile the code then start the server again:

    yarn webpack yarn webpack serve

  4. Reload the browser tab showing http://localhost:8080 and vote for 🍩. Notice how you see an error instead, improving the user experience.

7. 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 app to the version running locally instead.

  1. Start the intercept with the intercept command, setting the workload name (a Deployment in this case), namespace, and port: telepresence intercept web-app --namespace emojivoto --port 8080

  2. Go to the frontend service again in your browser at http://web-app.emojivoto. Voting for 🍩 should now show an error message to the user.

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.