Slide 1

Slide 1 text

Introduction to Telepresence

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Required Knowledge Basic knowledge of kubernetes Goals Understand: the concept of telepresence how to test application with Telepresence

Slide 4

Slide 4 text

Contents Overview What is Telepresence? Features Get Started Install Telepresence Examples (Demo)

Slide 5

Slide 5 text

Overview

Slide 6

Slide 6 text

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?

Slide 7

Slide 7 text

CNCF Landscape https://landscape.cncf.io/images/landscape.png

Slide 8

Slide 8 text

CNCF Landscape

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Get Started

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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 .

Slide 22

Slide 22 text

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!

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

Links Official https://www.telepresence.io/ Docs https://www.telepresence.io/discussion/overview/ GitHub https://github.com/telepresenceio/telepresence Book https://ktdkt.booth.pm/items/1574892

Slide 25

Slide 25 text

Thank you!