mac安裝Telepresence
arch -arm64 brew install datawire/blackbird/telepresence-arm64 arch -arm64 brew upgrade datawire/blackbird/telepresence-arm64
# Install via brew:
brew install datawire/blackbird/telepresence-arm64
1.1透過Telepresence cmd安裝Traffic Manager
telepresence helm install
自定參數安裝
telepresence helm install --values values.yaml
查看版本
telepresence version
查看連接狀態
telepresence status
斷開連接
telepresence quit -s
1.2手動安裝traffic-manager
helm repo add datawire https://app.getambassador.io helm install traffic-manager -n ambassador datawire/telepresence --create-namespace kubectl get pod -n ambassador
移除traffic-manager
helm uninstall traffic-manager -n ambassador
2.登入Ambassador Cloud 負責生成隨機臨時域名,可通過域名來預覽攔截的服務。
telepresence login
3.連接到k8s集群
telepresence connect --mapped-namespaces default
列出可以存取的服務
telepresence list
4.本機打洞可以存取到clusterip
直接存取service的服務
curl http://http-service.default:80
直接存取clusterip的服務
curl http://10.76.13.203:80
直接存取podip的服務
curl http://10.72.3.31
5.攔裁集群內部的流量到本地
telepresence helm upgrade --team-mode telepresence intercept nginx-deployment --service=http-service --port=8080:80 -n default --preview-url=true
6.本地端開發程式將k8s上服務攔截流程至本地端的服務
k8s 起一個nginx並改寫index
deployment.apps/nginx created service/nginx exposed kubectl exec deployment/nginx -c nginx \ -- /bin/bash -c 'echo "nginx in K8s pod" > /usr/share/nginx/html/index.html'
本地docker 起一個nginx 並改寫index
docker run -d --name nginx -p 3001:80 nginx:1.20.2 docker exec nginx /bin/bash -c \ 'echo "nginx in local docker container" > /usr/share/nginx/html/index.html'
開始攔截流量
telepresence intercept nginx --namespace=default --port=3001:80
說明
k8s的nginx 80流量會導向目標本地開發端的docker 3001
開啟preview url
可以從ambassador的平台上管理已攔截的服務
#連接grpc服務
telepresence intercept add --service add --port 10121:grpc
7.移除所有設定
telepresence list telepresence leave nginx-deployment-default telepresence uninstall --everything kubectl delete svc,deploy -n ambassador traffic-manager