成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

聊聊 Wasm 擴(kuò)展 Envoy 使用詳解

開發(fā) 前端
我們想要網(wǎng)格的服務(wù)發(fā)現(xiàn)、路由、熔斷降級、負(fù)載均衡,這些流量治理都在數(shù)據(jù)面Envoy中執(zhí)行才行。

[[437206]]

引言

我們想要網(wǎng)格的服務(wù)發(fā)現(xiàn)、路由、熔斷降級、負(fù)載均衡,這些流量治理都在數(shù)據(jù)面Envoy中執(zhí)行才行。Envoy也提供的Filter機(jī)制來做這些功能,通常有以下方式:

  • 通過C++代碼自定義filter重新編譯Envoy
  • 使用Lua腳本擴(kuò)展filter
  • 使用wasm擴(kuò)展Envoy

一、wasm工作原理

第一種C++編譯學(xué)習(xí)成本過高,維護(hù)也困難,第二種適合用于實現(xiàn)簡單功能可以,第三種是重點(diǎn)發(fā)展方向通過其他語言編寫filter,通過wasm編譯運(yùn)行嵌入在Envoy中運(yùn)行,通過可移植的二進(jìn)制指令實現(xiàn),以下特性:

動態(tài)加載到Envoy中執(zhí)行

  • 無需修改Envoy代碼容易維護(hù)
  • 支持較多開發(fā)語言比如tinygo
  • 進(jìn)程級隔離在VM沙箱運(yùn)行部影響Envoy進(jìn)程
  • 流量進(jìn)過Envoy示意圖:

二、wasm安裝過程

安裝Isito1.9.9

當(dāng)前最新版本為v0.0.33,支持的Istio為1.9.X

  1. https://github.com/solo-io/wasm/releases/ 

卸載原來的istio1.10版本,安裝1.9.9

  1. istioctl x uninstall --purge 

istio1.9.9安裝路徑,具體安裝過程見前面文章

  1. https://github.com/istio/istio/releases/download/1.9.9/istio-1.9.9-linux-amd64.tar.gz 

聲明式掛載wasme

下面有詳細(xì)的安裝建議,生產(chǎn)環(huán)境建議使用聲明式掛載:

  1. https://docs.solo.io/web-assembly-hub/latest/tutorial_code/wasme_operator/ 

1.安裝Wasme CRDs

  1. kubectl apply -f https://github.com/solo-io/wasm/releases/latest/download/wasme.io_v1_crds.yaml 
  2.  
  3. # kubectl apply -f wasme.io_v1_crds.yaml 
  4. customresourcedefinition.apiextensions.k8s.io/filterdeployments.wasme.io created 

2.安裝Operator components

  1. kubectl apply -f https://github.com/solo-io/wasm/releases/latest/download/wasme-default.yaml 
  2.  
  3. # kubectl apply -f wasme-default.yaml 
  4. namespace/wasme created 
  5. serviceaccount/wasme-operator created 
  6. serviceaccount/wasme-cache created 
  7. configmap/wasme-cache created 
  8. clusterrole.rbac.authorization.k8s.io/wasme-operator created 
  9. clusterrole.rbac.authorization.k8s.io/wasme-cache created 
  10. clusterrolebinding.rbac.authorization.k8s.io/wasme-operator created 
  11. clusterrolebinding.rbac.authorization.k8s.io/wasme-cache created 
  12. daemonset.apps/wasme-cache created 
  13. deployment.apps/wasme-operator created 

3.校驗是否安裝成功

  1. # kubectl get pod -n wasme 
  2. NAME                              READY   STATUS    RESTARTS   AGE 
  3. wasme-cache-96mnm                 1/1     Running   0          23s 
  4. wasme-cache-ktnpb                 1/1     Running   0          23s 
  5. wasme-cache-w929m                 1/1     Running   0          23s 
  6. wasme-operator-75bbf94974-nb684   1/1     Running   0          23s 

掛載工作原理

命令行安裝

官方安裝文檔

  1. https://docs.solo.io/web-assembly-hub/latest/tutorial_code/getting_started/ 

網(wǎng)絡(luò)好的可以使用快速安裝命令

  1. curl -sL https://run.solo.io/wasme/install | sh 

