Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Telepresence

Introduction to Telepresence

Slides for an in-house study meeting

Kyohei Mizumoto

November 08, 2019

More Decks by Kyohei Mizumoto

Other Decks in Technology


  1. Required Knowledge Basic knowledge of kubernetes Goals Understand: the concept

    of telepresence how to test application with Telepresence
  2. https://www.telepresence.io/ Local development against a remote Kubernetes cluster OSS hosted

    by CNCF The Sandbox project Enables developers to do fast and easy test/debug of a service What is Telepresence?
  3. 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
  4. How it works https://www.telepresence.io/discussion/how-it-works Telepresence builds a network-proxy between: a

    custom pod running inside a Kubernetes cluster a process running on your development machine
  5. 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
  6. 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
  7. Example $ cat hello-world-deploy.yaml apiVersion: apps/v1 kind: Deployment metadata: labels:

    app: hello-world name: hello-world spec: replicas: 1 selector: matchLabels: app: hello-world template: metadata: labels: app: hello-world spec: containers: - image: datawire/hello-world name: hello-world ports: - containerPort: 8000
  8. 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 8000:31793/TCP 4m49s
  9. Example # Send a query to a service running in

    the cluster $ export HELLOWORLD= $ curl $HELLOWORLD Hello, world! or display in web browser
  10. 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
  11. 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
  12. 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
  13. Example (Docker) https://www.telepresence.io/tutorials/docker # Get a sample from GitHub $

    git clone https://github.com/datawire/hello-world $ cd hello-world $ ls Dockerfile LICENSE README.md requirements.txt server.py
  14. 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 .
  15. 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 Hello, world! # Modify server.py $ sed -i.bak -e s/Hello/Greetings/ server.py $ curl Greetings, world!
  16. 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>38022/tcp telepresence-1573198854-7027166-39240