惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security Blog

Stray Episode

From OPC to NPC 如何手搓一辆公路车 PXE自动化无人值守安装Ubuntu 捡垃圾,H3C TX1801 plus路由器刷OpenWRT AI时代,人人都是架构师(bushi 捡垃圾,折腾一下HP 544+ FLR 老板,来杯IPA,像我生活一样苦的 偷一个ICC文件,把你的相机变哈苏 基于泰山派的 PiKVM 现代Python CRUD技术栈 电子佛曰:我看你是完全不懂哦 一个按键都被你玩出花——《节奏医生》 为什么学渣不喜欢上学 因为山就在那里,《Celeste蔚蓝》 只要开始摆烂,那我就是无敌的
使用Telepresence开发调试k8s应用
Windfarer · 2022-09-04 · via Stray Episode

简介

现在微服务的主流部署方式是用k8s,而微服务又是出了名的开发调试困难,这家名为ambassador的公司(他们也开发了知名的同名网关项目firmwarefirmwareambassador,现在改名叫emissary-ingress了),开发了这个叫Telepresence的工具,可以帮助开发者更方便的进行k8s环境下的应用开发,它能让你的本机直接访问到k8s集群内的服务,也可以将集群内的请求流量劫持到本机进行处理,这样就不需要在开发调试中反复进行构建镜像,推送镜像,部署服务的流程了,直接在本地一站式完成,比较方便。

telepresence-architecture.inline

安装

参考安装文档

主要分为两部分:

本机部分(安装teleprecense命令工具):
Linux直接安装二进制

# 1. Download the latest binary (~50 MB):
sudo curl -fL https://app.getambassador.io/download/tel2/linux/amd64/latest/telepresence -o /usr/local/bin/telepresence

# 2. Make the binary executable:
sudo chmod a+x /usr/local/bin/telepresence

MacOS用homebrew安装。

# Intel Macs

# Install via brew:
brew install datawire/blackbird/telepresence

# OR install manually:
# 1. Download the latest binary (~60 MB):
sudo curl -fL https://app.getambassador.io/download/tel2/darwin/amd64/latest/telepresence -o /usr/local/bin/telepresence

# 2. Make the binary executable:
sudo chmod a+x /usr/local/bin/telepresence

# Apple silicon Macs

# Install via brew:
brew install datawire/blackbird/telepresence-arm64

# OR Install manually:
# 1. Download the latest binary (~60 MB):
sudo curl -fL https://app.getambassador.io/download/tel2/darwin/arm64/latest/telepresence -o /usr/local/bin/telepresence

# 2. Make the binary executable:
sudo chmod a+x /usr/local/bin/telepresence

k8s集群部分(安装tranffic manager):
需要先安装helm,然后执行

telepresence helm install

或者直接调用helm安装

连接集群

安装完成后,需要使用下面的命令来连接到k8s集群。

telepresence connect

如果运行上面的命令之后,检查状态或使用功能时存在问题,可能是集群的namespace太多造成的,可以使用下面的参数来控制要连接哪些namespace,用逗号分隔。这样通常能够解决问题。

telepresence connect --mapped-namespaces namespace-a,namespace-b

连上之后可以使用如下命令检查状态

telepresence status

使用如下命令测试是否能正确访问集群内服务,如果返回401就是成功了。

curl -ik https://kubernetes.default

访问集群内的服务

接下来可以直接通过k8s的namespace和service作为域名访问集群内的service了,本地应用调试时的依赖服务配置文件也可以改成这样的地址,这样可以直连开发环境的数据库和其他服务,方便本地开发。

比如:

curl http://my-service.my-namespace:8080

劫持集群内的服务流量到本机

对于某些线上服务的疑难杂症,可以直接把发给他的流量劫持到本机,这样就能在本机直接边改代码边在集群中进行e2e的调试。目前这个功能有一定局限性,同一个service同时只能劫持一个端口。

开启劫持:

telepresence intercept my-service --port 8080:8080 -n my-namespace

开启之后,你就可以启动本地的服务,来接收来自集群中的流量了。

列出服务的劫持状态:

telepresence list -n my-namespace

调试完了别忘了卸载服务的劫持状态:

telepresence uninstall --agent my-service -n my-namespace

把集群的其他服务请求流量恢复到指向集群里的pod。

也可以用telepresence leave <intercept-name>来关闭劫持状态,这个intercept-name需要在list命令下找到对应的名字,但这种方式在服务有多个端口提供服务并劫持其中一个端口时,在关闭之后会造成其他端口仍不可用的状态,所以用上面uninstall的命令会比较好一些。

关闭集群连接

使用如下命令关闭到集群的连接,将本地的网络恢复原状:

telepresence quit

其他高级功能请参考文档说明。

参考