從install_cli.sh安裝腳本看做了什么事情

  1. if [ "$(uname -s)" = "Darwin" ]; then  OS=darwin // Mac為darwinelse  OS=linuxfi// 更名和授予執(zhí)行權(quán)限cd "$HOME"mkdir -p ".wasme/bin"mv "${tmp}/${filename}" ".wasme/bin/wasme"chmod +x ".wasme/bin/wasme"// 添加到環(huán)境變量export PATH=\$HOME/.wasme/bin:\$PATH" 

Mac可以下載wasme-darwin-amd64,照著安裝就是了。

  1. export PATH=$PATH:/Users/yongliang/work/software_install/wasme/binsource ~/.bash_profilechmod +x /Users/yongliang/work/software_install/wasme/bin/wasmewasme --versionwasme version 0.0.33 

三、wasm生成Filter

官方使用指南參見:

  1. https://docs.solo.io/web-assembly-hub/latest/tutorial_code/build_tutorials/building_assemblyscript_filters/ 

先試用tinygo做個示例看看效果

  1. wasme init melon-filterUse the arrow keys to navigate: ↓ ↑ → ← ? What language do you wish to use for the filter:     cpp    rust    assemblyscript  ▸ tinygo   

執(zhí)行后:

  1. wasme init melon-filter✔ tinygo✔ istio:1.7.x, gloo:1.6.x, istio:1.8.x, istio:1.9.x 

目錄結(jié)構(gòu)

  1. -rw-r--r--  1 yongliang  staff    83 11 15 19:26 go.mod-rw-r--r--  1 yongliang  staff   676 11 15 19:26 go.sum-rw-r--r--  1 yongliang  staff  1707 11 15 19:26 main.go-rw-r--r--  1 yongliang  staff   162 11 15 19:26 runtime-config.json 

runtime-config.json是wamse構(gòu)建filter使用的,必須包含rootIds字段

  1. {  "type""envoy_proxy",  "abiVersions": ["v0-4689a30309abf31aee9ae36e73d34b1bb182685f""v0.2.1"],  "config": {    "rootIds": [      "root_id"    ]  }} 

main.go是生成的示例代碼,主要在返回response頭部Header添加了信息,修改成「”hello“,“melon”」

  1. func (ctx *httpHeaders) OnHttpResponseHeaders(numHeaders int, endOfStream bool) types.Action {        if err := proxywasm.SetHttpResponseHeader("hello""melon"); err != nil {                proxywasm.LogCriticalf("failed to set response header: %v", err)        }        return types.ActionContinue} 

四、wasm構(gòu)建Filter

Filter構(gòu)建

構(gòu)建的過程耗時較長,多等一會

  1. wasme build tinygo /Users/yongliang/GoLandProjects/melon-filter -t xxx/base/melon-add-header:v0.1Unable to find image 'quay.io/solo-io/ee-builder:0.0.33' locally0.0.33: Pulling from solo-io/ee-builderdf27e1f7c31e: Pull complete 0a8813a60e2e: Pull complete 3c2cba919283: Pull complete 26f4837a47c0: Pull complete dd7b292cf068: Pull complete 4a4d78f042bc: Pull complete 9108a736d6a0: Pull complete 70ac09daaa76: Pull complete 809bdff17a4d: Pull complete 31fc029d676e: Pull complete 85533903f7c2: Pull complete f87e543b124a: Pull complete 93d78f561264: Pull complete 8ba3d0f61e41: Pull complete d511201136be: Pull complete Digest: sha256:94b6ce4624b0c4ed4cfa4f311c8af57083b538949b5c88ce62ef984f9b81ef66Status: Downloaded newer image for quay.io/solo-io/ee-builder:0.0.33Building with tinygo...go: downloading github.com/tetratelabs/proxy-wasm-go-sdk v0.1.1INFO[2146] adding image to cache...                      filter file=/tmp/wasme066130090/filter.wasm tag="xxx/base/melon-add-header:v0.1"INFO[2146] tagged image                                  digest="sha256:750d63889653e7117fcbc0831f10f0e1d3f7ec0c82fe5787b71d08a783e3393f" image="xxx/base/melon-add-header:v0.1" 

構(gòu)建完成,生成鏡像

  1. wasme listNAME                                      TAG  SIZE     SHA      UPDATEDxxxx/base/melon-add-header v0.1 247.6 kB 750d6388 15 Nov 21 20:23 CST 

備注:官方構(gòu)建教程參見

  1. https://docs.solo.io/web-assembly-hub/latest/tutorial_code/build_tutorials/building_assemblyscript_filters/ 

