ããã«ã¡ã¯ãNecoããã¸ã§ã¯ãã®satã§ãã
æ¬è¨äºã§ã¯Kubernetes(以ä¸K8sã¨è¨è¼)ã¢ããªã±ã¼ã·ã§ã³(以éã¢ããªã¨è¨è¼)ã®éçºãé«éåãããã¼ã«ãTelepresenceãç´¹ä»ãã¾ãã
æåã«çµè«ãæ¸ãã¦ããã¨ãTelepresenceã¯æ¬¡ã®ãããªãã¼ã«ã§ãã
- ãã¼ã«ã«ã§åãããã»ã¹ãã³ã³ãããk8sã¯ã©ã¹ã¿ã®ä¸ã§åããã
- æ¢åã®Deploymentå ã®ã³ã³ãããä¸è¨ãã¼ã«ã«ã³ã³ããã§ç½®ãæãããã
- ãã¹ãããããã°ã®ããã«ãã¡ãã¡ã³ã³ããã¤ã¡ã¼ã¸ãã¬ã¸ã¹ããªã«push,ããããpullâ¦ã¨ããå¿ è¦ããªãã®ã§éçºé度ãä¸ãããã
Telepresenceã¯ç¾å¨Cloud Native Computing Foundationã®SandBoxããã¸ã§ã¯ãã§ãã
Telepresenceç»å ´ã®èæ¯
åç¯ã«ããã¦"éçºãé«éåãã"ã¨æ¸ãã¾ããããã¾ãã¯Telepresenceã使ããªãã¨ãã®éçºããããã°ã¯ã©ã®ããã«ãªã£ã¦ããã®ãã«ã¤ãã¦è¿°ã¹ã¾ããããã¢ããªãKubernetesã¯ã©ã¹ã¿ã«deployããã¦ããç¶æ ãåæç¶æ ã¨ããã¨ã次ã®ããã«ãªãã¾ãã
- ã¢ããªã®ã½ã¼ã¹ã«å¤æ´ãå ãã
- ã¢ããªã®ã³ã³ããã¤ã¡ã¼ã¸ãä½ã
- Dockerhubãªã©ã®ã¬ã¸ã¹ããªã«ã³ã³ããã¤ã¡ã¼ã¸ãpushãã
- deploymentã®å¤æ´ã
kubectl set image
ãªã©ã«ãã£ã¦ã¢ããªãå¤æ´å¾ã®ã³ã³ããã¤ã¡ã¼ã¸ã使ãããã«ãã - ã¢ããªã®Podãå¤æ´å¾ã®ã³ã³ããã¤ã¡ã¼ã¸ã使ã£ã¦åèµ·åãã
ãã®ã¨ãã³ã³ããã¤ã¡ã¼ã¸ã®pushããPodã®åèµ·åã¾ã§ã«ã¯ãããªãã®æéå¾ ãããããããä¸åã½ã¼ã¹ãå¤æ´ãã¦ãããããåããã¾ã§ã®ãµã¤ã¯ã«ãé·ããªããã¡ã¨ããã®ãK8sã¢ããªéçºã®å¤§ããªåé¡ã§ããã³ã³ããã¤ã¡ã¼ã¸ã®ãµã¤ãºã大ããã»ã©ãã®ãµã¤ã¯ã«ã¯é·ããªãã¾ãããã®é¨åãé«éåãã¦ãããã®ãTelepresenceã§ãã
次ç¯ä»¥éã¯Telepresenceãã©ããããã®ãªã®ããå®éã«ä½¿ããªããç´¹ä»ãã¾ãã
ã¤ã³ã¹ãã¼ã«æ¹æ³
å ¬å¼ãµã¤ãã®æé ã«å¾ã£ã¦ã¤ã³ã¹ãã¼ã«ãã¾ããUbuntu 18.04ã®å ´åã¯æ¬¡ã®ã³ãã³ãã使ãã¾ãã
$ curl -s https://packagecloud.io/install/repositories/datawireio/telepresence/script.deb.sh | sudo bash $ sudo apt install --no-install-recommends telepresence
ãµã³ãã«1: ãã¼ã«ã«ã³ã³ãããK8sã¯ã©ã¹ã¿å ã§åãã
ã¾ãã¯Telepresenceã®åºæ¬æ©è½ã§ããããã¼ã«ã«ã³ã³ãããK8sã¯ã©ã¹ã¿å ã§åããæ¹æ³ã«ã¤ãã¦æ¸ãã¾ãã
step 1: K8sã¯ã©ã¹ã¿ã®ä½æ
kindã使ã£ã¦K8sã¯ã©ã¹ã¿ãä½ãã¾ããããã§ã¯ã¯ã©ã¹ã¿ã®ä½æã«kindã使ãã¾ããkindã®ã¤ã³ã¹ãã¼ã«æ¹æ³ã«ã¤ãã¦ã¯ä»¥åç´¹ä»ããkindã«ã¤ãã¦ã®è¨äºãåç §ãã ããã
$ kind create cluster $ export KUBECONFIG="$(kind get kubeconfig-path)"
step 2: ãµã¼ãã¹ãdeploy
以ä¸ã®hello.yamlã¨ãããããã§ã¹ãã使ã£ã¦hellow-world-web-serverã¨ããã¢ããªãã¯ã©ã¹ã¿ä¸ã§åããã¾ãã
apiVersion: apps/v1 kind: Deployment metadata: name: hello-world-web-server spec: replicas: 1 selector: matchLabels: app: hello-world-web-server template: metadata: labels: app: hello-world-web-server spec: containers: - name: hello-world-web-server image: quay.io/satoru_takeuchi/hello-world-web-server:0.1 ports: - containerPort: 8000 --- apiVersion: v1 kind: Service metadata: name: hello-world-web-server spec: selector: app: hello-world-web-server ports: - protocol: TCP port: 8000 targetPort: 8000
ããã¯port 8000ã«ã¢ã¯ã»ã¹ããã¨"hello, world!"ã¨ããæååãè¿ãã¨ããã¢ããªã§ãã
次ã®ããã«deployããä¸ã§serviceåãã¾ãã
$ kubectl create -f hello.yaml ... $ kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-world-web-server ClusterIP 10.109.22.168 <none> 8000/TCP 37s kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 104m $
ããã¾ã§ã§ãã¯ã©ã¹ã¿å
é¨ããã¯ãã®ã¢ããªã«hello-world-web-server
ã¨ããååããªãã10.109.22.168
ã«ãã£ã¦ã¢ã¯ã»ã¹ã§ãã¾ãããã®ä¸æ¹ã§ãã®è¨å®ã§ã¯ã¯ã©ã¹ã¿ã®å¤ããã¯ã¢ã¯ã»ã¹ã§ãã¾ããã
step 3: telepresenceã«ãã£ã¦ã¯ã©ã¹ã¿ä¸ã§ãã¼ã«ã«ããã»ã¹/ã³ã³ãããå®è¡
ãã¼ã«ã«ããã»ã¹curlããhello-world-web-serverã®port 8000ã«ã¢ã¯ã»ã¹ãã¦ã¿ã¾ãã
$ curl http://hello-world-web-server:8000 curl: (6) Could not resolve host: hello-world-web-server $
ã¯ã©ã¹ã¿ã®å¤ããã®ã¢ã¯ã»ã¹ãªã®ã§å¤±æãã¾ãããããã¯æ³å®éãã®åãã§ãã
ç¶ãã¦Telepresenceãä»ãã¦åãããã»ã¹ãåä½ãããã¨ã©ããªãã§ããããã
$ telepresence --run curl http://hello-world-web-server:8000 T: Starting proxy with method 'vpn-tcp', which has the following limitations: All processes are affected, only one telepresence can 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 list of method limitations see T: 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-1562306285-3227046-17962 T: No traffic is being forwarded from the remote Deployment to your local machine. You can use the --expose option to specify which ports you want to forward. T: Setup complete. Launching your command. Hello world! â ãµã¼ãã¹ã«ã¢ã¯ã»ã¹ã§ãã¦ãã T: Your process has exited. T: Exit cleanup in progress T: Cleaning up Deployment telepresence-1562306285-3227046-17962
ã¢ã¯ã»ã¹ãæåãã¾ãããæ¬ç¯åé ã§è¿°ã¹ãããã«Telepresenceã«ãã£ã¦ãã¼ã«ã«ç°å¢ã«ããããã»ã¹(ããã³å¾è¿°ããã³ã³ãã)ãã¯ã©ã¹ã¿å ã«ãããã®ããã«æ±ãããã¨ããããã¾ããã
ãã®ã¨ãTelepresenceã¯å®è¡ãã°ãtelepresence.log
ã«åºåãã¾ãã
åæ§ã«ã¯ã©ã¹ã¿å ã§shellãåãããã¨ãã§ãã¾ãã
$ telepresence --run-shell T: Starting proxy with method 'vpn-tcp', which has the following limitations: All processes are affected, only one telepresence can 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 list of method limitations see T: 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-1562306514-402358-21367 T: No traffic is being forwarded from the remote Deployment to your local machine. You can use the --expose option to specify which ports you want to forward. T: Setup complete. Launching your command. $ curl http://hello-world-web-server:8000 Hello world!
shellãå«ãããã»ã¹ã ãã§ã¯ãªããã¯ã©ã¹ã¿å ã§ã³ã³ãããåãããã¨ãã§ãã¾ãã
$ telepresence --docker-run -it --rm pstauffer/curl curl http://hello-world-web-server:8000 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-1562306747-6756666-25541 T: No traffic is being forwarded from the remote Deployment to your local machine. You can use the --expose option to specify which ports you want to forward. T: Setup complete. Launching your container. Hello world! T: Your process has exited. T: Exit cleanup in progress T: Cleaning up Deployment telepresence-1562306747-6756666-25541 $
ãµã³ãã«2: deploymentå ã®ã³ã³ããããã¼ã«ã«ç°å¢ã§åä½ããã³ã³ããã§å·®ãæ¿ãã
åæç¶æ ã¯ãµã³ãã«1ã®çµäºæç¹ã§ããã¨ãã¾ãã
é常ã¯å®è¡ä¸ã®ã¢ããªã®ã³ã³ãããå·®ãæ¿ããã«ã¯åè¿°ã®ããã«ã³ã³ããã¤ã¡ã¼ã¸ããã«ãããå¾ã«æ¬¡ã®ãããªæé ãå¿ è¦ã§ãã
- ã³ã³ããã¤ã¡ã¼ã¸ãã¬ã¸ã¹ããªã«push
- deploymentãæ¸ãæã or
kubectl set image
ã«ãã£ã¦ã¢ããªã使ãã³ã³ãããå¤æ´ãã - ã¢ããªã®podãåèµ·åãã¦ã³ã³ããããªãã¼ã
ããã«å¯¾ãã¦Telepresenceã使ãå ´åã¯ã¢ããªã使ãã³ã³ããããã¼ã«ã«ã§åããã®ã«å·®ãæ¿ãããã¾ããå¥ã®ãããããããã¨ä¸è¨ã®æé ããã¹ã¦çç¥ã§ãã¾ãã
step 1: å¤æ´çã®ã³ã³ããããã«ããã
step 1.1: ã½ã¼ã¹ã®æºå
hello-world-web-serverã³ã³ããã®ã½ã¼ã¹ããã¦ã³ãã¼ããã¦hello-world-web-server:0.1
ã«ç¸å½ãããã¼ã¸ã§ã³ããã§ãã¯ã¢ã¦ããã¾ãã
$ git clone https://github.com/satoru-takeuchi/hello-world-web-server.git ... $ cd hello-world-web-server $ git checkout v0.1 ... $
step 1.2: ã¡ãã»ã¼ã¸ãå·®ãæ¿ã
ã¢ããªã®ã½ã¼ã¹ã³ã¼ãå¤æ´ã«ãã£ã¦"Hello world!"ã¨ããã¡ãã»ã¼ã¸ã"Hello telepresence!"ã§å·®ãæ¿ãã¾ãã
$ cat index.html Hello world! $ sed -i -e s/world/Telepresence/ index.html $ cat index.html Hello Telepresence! $
step 1.3: ã³ã³ããã¤ã¡ã¼ã¸ããã«ã
次ã®ããã«ã³ã³ããã¤ã¡ã¼ã¸ããã«ããã¾ãã
$ docker build -t hello-world-web-server:dev . ... Successfully tagged hello-world-web-server:dev ... $
step 2: ã¢ããªå ã®ã³ã³ããããã¼ã«ã«ã®ãã®ã¨å·®ãæ¿ãã
次ã®ãããªã³ãã³ããçºè¡ãã¾ãã
$ telepresence --swap-deployment hello-world-web-server --docker-run --rm -it hello-world-web-server:dev 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-web-server with a proxy T: Forwarding remote port 8000 to local port 8000. T: Setup complete. Launching your container. Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ... ...
ãã®å¾ãå¥ç«¯æ«ã§k8sã¯ã©ã¹ã¿å ããhello worldãµã¼ãã¹ã«ã¢ã¯ã»ã¹ããã¨å·®ãæ¿ãå¾ã®ã³ã³ããã使ã£ã¦ããã®ããããã¾ãã
$ export KUBECONFIG="$(kind get kubeconfig-path)" $ kubectl run access-hello-world-web-server -it --rm --image=pstauffer/curl --restart=Never -- curl http://hello-world-web-server:8000 Hello Telepresence! â ã¡ãã»ã¼ã¸ãå¤æ´ããã¦ãã pod "access-hello-world-web-server" deleted $
ä¸å³ã«ããã¦ãé常ã¯ç¹ç·ã®ç¢å°ã®ããã«ã¢ã¯ã»ã¹ããã¯ãã§ãããTelepresenceã«ãã£ã¦å®ç·ã®ç¢å°ã®ããã«ã¢ã¯ã»ã¹ããããã«ãªãã¾ãã
æå¾ã«ç°å¢ã綺éºã«ãã¦ããã¾ãããã
$ kubectl delete -f hello.yaml
ãµã³ãã«3: è¤æ°ã³ã³ããããæãdeploymentå ã®ã³ã³ããã®å·®ãæ¿ã
ãµã³ãã«2ã®æå¾ã®ç¶æ ã§æ¬¡ã«ç¤ºãmulti-container.yamlã¨ãããããã§ã¹ããèªã¿è¾¼ã¿ã¾ãããã®Deploymentã®ä¸ã«ã¯hello.yamlã®å ´åã«å ãã¦sleepãç¶ããdummyã¨ããã³ã³ãããåå¨ãã¾ãã
apiVersion: apps/v1 kind: Deployment metadata: name: hello-world-web-server spec: replicas: 1 selector: matchLabels: app: hello-world-web-server template: metadata: labels: app: hello-world-web-server spec: containers: - name: hello-world-web-server image: quay.io/satoru_takeuchi/hello-world-web-server:0.1 ports: - containerPort: 8000 containers: - name: dummy image: quay.io/satoru_takeuchi/hello-world-web-server:0.1 command: ["/bin/sh"] args: ["-c", "while sleep 1000 ; do : ; done"] --- apiVersion: v1 kind: Service metadata: name: hello-world-web-server spec: selector: app: hello-world-web-server ports: - protocol: TCP port: 8000 targetPort: 8000
Telepresenceã¯ã³ã³ãããç¹å®ããããã«deployemtåãæå®ããéã«<deploymentå>:<ã³ã³ããå>
ã¨ããæ¸ãæ¹ãã§ãã¾ãã
$ kubectl create -f multi-container.yaml ... $ telepresence --swap-deployment hello-world-web-server:hello-world-web-server --docker-run --rm -it hello-world-web-server:dev ... Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
ããã§å¥ç«¯æ«ããhello-world-web-serverã«ã¢ã¯ã»ã¹ããã¨å¤æ´å¾ã®ã³ã³ãããè¦ãã¾ãã
$ kubectl run access-hello-world-web-server -it --rm --image=pstauffer/curl --restart=Never -- curl http://hello-world-web-server:8000 Hello Telepresence! â ã¡ãã»ã¼ã¸ãå¤ãã£ã¦ãã pod "access-hello-world-web-server" deleted
æå¾ã«ç°å¢ã綺éºã«ãã¦ããã¾ãã
$ kubectl delete -f multi-container.yaml
ãããã«
å¼ç¤¾ã«ãããTelepresenceãç¨ä¾ãä¸ã¤ç´¹ä»ãã¦ããã¾ããå¼ç¤¾ã«ã¯æ¥æ¬å½å ã®ã¤ã³ãã©åºç¤ãå·æ°ããNecoããã¸ã§ã¯ãã¨ã¯å¥ã«ãUSåãã®ã¤ã³ãã©åºç¤ãå·æ°ããYakumoã¨ããããã¸ã§ã¯ããããã¾ãããã¡ãã§ãTelepresenceããã§ã«æ´»çºã«ä½¿ããã¦ãã¾ãã
Yakumoã§æä¾ãããkintoneã¯å½å ã®ãã¼ã¿ã»ã³ã¿ã¼ã§æä¾ããã¦ããkintoneã¨æ§æãç°ãªããããAWS移è¡ã¨åæã«kintoneã®ãã¹ãã±ã¼ã¹ã®ä¿®æ£ãçºçãã¾ããYakumoä¸ã§ã®kintoneã®ãã¹ãã¯Kubernetes Jobã¨ãã¦å®è¡ãã¦ãã¾ãããã®ãã¹ãã®ãã¹ãã±ã¼ã¹æ°ã¯æ°åã«ãåã¶ã®ã§ããã¹ããä¿®æ£ãã度ã«Jobããããã¤ãã¦ãã¨ç¢ºèªã«æéããããã¾ããããã§Yakumoãã¼ã ã§ã¯Telepresenceã使ã£ã¦ç¹å®ã®ãã¹ãã±ã¼ã¹ã ãããã¼ã«ã«ç°å¢ã§å®è¡ãããã¨ã«ãã£ã¦ãå¾ ã¡æéãå¤§å¹ ã«åæ¸ã§ãã¦ãã¾ãã
Necoããã¸ã§ã¯ãã«ããã¦ãéçºãé²ãã«ãããã£ã¦k8sã¢ããªã®ãµã¤ãºãå¤ãããã¤ãããããã®ãµã¤ãºå¤§ãããªã£ã¦ãããã¨ã«ãããä»å¾ã¾ãã¾ãTelepresenceã使ãå ´é¢ãå¢ãã¦ããè¦è¾¼ã¿ã§ãã
æå¾ã«ãªãã¾ãããK8sã¢ããªã®éçºã«ããã¦æ¬è¨äºã§è¿°ã¹ããããªåé¡ããããã¦ããã¿ãªãã¾ã¯ããã²Telepresenceã試ãã¦ããã ãããã¨ãããã¾ãã