Testing with Telepresence and Docker

Get hands-on with demos

GoJava

Testing your microservices-based application becomes difficult when it can no longer be run locally due to resource requirements. Moving to the cloud for testing is a no-brainer, but how do you synchronize your local changes against your remote Kubernetes environment? Even with Docker Desktop making the container build-push-test cycle easy, this still takes time and introduces wasteful context switches for you as an engineer.

By using Telepresence with Docker, you get flexible remote development environments that work with your Docker toolchain so you can code and test faster for Kubernetes-based apps.

Get early access to the extension today:

  • Visit the Docker website and install Docker Desktop.
  • Read the Docker Desktop Extension for Telepresence docs here.
  • Need help with your Docker and Telepresence setup? Schedule a session with our team of experts here.

Traditional Way

  1. Code: Make changes to your app locally via IDE
  2. Build: Create container with code change: docker build
  3. Push: docker push
  4. Pause: wait for remote upload to remote registry
  5. Deploy: kubectl apply -f manifest.yaml (wait)
  6. Verify: Run tests against the staging cluster URL
  7. View: kubectl logs xyz -f
  8. Repeat: Identify new issue/bug and start this cycle again

Telepresence / Docker Way

  1. Code: Make changes to your app locally via IDE
  2. Build: Create container with code change: docker build
  3. Connect: Join your container’s network to the remote cluster: (push button)
  4. Verify: Use the auto-generated preview URL to view changes and run tests
  5. View: Access application logs locally via Docker Deskop UI or CLI e.g. docker logs
  6. Flow: Identify new issue/bug and begin fixing and verifying without repeating all the above steps

Try Telepresence & Docker with a sample app to see how fast your dev/test loop can be!

1. Enable and start your Docker Desktop Kubernetes cluster locally.

Install the Telepresence extension to Docker Desktop if you haven’t already.

2. Install the Emojivoto application in your local Docker Desktop cluster (we will use this to simulate a remote K8s cluster).

The Emojivoto application is a sample application that consists of three independent Kubernetes services: a frontend service (web) and two backend service (emoji and voting). Use the following command to apply the Emojivoto application to your cluster:

text
1kubectl apply -k github.com/BuoyantIO/emojivoto/kustomize/deployment

3. Start the web service in a single container with Docker.

In addition to running the entire application in the Kubernetes cluster, we'll also start a containerized version of the web service. This will simulate a local dev/test loop of the frontend. Create a file called docker-compose.yml and paste the following into that file:

yaml
1version: '3'
2services:
3 web:
4 image: buoyantio/emojivoto-web:v11
5 environment:
6 - WEB_PORT=8080
7 - EMOJISVC_HOST=emoji-svc.emojivoto:8080
8 - VOTINGSVC_HOST=voting-svc.emojivoto:8080
9 - INDEX_BUNDLE=dist/index_bundle.js
10 ports:
11 - "8080:8080"
12 network_mode: host

In your terminal, run docker compose up to start running the web service locally.

4. Using a test container, curl the API endpoint in Emojivoto and watch it fail (because it can’t access the backend cluster).

In a new terminal, we will test the Emojivoto app with another container. Run the following command: docker run -it --rm --network=host alpine. Then we’ll install curl: apk --no-cache add curl

Finally, curl localhost:8080/api/list and you should get an rpc error message because we are not connected to the backend cluster and cannot resolve the emoji or voting services:

text
1> docker run -it --rm --network=host alpine
2apk --no-cache add curl
3fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
4fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
5
6(1/5) Installing ca-certificates (20211220-r0)
7(2/5) Installing brotli-libs (1.0.9-r5)
8(3/5) Installing nghttp2-libs (1.46.0-r0)
9(4/5) Installing libcurl (7.80.0-r0)
10(5/5) Installing curl (7.80.0-r0)
11Executing busybox-1.34.1-r3.trigger
12Executing ca-certificates-20211220-r0.trigger
13OK: 8 MiB in 19 packages
14
15curl localhost:8080/api/list
16{"error":"rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing dial tcp: lookup emoji-svc on 192.168.65.5:53: no such host\""}

5. Run Telepresence connect via Docker Desktop.

Open Docker Desktop and click the Telepresence extension on the left-hand side. Click the blue “Connect” button. Copy and paste an API key from Ambassador Cloud if you haven’t done so already (https://app.getambassador.io/cloud/settings/licenses-api-keys).

Select the cluster you deployed the Emojivoto application to by selecting the appropriate Kubernetes Context from the menu. Click next and the extension will connect Telepresence to your local cluster.

6. Re-run the curl and watch this succeed.

Now let’s re-run the curl command. Instead of an error, the list of emojis should be returned indicating that we are connected to the remote cluster:

text
1/ # curl localhost:8080/api/list
2[{"shortcode":":joy:","unicode":"😂"},{"shortcode":":sunglasses:","unicode":"😎"},{"shortcode":":doughnut:","unicode":"🍩"},{"shortcode":":stuck_out_tongue_winking_eye:","unicode":"😜"},{"shortcode":":money_mouth_face:","unicode":"🤑"},{"shortcode":":flushed:","unicode":"😳"},{"shortcode":":mask:","unicode":"😷"},{"shortcode":":nerd_face:","unicode":"🤓"},{"shortcode":":ghost:","unicode":"👻"}

Let’s intercept traffic to the web service and reroute it to the Docker Compose instance by creating a Telepresence intercept. Select the emojivoto namespace and click the intercept button next to “web”. Set target port to 8080 and service port 80 then create the intercept.

After the intercept is created, you will see it listed in the UI. Click the nearby blue button with three dots to access your preview URL. Open this URL in your browser and you can interact with your local instance of the web service with its dependencies running in your Kubernetes cluster.

Congratulations, you've successfully created a Telepresence intercept and a sharable preview URL! Send this to your teammates and they will be able to see the results of your local service interacting with the Docker Desktop cluster.

Need setup help?

Get help with Docker, Kubernetes, and cloud technologies from our team of experts, with lunch & swag on us 🍕

SCHEDULE SESSION