鏡像推送

將構(gòu)建好的鏡像需要推送到遠(yuǎn)程倉庫

  1. wasme push xxx/base/melon-add-header:v0.1INFO[0000] Pushing image xxxn/base/melon-add-header:v0.1 INFO[0004] Pushed xxx/base/melon-add-header:v0.1 INFO[0004] Digest: sha256:27aecb092318b2f922204ce722a34e5c2866baa168cf2f9f00c303b1982cfa9a  

備注:官方推送教程參見

  1. https://docs.solo.io/web-assembly-hub/latest/tutorial_code/push_tutorials/basic_push/ 

五、Filter生效部署

通過Kubernetes的自定義資源,通過FilterDeployment來實現(xiàn),下面是melon-add-header.yaml內(nèi)容

  1. apiVersion: wasme.io/v1kind: FilterDeploymentmetadata:  name: melon-add-header  namespace: defaultspec:  deployment:    istio:      kind: Deployment  filter:       image: xxx/base/melon-add-header:v0.1 

執(zhí)行部署命令

  1. kubectl apply -f melon-add-header.yamlfilterdeployment.wasme.io/melon-add-header created 

備注:官方教程參見

  1. https://docs.solo.io/web-assembly-hub/latest/tutorial_code/wasme_operator/ 

六、生效驗證

1.訪問網(wǎng)格Mesh服務(wù)

2.檢驗Response Headers添加了「hello:melon」

本文轉(zhuǎn)載自微信公眾號「瓜農(nóng)老梁」,可以通過以下二維碼關(guān)注。轉(zhuǎn)載本文請聯(lián)系瓜農(nóng)老梁公眾號。

 

責(zé)任編輯:武曉燕 來源: 瓜農(nóng)老梁
相關(guān)推薦

2023-12-12 07:30:54

IstioWasm前端

2021-10-26 00:10:18

信息EnvoyServiceEntr

2022-11-28 11:41:24

Wasm

2010-01-12 09:11:18

Visual StudVisual Stud

2021-12-09 07:54:19

IDL字段兼容

2009-03-16 09:16:13

行為擴(kuò)展WCF.NET

2023-01-06 08:06:52

Groovy類型擴(kuò)展

2024-05-13 08:04:26

Vue.jsWeb應(yīng)用程序

2022-11-14 08:32:51

CSS組件Box

2021-11-09 23:54:19

開發(fā)SMI Linkerd

2009-04-21 13:14:33

SilverlightWPF擴(kuò)展

2014-07-11 09:33:24

iOS 8動作擴(kuò)展

2009-09-21 16:59:29

Array擴(kuò)展

2022-01-19 22:14:36

Apache APIAPI 網(wǎng)關(guān)插件

2021-06-07 08:04:39

Restorecon命令安全

2022-02-22 08:00:48

JavaNIOBuffer

2024-10-08 10:11:57

2023-02-15 13:57:13

JavaSPI動態(tài)擴(kuò)展

2023-12-06 08:45:01

WasmJavaScript

2023-09-04 07:30:03

Wasm匯編語言
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 91亚洲国产成人精品一区二三 | www.亚洲精品 | 国产精品女人久久久 | 狠狠狠| 国产亚洲精品久久久优势 | 亚洲国产激情 | 99精品免费久久久久久久久日本 | 成人在线观看免费视频 | 精品久久久久久久人人人人传媒 | 一区二区三区精品视频 | 久久这里只有精品首页 | 久久久久国产精品人 | 欧美日韩一卡二卡 | 亚洲天堂二区 | 国产精品日产欧美久久久久 | 亚洲永久| 日韩精彩视频 | 成人伊人网 | 婷婷在线视频 | 亚洲激情综合 | 欧美一区二区三区在线 | 国产精品视频久久久 | 在线观看www高清视频 | 日韩毛片在线免费观看 | 亚洲一区二区三区久久 | 国产黄色大片 | 亚洲一区在线播放 | 国产精品夜间视频香蕉 | 性欧美xxxx | 日韩精品一区二 | 久久一区二区三区电影 | 国产高清一二三区 | 婷婷精品 | 亚洲性爰 | 国产中文视频 | 中文字幕91 | 久久国产三级 | 狠狠艹 | 国产精品日韩欧美一区二区三区 | 新91 | 久久综合婷婷 |