Introduction to Telepresence

0f5f81b602e9ad7f24e7ebe9b994d04c?s=47 kyo
November 08, 2019

Introduction to Telepresence

Slides for an in-house study meeting



November 08, 2019


  1. Introduction to Telepresence

  2. Kyohei Mizumoto(@kyohmizu) C# Software Engineer Interests Docker/Kubernetes Go Security whoami

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

    of telepresence how to test application with Telepresence
  4. Contents Overview What is Telepresence? Features Get Started Install Telepresence

    Examples (Demo)
  5. Overview

  6. 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?
  7. CNCF Landscape

  8. CNCF Landscape

  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
  10. How it works Telepresence builds a network-proxy between: a

    custom pod running inside a Kubernetes cluster a process running on your development machine
  11. Get Started

  12. Install Telepresence On Ubuntu, run the following: $ curl

    -s→ datawireio/telepresence/ | sudo bash $ sudo apt install --no-install-recommends telepresence # Verify the Installation $ telepresence --version
  13. Quick Start # 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
  14. 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
  15. Example # 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
  16. Example # Send a query to a service running in

    the cluster $ export HELLOWORLD= $ 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
  20. Example (Docker) # Get a sample from GitHub $

    git clone $ cd hello-world $ ls Dockerfile LICENSE requirements.txt
  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 Hello, world! # Modify $ sed -i.bak -e s/Hello/Greetings/ $ curl 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 ./" 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
  24. Links Official Docs GitHub Book

  25. Thank you!