Telepresence allows developers to test applications locally that are deployed to Kubernetes clusters. It creates a network proxy between a local development environment and a pod running in the cluster, enabling local development and testing that reflects the cluster environment. Key features include deploying and debugging services locally without changing code in the cluster. The document provides an overview of Telepresence and examples for installing it and using it to swap a deployment for local development of both a Python HTTP server and Docker container-based application.
9. Features
With Telepresence, developers can:
Deploy a service locally in the same condition as a
Kubernetes cluster
Use any tool installed locally to test/debug/edit a
service
Swap a service running on a cluster for a local service
12. Install Telepresence
https://www.telepresence.io/reference/install
On Ubuntu, run the following:
$ curl -s https://packagecloud.io/install/repositories/→
datawireio/telepresence/script.deb.sh | sudo bash
$ sudo apt install --no-install-recommends telepresence
# Verify the Installation
$ telepresence --version
13. Quick Start
https://github.com/telepresenceio/telepresence
# Verify the connection to the Kubernetes cluster
$ kubectl get no
NAME STATUS ROLES AGE VERSION
aks-default-09796230-0 Ready agent 43h v1.13.12
aks-default-09796230-1 Ready agent 43h v1.13.12
# Start a shell that proxies connections to Kubernetes
# Needs to enter the sudo password
$ telepresence
15. Example
https://www.telepresence.io/tutorials/kubernetes
# Deploy a service in the Kubernetes cluster
$ kubectl apply -f hello-world-deploy.yaml
deployment.apps/hello-world created
$ kubectl expose deployment hello-world --type=LoadBalancer
--port=8000 --target-port=8000 --name=hello-world
service/hello-world exposed
$ kubectl get po | grep hello-world
hello-world-645b769fd4-pxh8l 1/1 Running 0 3m52s
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP
PORT(S) AGE
hello-world LoadBalancer 10.0.181.195 104.46.217.233
8000:31793/TCP 4m49s
16. Example
# Send a query to a service running in the cluster
$ export HELLOWORLD=http://104.46.217.233:8000
$ curl $HELLOWORLD
Hello, world!
or display in web browser
17. Example
# Set up a development environment
$ mkdir telepresence; cd telepresence
$ echo "hello from your laptop" > file.txt
$ ls
file.txt
# Test locally
$ python3 -m http.server 8001 &
[1] 47404
$ curl http://localhost:8001/file.txt
hello from your laptop
$ kill %1
18. Example
# Swap the deployment with Telepresence
$ telepresence --swap-deployment hello-world --expose 8000
--run python3 -m http.server 8000 &
# A pod is swapped
$ kubectl get po | grep hello-world
hello-world-7c2fc81aaad6400bae6c760f74be47cb-59db7d4c9b-7ll2r
1/1 Running 0 5m28s
# Send a query to a service
$ curl $HELLOWORLD/file.txt
hello from your laptop
or display in web browser
19. Example
# Finish swapping
# Kill Telepresence locally
$ fg
^C
# New pod is created
$ kubectl get po | grep hello-world
hello-world-645b769fd4-tvsr6 1/1 Running 0 8s
21. Example (Docker)
# Fix a dependency problem
$ git diff requirements.txt
diff --git a/requirements.txt b/requirements.txt
index a938e09..16b0f08 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,4 +3,4 @@ Flask==1.0.2
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.1
-Werkzeug==0.15.2
+Werkzeug==0.15.6
# Build a docker image
$ sudo docker build -t hello-dev .
22. Example (Docker)
$ sudo docker image ls | grep hello-dev
hello-dev latest 4ef6bfec0bdb 2 hours ago 122MB
# Swap a service for a docker container running locally
$ telepresence --swap-deployment hello-world --docker-run
--rm -it -v $(pwd):/usr/src/app hello-dev
$ curl http://104.46.217.233:8000
Hello, world!
# Modify server.py
$ sed -i.bak -e s/Hello/Greetings/ server.py
$ curl http://104.46.217.233:8000
Greetings, world!
23. Example (Docker)
# 2 docker containers are running locally
$ sudo docker container ls
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
e9fc5e0f7ddc hello-dev "python3 ./server.py"
8 minutes ago Up 8 minutes
telepresence-1573198861-6937146-39240
1851864adb52 datawire/telepresence-local:0.103 "/sbin/tini -v -- py…"
8 minutes ago Up 8 minutes 127.0.0.1:41695->38022/tcp
telepresence-1573198854-7027166-39240