Telepresenceを試してみたメモ。
大きくは3つの機能がある。
準備
手順にしたがってインストールする。
brew cask install osxfuse brew install datawire/blackbird/telepresence
Delpoymentの入れ替え
チュートリアル用にネームスペースを作る。
kubectl create ns tutorial kubens tutorial
サービスを起動する。
kubectl create deployment hello-world --image=datawire/hello-world kubectl expose deployment hello-world --type=LoadBalancer --port=8000
サービスの外部IPを取得する。
export HELLOWORLD="http://$(kubectl get service hello-world -o json | jq -r '.status.loadBalancer.ingress[].hostname'):8000"
アクセスできることを確認する。
$ curl ${HELLOWORLD}
Hello, world!
ローカルでpythonのHTTPサーバープロセスを立ち上げてテストする。
mkdir telepresence-test cd telepresence-test echo "hello from your laptop" > file.txt python3 -m http.server 8001
別ターミナルからアクセスする。
$ curl http://localhost:8001/file.txt hello from your laptop
アクセスできたらフォアグラウンドのプロセスは終了する。
同じようにプロセスを立ち上げて今度はクラスター上のDeploymentとスワップする。
telepresence --swap-deployment hello-world --expose 8000 \ --run python3 -m http.server 8000
T: How Telepresence uses sudo: https://www.telepresence.io/reference/install#dependencies T: Invoking sudo. Please enter your sudo password. Password: T: Starting proxy with method 'vpn-tcp', which has the following limitations: All processes are affected, only one telepresence can T: run per machine, and you can't use other VPNs. You may need to add cloud hosts and headless services with --also-proxy. For a full T: list of method limitations see https://telepresence.io/reference/methods.html T: Volumes are rooted at $TELEPRESENCE_ROOT. See https://telepresence.io/howto/volumes.html for details. T: Starting network proxy to cluster by swapping out Deployment hello-world with a proxy T: Forwarding remote port 8000 to local port 8000. T: Guessing that Services IP range is 172.20.0.0/16. Services started after this point will be inaccessible if are outside this range; T: restart telepresence if you can't access a new Service. T: Connected. Flushing DNS cache. T: Setup complete. Launching your command. Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
別のターミナルでアクセスする。
$ export HELLOWORLD="http://$(kubectl get service hello-world -o json | jq -r '.status.loadBalancer.ingress[].hostname'):8000" $ curl ${HELLOWORLD}/file.txt hello from your laptop
このとき、別のDeploymentが作られている。
$ k get deploy NAME READY UP-TO-DATE AVAILABLE AGE hello-world 0/0 0 0 20m hello-world-56acba6dff3d45298ca3642bfa98f9a6 1/1 1 1 16s
フォアグラウンドで起動していたtelepresenceプロセスを終了する。
クラスターとの接続
サービスを起動する。ClusterIPタイプのサービスなので外からはアクセスできない。
kubectl create deployment myservice --image=datawire/hello-world kubectl expose deployment myservice --port=8000
telepresence --run curl http://myservice:8000/
T: Starting proxy with method 'vpn-tcp', which has the following limitations: All processes are affected, only one telepresence can T: run per machine, and you can't use other VPNs. You may need to add cloud hosts and headless services with --also-proxy. For a T: full list of method limitations see https://telepresence.io/reference/methods.html T: Volumes are rooted at $TELEPRESENCE_ROOT. See https://telepresence.io/howto/volumes.html for details. T: Starting network proxy to cluster using new Deployment telepresence-1594111961-935412-10577 T: No traffic is being forwarded from the remote Deployment to your local machine. You can use the --expose option to specify which T: ports you want to forward. T: Connected. Flushing DNS cache. T: Setup complete. Launching your command. Hello, world! T: Your process has exited. T: Exit cleanup in progress T: Cleaning up Deployment telepresence-1594111961-935412-10577
これもこのタイミングでDeploymentが作成されて実行されている。環境変数はローカルで設定されているものと、Kubernetes Podに付与されるものが両方設定されている。