背景

WebAssembly是一种可以将多种语言编译成目标字节码,并在相应的wasm虚拟机中运行的技术。

在service mesh中,通常使用envoy作为proxy sidecar。而envoy是基于c++编写,扩展和定制稍有不便。

借助WebAssembly,我们可以利用其他语言比如AssemblyScript(ts),Rust等来编写envoy的扩展(类似与用lua扩展nginx),并在envoy中运行。

目前envoy官方仓库仅有wasm分支对wasm进行了实验性支持,所以本文基于gloo(官方支持wasm的一个api网关)进行搭建。

环境介绍

ECS:阿里云香港,2c4g,ubuntu20.04

本机:ubuntu18

搭建步骤

  1. docker
  2. minikube
  3. gloo

docker

参考:https://docs.docker.com/engine/install/ubuntu/

# 卸载原有docker安装
$ sudo apt-get remove docker docker-engine docker.io containerd runc$ sudo apt-get update# 安装必要依赖
$ sudo apt-get install \apt-transport-https \ca-certificates \curl \gnupg-agent \software-properties-common# 下载key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -# 验证key
$ sudo apt-key fingerprint 0EBFCD88# 添加仓库
$ sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu \$(lsb_release -cs) \stable"# 更新源、安装
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io# 验证安装
$ sudo docker run hello-world

minikube

先安装kubectl

参考:https://kubernetes.io/docs/tasks/tools/install-kubectl/

由于google连不上,本机国内安装参考:

https://zhuanlan.zhihu.com/p/38118017

https://www.cnblogs.com/dudu/p/12155869.html

$ sudo apt-get update && sudo apt-get install -y apt-transport-https gnupg2 curl
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
$ echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
$ sudo apt-get update
$ sudo apt-get install -y kubectl

再安装minikube

参考:https://minikube.sigs.k8s.io/docs/start/#install-minikube

本机国内安装参考:https://developer.aliyun.com/article/221687

# 下载安装
$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
$ sudo install minikube-linux-amd64 /usr/local/bin/minikube# 启动(默认使用docker驱动)
$ minikube start# 如果连接docker报错(/var/run/docker.sock: connect: permission denied),可能是用户权限的问题:
$ sudo usermod -aG docker $USER
$ newgrp docker
$ sudo service docker restart# 验证
$ kubectl get po -A

gloo

gloo是一个基于envoy的api gateway,介绍及文档:https://docs.solo.io/gloo/latest/

