微軟近期開源了一個新的名爲 Open Service Mesh 的項目並準備捐贈給 CNCF 。html
Open Service Mesh (OSM) is a lightweight, extensible, Cloud Native service mesh that allows users to uniformly manage, secure, and get out-of-the-box observability features for highly dynamic microservice environments.
Open Service Mesh(OSM)是一個輕量級,可擴展的雲原生服務網格,它使用戶可以統一管理,保護和得到針對高度動態微服務環境的開箱即用的可觀察性功能。linux
OSM 在 Kubernetes 上運行基於 Envoy 的控制平面,可使用 SMI API 進行配置。它經過以 sidecar 的形式注入 Envoy 代理來工做。git
控制面負責持續配置代理,以配置策略和路由規則等都保持最新。代理主要負責執行訪問控制的規則,路由控制,採集 metrics 等。(這和目前咱們常見到的 Service Mesh 方案基本都同樣的)github
Traffic Access Control
, Traffic Specs
和 Traffic Split
。剩下的 Traffic Metrics
正在開發中;只作介紹未免太過無趣,並且說實話,這麼多 service mesh 實現,不親自上手試試看,感受不出來太多差別的。web
這裏我使用 KIND 做爲我本地的實驗環境。api
安裝過程很簡單,直接去 Release 頁面 下載預編譯好的二進制文件。可將二進制文件加入到 $PATH
中。瀏覽器
(MoeLove) ➜ ~ wget -q https://github.com/openservicemesh/osm/releases/download/v0.1.0/osm-v0.1.0-linux-amd64.tar.gz (MoeLove) ➜ ~ tar -xzvf osm-v0.1.0-linux-amd64.tar.gz linux-amd64/ linux-amd64/LICENSE linux-amd64/README.md linux-amd64/osm (MoeLove) ➜ ~ cd linux-amd64 (MoeLove) ➜ linux-amd64 ls LICENSE osm README.md
在進行 osm 資源和服務的正式安裝前,先作個必要的檢查:app
(MoeLove) ➜ linux-amd64 ./osm check --pre-install ok: initialize Kubernetes client ok: query Kubernetes API ok: Kubernetes version ok: can create namespaces ok: can create customresourcedefinitions ok: can create clusterroles ok: can create clusterrolebindings ok: can create mutatingwebhookconfigurations ok: can create serviceaccounts ok: can create services ok: can create deployments ok: can create configmaps ok: can read secrets ok: can modify iptables All checks successful!
能夠看到主要是和權限相關的一些檢查。接下來就正式對 ocm 相關資源進行部署。tcp
默認使用的鏡像,託管在 DockerHub 上,若是須要配置加速的小夥伴,可傳遞 --container-registry
更改源地址,以便於加速安裝進度。ide
(MoeLove) ➜ linux-amd64 ./osm install OSM installed successfully in namespace [osm-system] with mesh name [osm] (MoeLove) ➜ linux-amd64 kubectl -n osm-system get pods NAME READY STATUS RESTARTS AGE osm-controller-d499d6cc7-88659 0/1 ContainerCreating 0 12s osm-grafana-58ff65dfb7-svztv 0/1 ContainerCreating 0 12s osm-prometheus-5756769877-zj6f6 0/1 ContainerCreating 0 12s zipkin-6df4b57677-dcq8q 0/1 ContainerCreating 0 12s
能夠看到默認安裝完成後,都在 osm-system
命名空間下,有 4 個 Pods
osm dashboard
命令喚起;還有對應的 service 記錄.
(MoeLove) ➜ linux-amd64 kubectl -n osm-system get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE osm-controller ClusterIP 10.97.115.1 <none> 15128/TCP,443/TCP 7m46s osm-grafana ClusterIP 10.110.209.86 <none> 3000/TCP 7m46s osm-prometheus ClusterIP 10.97.10.65 <none> 7070/TCP 7m46s zipkin ClusterIP 10.103.150.158 <none> 9411/TCP 7m46s
以及一系列的 CRD
(MoeLove) ➜ linux-amd64 kubectl -n osm-system get crd NAME CREATED AT backpressures.policy.openservicemesh.io 2020-08-06T16:14:03Z httproutegroups.specs.smi-spec.io 2020-08-06T16:14:03Z tcproutes.specs.smi-spec.io 2020-08-06T16:14:03Z trafficsplits.split.smi-spec.io 2020-08-06T16:14:03Z traffictargets.access.smi-spec.io 2020-08-06T16:14:03Z
osm namespace add
將其歸入管理範圍中:(MoeLove) ➜ ~ kubectl create ns bookstore namespace/bookstore created (MoeLove) ➜ ~ kubectl create ns bookbuyer namespace/bookbuyer created (MoeLove) ➜ ~ kubectl create ns bookthief namespace/bookthief created (MoeLove) ➜ ~ kubectl create ns bookwarehouse namespace/bookwarehouse created (MoeLove) ➜ ~ osm namespace add bookstore bookbuyer bookthief bookwarehouse Namespace [bookstore] succesfully added to mesh [osm] Namespace [bookbuyer] succesfully added to mesh [osm] Namespace [bookthief] succesfully added to mesh [osm] Namespace [bookwarehouse] succesfully added to mesh [osm]
# 在項目的代碼目錄中執行 (MoeLove) ➜ osm git:(main) kubectl apply -f docs/example/manifests/apps Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply namespace/bookbuyer configured serviceaccount/bookbuyer created service/bookbuyer created deployment.apps/bookbuyer created Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply namespace/bookstore configured service/bookstore created service/bookstore-v1 created serviceaccount/bookstore-v1 created deployment.apps/bookstore-v1 created Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply namespace/bookthief configured serviceaccount/bookthief created service/bookthief created deployment.apps/bookthief created Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply namespace/bookwarehouse configured serviceaccount/bookwarehouse created service/bookwarehouse created deployment.apps/bookwarehouse created trafficsplit.split.smi-spec.io/bookstore-split created
你能夠經過 kubectl port-foward
在本地對剛纔部署的應用進行訪問。示例中也提供了相應的啓動腳本 scripts/port-forward-all.sh
,注意這裏須要先安裝 GNU parallel ,例如: dnf install parallel
.
(MoeLove) ➜ osm git:(main) ✗ ./scripts/port-forward-all.sh Academic tradition requires you to cite works you base your article on. If you use programs that use GNU Parallel to process data for an article in a scientific publication, please cite: O. Tange (2018): GNU Parallel 2018, Mar 2018, ISBN 9781387509881, DOI https://doi.org/10.5281/zenodo.1146014 This helps funding further development; AND IT WON'T COST YOU A CENT. If you pay 10000 EUR you should feel free to use GNU Parallel without citing. More about funding GNU Parallel and the citation notice: https://www.gnu.org/software/parallel/parallel_design.html#Citation-notice To silence this citation notice: run 'parallel --citation' once.
訪問本地的 8080~8083
端口便可看到示例項目。例如:
備註:這裏是由於個人應用程序已經運行一段時間了,若是是新部署的,全部數字皆爲 0
咱們來看看如何調整訪問控制的策略
kind: TrafficTarget apiVersion: access.smi-spec.io/v1alpha2 metadata: name: bookstore-v1 namespace: bookstore spec: destination: kind: ServiceAccount name: bookstore-v1 namespace: bookstore rules: - kind: HTTPRouteGroup name: bookstore-service-routes matches: - buy-a-book - books-bought sources: - kind: ServiceAccount name: bookbuyer namespace: bookbuyer #- kind: ServiceAccount #name: bookthief #namespace: bookthief --- apiVersion: specs.smi-spec.io/v1alpha3 kind: HTTPRouteGroup metadata: name: bookstore-service-routes namespace: bookstore spec: matches: - name: books-bought pathRegex: /books-bought methods: - GET headers: - host: "bookstore.bookstore" - "user-agent": ".*-http-client/*.*" - "client-app": "bookbuyer" - name: buy-a-book pathRegex: ".*a-book.*new" methods: - GET headers: - host: "bookstore.bookstore"
這裏定義了兩個 SMI 中的資源 TrafficTarget
和 HTTPRouteGroup
,用來控制入口流量。
(MoeLove) ➜ osm git:(main) ✗ kubectl apply -f docs/example/manifests/access/
經過以上命令建立這兩個資源。而後再次打開咱們的示例應用程序,就會看到對應的計數正在逐步增長(由於請求被放行了) 。
以上示例來自於項目倉庫 中的示例。
經過 osm dashboard
可直接喚起本地瀏覽器,並 port-foward 將 Grafana 打開。
Open Service Mesh 相對來講,確實很輕量。 所須要的訪問控制,流量切割等功能經過本身建立 SMI 資源來控制。
而且,在同一個集羣內可存在多組 mesh ,osm 安裝的時候,可指定 mesh 名稱。
此外,這個項目也是微軟在 Service Mesh 方向的又一個大動做了。目標也許是 Istio 。讓咱們拭目以待。
歡迎訂閱個人文章公衆號【MoeLove】