快速体验
osm-edge 快速体验
以下演示如何在 5 分钟之内,下载、安装、运行 osm-edge,并部署一个演示应用,并完成链路加密、访问控制、流量分割等 SMI 标准功能。该演示使用 x86 版本的 Ubuntu 21,运行v1.23.8+k3s1
版本的 k3s。更多版本和平台的支持,请参考完整的新手上路文档。
先决条件
一个运行中的 Kubernetes 集群,可以通过下面的命令快速创建 k3s 单节点集群:
export INSTALL_K3S_VERSION=v1.23.8+k3s1
curl -sfL https://get.k3s.io | sh -s - --disable traefik --write-kubeconfig-mode 644 --write-kubeconfig ~/.kube/config
osm-edge 支持的最低 Kubernetes 版本为 v1.19.0。
下载并安装 osm-edge 命令行工具
system=$(uname -s | tr [:upper:] [:lower:])
arch=$(dpkg --print-architecture)
release=v1.1.2
curl -L https://github.com/flomesh-io/osm-edge/releases/download/${release}/osm-edge-${release}-${system}-${arch}.tar.gz | tar -vxzf -
./${system}-${arch}/osm version
cp ./${system}-${arch}/osm /usr/local/bin/
在 Kubernetes 上安装 osm-edge
此命令启用 Prometheus、Grafana 和 Jaeger 集成
export osm_namespace=osm-system
export osm_mesh_name=osm
osm install \
--mesh-name "$osm_mesh_name" \
--osm-namespace "$osm_namespace" \
--set=osm.enablePermissiveTrafficPolicy=true \
--set=osm.deployPrometheus=true \
--set=osm.deployGrafana=true \
--set=osm.deployJaeger=true \
--set=osm.tracing.enable=true
部署演示应用
演示应用包括了如下服务:
bookbuyer
是一个 HTTP 客户端,它发送请求给bookstore
。这个流量是允许的。bookthief
是一个 HTTP 客户端,很像bookbuyer
,也会发送 HTTP 请求给bookstore
。这个流量应该被阻止。bookstore
是一个服务器,负责对 HTTP 请求给与响应。同时,该服务器也是一个客户端,发送请求给bookwarehouse
服务。这个流量是被允许的。bookwarehouse
是一个服务器,应该只对bookstore
做出响应。bookbuyer
和bookthief
都应该被其阻止。mysql
是一个 MySQL 数据库,只有bookwarehouse
可以访问。
使用如下命令部署这些服务:
kubectl create namespace bookstore
kubectl create namespace bookbuyer
kubectl create namespace bookthief
kubectl create namespace bookwarehouse
osm namespace add bookstore bookbuyer bookthief bookwarehouse
kubectl apply -f https://raw.githubusercontent.com/flomesh-io/osm-edge-docs/release-v1.1/manifests/apps/bookbuyer.yaml
kubectl apply -f https://raw.githubusercontent.com/flomesh-io/osm-edge-docs/release-v1.1/manifests/apps/bookthief.yaml
kubectl apply -f https://raw.githubusercontent.com/flomesh-io/osm-edge-docs/release-v1.1/manifests/apps/bookstore.yaml
kubectl apply -f https://raw.githubusercontent.com/flomesh-io/osm-edge-docs/release-v1.1/manifests/apps/bookwarehouse.yaml
kubectl apply -f https://raw.githubusercontent.com/flomesh-io/osm-edge-docs/release-v1.1/manifests/apps/mysql.yaml
把每个服务的GUI端口对外暴露,这样用浏览器我们可以访问这些端口,观察演示的现象。
git clone https://github.com/flomesh-io/osm-edge.git -b release-v1.1
cd osm-edge
cp .env.example .env
./scripts/port-forward-all.sh #可以忽略错误信息
在一个浏览器中,打开下面的 URL:
注意:如果需要从宿主机访问,需要将 localhost
替换成虚拟机的 IP 地址;或者在宿主机上运行 port-forward-all.sh
脚本。
- http://localhost:8080 - bookbuyer
- http://localhost:8083 - bookthief
- http://localhost:8084 - bookstore
访问控制
通过上面的命令安装 osm-edge,所有的服务都是没有访问控制的(宽松流量模式),或者说所有的访问都是允许的。通过在浏览器中观察每个服务的页面数量增长可以看到没有访问控制时候的情况:
在 bookbuyer
、bookthief
UI 中的计数分别对应了购买和盗窃的书籍数量,而在 bookstore-v1
中这些都应该在增加:
- http://localhost:8080 - bookbuyer
- http://localhost:8083 - bookthief
在 bookstore
UI 中的对于书籍销售的计数也应该在增加:
- http://localhost:8084 - bookstore
接下来演示通过禁用宽松流量策略模式,拒绝对 bookstore
服务的访问:
kubectl patch meshconfig osm-mesh-config -n osm-system -p '{"spec":{"traffic":{"enablePermissiveTrafficPolicyMode":false}}}' --type=merge
此时会发现计数将不再增加。
现在执行下面的命令,放行 bookbuyer
对 bookstore
的访问:
kubectl apply -f https://raw.githubusercontent.com/flomesh-io/osm-edge-docs/main/manifests/access/traffic-access-v1.yaml
这里再去查看 bookbuyer
和 bookstore
UI,会发现计数恢复增加,而 bookthief
UI 的计数仍然停止。
通过访问控制,我们成功阻止 bookthief
从 bookstore
盗窃书籍,而正常的购买不受影响。
可观测性
Metrics
使用下面的命令开启命名空间下的 metrics 采集,否则前面创建的 Pod 产生的 metrics 并不会被采集:
osm metrics enable --namespace "bookstore,bookbuyer,bookthief,bookwarehouse"
在执行了端口转发脚本之后,在浏览器中打开 http://localhost:3000
可以访问已经安装的 Grafana,默认的用户名和密码分别为 admin
、admin
。
osm-edge 内置了多个 dashboard 提供控制平面和数据平面各项指标的可视化展示。比如下图中展示的是 bookthief
服务的 pod http://localhost:3000
访问其他 service
的指标:
下图展示的是 bookthief
以 deployment
为粒度,访问其他 service
的指标。与上个图的差别在于,假如 bookthief
有多个副本,这里会展示所有副本的汇总数据:
接下来展示的 osm-edge 组件、以及网格基础信息等的指标:
Tracing
在浏览器中输入 http://localhost:16686/search
可访问 Jaeger 的仪表板:
仪表板中可以查询服务相关的 tracing 信息:
展示服务拓扑图:
Logging
osm-edge 控制平面将诊断日志输出到了标准输出上,用于服务网格的管理,可以通过调整日志的级别来控制日志信息的输出。输出到标准输出上的日志,可以通过日志采集工具采集聚合并存储。
卸载服务网格
在完成 osm-edge 的快速体验后,如果要卸载全部与之相关的资源,就需要删除这些示例应用和相关的 SMI 资源,并且卸载掉 osm-edge 控制平面和集群范围内的 osm-edge 资源。
删除示例应用:
kubectl delete ns bookbuyer bookthief bookstore bookwarehouse
卸载控制平面:
osm uninstall mesh
反馈
该内容是否有帮助?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.