# 安装glooctl工具
$ curl -sL https://run.solo.io/gloo/install | sh
$ export PATH=$HOME/.gloo/bin:$PATH
$ glooctl version# 安装gloo的upstream示例程序petstore
$ kubectl apply -f https://raw.githubusercontent.com/solo-io/gloo/master/example/petstore/petstore.yaml# 安装gloo的wasm版本
$ glooctl install gateway --values <(echo '{"crds":{"create":true},"global":{"wasm":{"enabled":true}}}')# 添加virtual service路由
$ cat <<EOF | kubectl apply -f-
apiVersion: gateway.solo.io/v1
kind: VirtualService
metadata:name: defaultnamespace: gloo-system
spec:virtualHost:domains:- '*'routes:- matchers:- prefix: /routeAction:single:upstream:name: default-petstore-8080namespace: gloo-system
EOF# 验证路由
$ curl -v $(glooctl proxy url)/api/pets# 正常情况下输出
*   Trying 192.168.49.2:30277...
* TCP_NODELAY set
* Connected to 192.168.49.2 (192.168.49.2) port 30277 (#0)
> GET /api/pets HTTP/1.1
> Host: 192.168.49.2:30277
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< content-type: application/xml
< date: Fri, 16 Oct 2020 03:49:56 GMT
< content-length: 86
< x-envoy-upstream-service-time: 1
< server: envoy
<
[{"id":1,"name":"Dog","status":"available"},{"id":2,"name":"Cat","status":"pending"}]

编译wasm示例:https://docs.solo.io/web-assembly-hub/latest/tutorial_code/getting_started/

# 安装wasme工具
$ curl -sL https://run.solo.io/wasme/install | sh
$ export PATH=$HOME/.wasme/bin:$PATH
$ wasme --version# 初始化wasm工程
$ wasme init ./new-filter# 选择语言
? What language do you wish to use for the filter:cpp▸ assemblyscript
? With which platforms do you wish to use the filter?:▸ gloo:1.3.x, istio:1.5.x# 编译
$ wasme build assemblyscript -t webassemblyhub.io/$YOUR_USERNAME/add-header:v0.1 .# 查看本地编译结果
$ wasme list# 到webassemblyhub.io创建一个账号
# 推送编译结果到仓库
$ wasme login -u $YOUR_USERNAME -p $YOUR_PASSWORD
$ wasme push webassemblyhub.io/$YOUR_USERNAME/add-header:v0.1
# 查看推送结果
$ wasme list --search $YOUR_USERNAME

验证结果,header中已包含插件写入的hello world

# 将wasm filter注入到gloo网关中
$ wasme deploy gloo webassemblyhub.io/$YOUR_USERNAME/add-header:v0.1 --id=add-header# 再次访问
$ curl -v $(glooctl proxy url)/api/pets*   Trying 192.168.49.2:30277...
* TCP_NODELAY set
* Connected to 192.168.49.2 (192.168.49.2) port 30277 (#0)
> GET /api/pets HTTP/1.1
> Host: 192.168.49.2:30277
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< content-type: application/xml
< date: Fri, 16 Oct 2020 03:49:56 GMT
< content-length: 86
< x-envoy-upstream-service-time: 1
< hello: world!
< server: envoy
<
[{"id":1,"name":"Dog","status":"available"},{"id":2,"name":"Cat","status":"pending"}]

相关参考:

编写wasm插件:https://docs.solo.io/web-assembly-hub/latest/tutorial_code/build_tutorials

部署wasm插件:https://docs.solo.io/web-assembly-hub/latest/tutorial_code/deploy_tutorials

搭建istio环境:https://istio.io/latest/docs/setup/getting-started/#download

搭建gloo网关(基于envoy)的wasm实验环境(阿里云、本机)相关推荐

  1. 搭建以太坊私有链(PoA)--CentOS7.6 on 阿里云ECS、macOS Catalina on Mac、Ubuntu20.04 on Raspberry Pi 4B

    使用Geth搭建以太坊PoA私有链 搭建以太坊私有链(PoA) 1 阿里云ECS上的操作步骤 1.1 准备环境 1.2 安装Geth及Tools 1.3 创建以太坊私有链的数据文件夹 1.4 用pup ...

  2. 微信小程序连接物联网(三):微信小程序远程遥控宿舍开门 基于NodeMCU通过MQTT协议连接阿里云物联网平台

    索引 这是用微信小程序遥控开门的系列文章,具体微信小程序连接物联网的代码在第三章提及. 微信小程序连接物联网(一):初始化ESP8266 NodeMCU 微信小程序连接物联网(二):NodeMCU L ...

  3. 基于STM32+FreeRtos+ESP8266+MQTT连接阿里云

    基于STM32+FreeRtos+DHT12+ESP8266+MQTT连接阿里云 1.概述 2.实现步骤 2.1.MQTT.fx模拟器与阿里云通信 2.2.STM32与阿里云通信 3. 搭建云平台 3 ...

  4. java实现mqtt服务端_基于Swoole使用MQTT协议连接阿里云物联网平台设备实现消息订阅

    阿里云物联网平台为设备提供安全可靠的连接通信能力,支撑设备数据采集上云,我们这里认为阿里云物联网平台是 MQTT 服务端,那么我们自己的设备作为客户端,应该如何实现消息订阅? 阿里云没有提供 PHP ...

  5. 树莓派4b: 初级使用(Ubuntu21.10,Windows11写入SSD,远程连接,软路由搭建,webmin安装,自建Dockerhub,远程管理, 百度云盘,阿里云盘同步等)

    虽然vps也便宜,但还是想买4b 树莓派4b显示器接线为 hdmini,买时没有附赠 所以以下均为mac系统下通过ssh操作 文章来自:http://blog.csdn.net/intbird 转载请 ...

  6. 嵌入式Linux搭建物联网网关,基于嵌入式Linux的物联网网关研究与实现

    摘要: 随着物联网发展速度日益加快,作为连接感知网络和传统通信网络的物联网网关正在其中扮演着重要角色.然而,目前针对物联网网关的统一标准尚未制定,物联网网关的设备类型千差万别.人们往往针对某一具体应用 ...

  7. Win10下搭建绿色版基于WAMP的PHP开发环境

    1.安装Apache 下载最新稳定版http://www.apachehaus.com/downloads/httpd-2.4.23-x64-vc11.zip: 解压到D:\Apached下: 修改D ...

  8. python可视化库matplotlib_环境搭建 | Python 数据可视化库 Matplotlib 快速入门之一-阿里云开发者社区...

    数据挖掘基础环境安装与使用 [学习目标] 完成数据挖掘基础阶段的所有环境安装 应用jupyter notebook完成代码编写运行 库的安装 学习目标 目标 搭建好数据挖掘基础阶段的环境 应用 无 整 ...

  9. 只更新代码,然后发布版本:基于 Serverless Devs 原子化操作阿里云函数计算

    众所周知,随着时间的发展,Serverless 命令行工具也逐渐的玩出了更多的花样,就目前来看,常见的形态有两种,一种是通过 Yaml 来进行资源的描述,另外一种是纯粹的命令行操作,而不依赖这些内容. ...

最新文章

  1. Ubuntu 修改本地磁盘名称
  2. Intellij IDEA单元测试提示Test events were not received
  3. Spring 事务失效?看这篇文章就够了!
  4. SQL Server 索引结构及其使用(二)(转)
  5. 【数据库系统】再谈关系模型和关系型数据库
  6. 轻量级音乐服务器LMS
  7. mysql如何创建视图语句_创建视图的语句
  8. 安卓干货——安卓NFC通信
  9. 阿里云ecs云服务器和域名的购买,绑定及备案教程
  10. 测试同学反馈,java 程序内存泄露,症状是RSS不断增加超过了jvm的xmx
  11. 怎么看计算机内存和独显,电脑独立显卡或集成显卡的显存大小怎么查看?
  12. 计算机控制技术俞光昀练习答案,计算机控制技术 复习重点 ( 俞光昀)
  13. 20191019杂谈——祸兮福所倚
  14. 嵌入式工程师面试知识总结
  15. 在Vue中使用 createjs
  16. js中的escape方法有什么用?
  17. c++求矩阵的秩_高等代数|第八章 矩阵 最小多项式与若尔当标准形
  18. 计算机管理中不显示独立显卡,win10系统下检测不到独立显卡如何解决
  19. CTF-合天WEB漏洞靶场
  20. 第3章 Linux内核调试手段之二

热门文章

  1. 翻译:《实用的Python编程》01_04_Strings
  2. python爬虫实例教程-Python网络爬虫实例教程(视频讲解版)
  3. java计算机毕业设计青岛地区常见昆虫图鉴与论坛源程序+mysql+系统+lw文档+远程调试
  4. 问题 B: 第N个智慧数
  5. 基于《PythonCookbook》的学习(2)——在字符串的卡头或结尾做文本匹配
  6. C++标准库实现WAV文件读写
  7. Oracle数据库应用
  8. 街都VR:景区使用360全景制作的八个优势
  9. USB Mass Storage 6.7 The Thirteen Cases章节的理解
  10. ProGuard入门