<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>gloo | 伪架构师</title>
    <link>/tags/gloo/</link>
      <atom:link href="/tags/gloo/index.xml" rel="self" type="application/rss+xml" />
    <description>gloo</description>
    <generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>zh</language><lastBuildDate>Mon, 07 Jan 2019 23:24:10 +0800</lastBuildDate>
    <image>
      <url>/img/logo-wide.png</url>
      <title>gloo</title>
      <link>/tags/gloo/</link>
    </image>
    
    <item>
      <title>Gloo，充满想象力的 API Gateway</title>
      <link>/post/gloo-amazing-gateway/</link>
      <pubDate>Mon, 07 Jan 2019 23:24:10 +0800</pubDate>
      <guid>/post/gloo-amazing-gateway/</guid>
      <description>

&lt;h2 id=&#34;缘起&#34;&gt;缘起&lt;/h2&gt;

&lt;p&gt;2018 年 11 月，在 Medium 上闲逛时候看到一篇吓人的东西：&lt;a href=&#34;https://medium.com/solo-io/announcing-gloo-the-function-gateway-3f0860ef6600&#34; target=&#34;_blank&#34;&gt;Introducing SuperGloo: The Service Mesh Orchestration Platform&lt;/a&gt;，服务网格编排器——当时感觉挺奇幻的，在群里打趣了一下，并不以为意；直到有一天看到了另外一条消息：&lt;/p&gt;

&lt;blockquote class=&#34;twitter-tweet&#34;&gt;&lt;p lang=&#34;en&#34; dir=&#34;ltr&#34;&gt;My new adventure! Starting as Field CTO &lt;a href=&#34;https://twitter.com/soloio_inc?ref_src=twsrc%5Etfw&#34;&gt;@soloio_inc&lt;/a&gt; &lt;a href=&#34;https://t.co/FQKW2eoLlw&#34;&gt;https://t.co/FQKW2eoLlw&lt;/a&gt;&lt;/p&gt;&amp;mdash; Christian Posta (@christianposta) &lt;a href=&#34;https://twitter.com/christianposta/status/1080483078139572229?ref_src=twsrc%5Etfw&#34;&gt;January 2, 2019&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async src=&#34;https://platform.twitter.com/widgets.js&#34; charset=&#34;utf-8&#34;&gt;&lt;/script&gt;



&lt;p&gt;著名技术网红 Christian Posta 跳槽了，又是这个 &lt;a href=&#34;https://solo.io&#34; target=&#34;_blank&#34;&gt;solo.io&lt;/a&gt;，这就不能不好奇了。在网站上浏览一圈，感觉脑洞大开，不管是否现实，真的有趣，一时手痒，又拿出祖传的 Hello world，有了这篇文章。&lt;/p&gt;

&lt;h2 id=&#34;产品&#34;&gt;产品&lt;/h2&gt;

&lt;p&gt;&lt;a href=&#34;https://solo.io&#34; target=&#34;_blank&#34;&gt;Solo.io&lt;/a&gt; 首页上列出了六个产品：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/solo-io/gloo&#34; target=&#34;_blank&#34;&gt;Gloo&lt;/a&gt;：混合应用网关；&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.solo.io/glooe&#34; target=&#34;_blank&#34;&gt;GlooE&lt;/a&gt;：Gloo 的企业版；&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/solo-io/supergloo&#34; target=&#34;_blank&#34;&gt;SuperGloo&lt;/a&gt;：服务网格编排器；&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/solo-io/sqoop&#34; target=&#34;_blank&#34;&gt;Sqoop&lt;/a&gt;：构建在 Gloo 之上的 GraphQL 引擎，提供跨 API 的查询支持；&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/solo-io/unik&#34; target=&#34;_blank&#34;&gt;UniK&lt;/a&gt;：将代码编译为 unikernels 和 MicroVM；&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/solo-io/squash&#34; target=&#34;_blank&#34;&gt;Squash&lt;/a&gt;：在多云环境下为 IDE 提供微服务调试支持。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;自然我最感兴趣的就是 SuperGloo 和 Gloo 了。宣发稿中已经做出了很多介绍，根据 CLI Reference 看看其中的亮点。&lt;/p&gt;

&lt;h3 id=&#34;supergloo&#34;&gt;SuperGloo&lt;/h3&gt;

&lt;p&gt;注意，这是一个“网格编排器”，因此其特性都是&lt;strong&gt;跨网格的&lt;/strong&gt;。&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;支持 Istio、Consul、Linkerd2 以及 AppMesh 的安装部署；&lt;/li&gt;
&lt;li&gt;路由规则：

&lt;ul&gt;
&lt;li&gt;流量迁移；&lt;/li&gt;
&lt;li&gt;故障注入；&lt;/li&gt;
&lt;li&gt;超时控制；&lt;/li&gt;
&lt;li&gt;重试控制；&lt;/li&gt;
&lt;li&gt;CORS 策略；&lt;/li&gt;
&lt;li&gt;流量镜像；&lt;/li&gt;
&lt;li&gt;Header 处理。&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;安全加固：

&lt;ul&gt;
&lt;li&gt;策略管理；&lt;/li&gt;
&lt;li&gt;mTLS；&lt;/li&gt;
&lt;li&gt;Ingress 加固&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;事实上这部分的特性主要是基于 Istio 的实现，Linkerd2 和 Consul 自身的功能还相当匮乏，具体情况可以参看其&lt;a href=&#34;https://supergloo.solo.io/#roadmap&#34; target=&#34;_blank&#34;&gt;路线快照&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&#34;gloo&#34;&gt;Gloo&lt;/h3&gt;

&lt;p&gt;作为一个混合应用网关，其最大特色就是跨云的网关支持：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;支持 Upstream：

&lt;ul&gt;
&lt;li&gt;Kubernetes&lt;/li&gt;
&lt;li&gt;AWS&lt;/li&gt;
&lt;li&gt;Azure&lt;/li&gt;
&lt;li&gt;Consule&lt;/li&gt;
&lt;li&gt;Static&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;VirtualService：在网关上定义虚拟服务，并在此基础上提供限流。&lt;/li&gt;
&lt;li&gt;路由：在虚拟服务中定义访问的路由规则。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;gloo-初体验&#34;&gt;Gloo 初体验&lt;/h2&gt;

&lt;p&gt;下面我们会使用 Gloo 将一个 Kubernetes 集群上的 HTTPBIN 服务和一个运行在 Azure 上的 Function 粘合起来，合作提供服务，并在最后进行限流测试。&lt;/p&gt;

&lt;h2 id=&#34;gloo-部署&#34;&gt;Gloo 部署&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Gloo 要求 Kubernetes 版本在 1.8 以上&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;使用脚本安装客户端：&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;curl -sL https://run.solo.io/gloo/install | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;按照后续指引完成之后，就安装好了 glooctl 的客户端了，接下来是部署 Gloo：&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-shell&#34;&gt;$ glooctl install kube

$ kubectl get po -n gloo-system
NAME                            READY   STATUS    RESTARTS   AGE
discovery-78bb6fff4c-86t9c      1/1     Running   0          1m
gateway-6bc69b9cdc-4cgpv        1/1     Running   0          1m
gateway-proxy-bd895c6db-pxk8q   1/1     Running   0          1m
gloo-7588c6d774-25z5f           1/1     Running   0          1m

$ kubectl get svc -n gloo-system
NAME            TYPE           CLUSTER-IP       EXTERNAL-IP      PORT(S)          AGE
gateway-proxy   LoadBalancer   10.245.237.65    203.129.214.16   8080:30859/TCP   1m
gloo            ClusterIP      10.245.194.168   &amp;lt;none&amp;gt;           9977/TCP         1m
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;这样 Gloo 就成功启动并运行了。&lt;/p&gt;

&lt;h3 id=&#34;部署-kubernetes-应用&#34;&gt;部署 Kubernetes 应用&lt;/h3&gt;

&lt;p&gt;首先部署我们的老朋友 httpbin：&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-shell&#34;&gt;
$ kubectl create deployment httpbin --image=citizenstig/httpbin
deployment.apps/httpbin created
$ kubectl expose deploy httpbin --name=httpbin --port 8000 --selector=&amp;quot;app=httpbin&amp;quot;
service/httpbin exposed
$ kubectl get svc httpbin
NAME      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
httpbin   ClusterIP   10.245.47.195   &amp;lt;none&amp;gt;        8000/TCP   1m
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;服务已经成功建立，是缺省的 ClusterIP 类型。&lt;/p&gt;

&lt;h2 id=&#34;通过-gloo-提供对外服务&#34;&gt;通过 Gloo 提供对外服务&lt;/h2&gt;

&lt;p&gt;我们希望通过 &lt;code&gt;http://[service-ip]/httpbin/&lt;/code&gt; 的形式，透过 Gloo 的负载均衡服务，对外开放 httpbin 的 API。在 Gloo 中首先通过其发现服务，查找系统中可用的 Upstream：&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-shell&#34;&gt;$ glooctl get upstreams

+--------------------------------+------------+----------+------------------------------+
|            UPSTREAM            |    TYPE    |  STATUS  |           DETAILS            |
+--------------------------------+------------+----------+------------------------------+
| default-httpbin-8000           | Kubernetes | Accepted | svc name:      httpbin       |
|                                |            |          | svc namespace: default       |
|                                |            |          | port:          8000          |
......
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;可以看到，Gloo 使用 Kubernetes Service 创建了 Upstream；&lt;code&gt;default-httpbin-8000&lt;/code&gt;。可以使用 &lt;code&gt;glooctl get upstream default-httpbin-8000 -o yaml&lt;/code&gt; 获取其定义：&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-yaml&#34;&gt;discoveryMetadata: {}
metadata:
  labels:
    app: httpbin
    discovered_by: kubernetesplugin
  name: default-httpbin-8000
  namespace: gloo-system
  resourceVersion: &amp;quot;13678&amp;quot;
status:
  reportedBy: gloo
  state: Accepted
upstreamSpec:
  kube:
    selector:
      app: httpbin
    serviceName: httpbin
    serviceNamespace: default
    servicePort: 8000
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;接下来为服务创建一个 &lt;code&gt;httpbin&lt;/code&gt; 路径：&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-shell&#34;&gt;$ glooctl add route \
  --path-prefix /httpbin \
  --dest-name default-httpbin-8000 \
  --prefix-rewrite /
selected virtualservice default for route
+-----------------+---------+------+----------+---------+--------------------------------+
| VIRTUAL SERVICE | DOMAINS | SSL  |  STATUS  | PLUGINS |             ROUTES             |
+-----------------+---------+------+----------+---------+--------------------------------+
| default         | *       | none | Accepted |         | /httpbin -&amp;gt;                    |
|                 |         |      |          |         | default-httpbin-8000           |
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;可以看到，为了创建这个路由规则，首先创建了缺省的虚拟服务。&lt;/p&gt;

&lt;h2 id=&#34;测试服务&#34;&gt;测试服务&lt;/h2&gt;

&lt;pre&gt;&lt;code class=&#34;language-shell&#34;&gt;$ export GATEWAY_URL=$(glooctl gateway url)
$ curl ${GATEWAY_URL}/httpbin/get
{
  &amp;quot;args&amp;quot;: {},
  &amp;quot;headers&amp;quot;: {
    &amp;quot;Accept&amp;quot;: &amp;quot;*/*&amp;quot;,
    &amp;quot;Content-Length&amp;quot;: &amp;quot;0&amp;quot;,
    &amp;quot;Host&amp;quot;: &amp;quot;206.189.254.16:8080&amp;quot;,
    &amp;quot;User-Agent&amp;quot;: &amp;quot;curl/7.54.0&amp;quot;,
    &amp;quot;X-Envoy-Expected-Rq-Timeout-Ms&amp;quot;: &amp;quot;15000&amp;quot;,
    &amp;quot;X-Envoy-Original-Path&amp;quot;: &amp;quot;/httpbin/get&amp;quot;,
    &amp;quot;X-Request-Id&amp;quot;: &amp;quot;1bb19f60-57c9-43aa-b78a-1cd556cc5800&amp;quot;
  },
  &amp;quot;origin&amp;quot;: &amp;quot;10.244.93.3&amp;quot;,
  &amp;quot;url&amp;quot;: &amp;quot;http://206.189.254.16:8080/get&amp;quot;
}
$ curl ${GATEWAY_URL}/httpbin/ip
{
  &amp;quot;origin&amp;quot;: &amp;quot;10.244.93.3&amp;quot;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;可以看到，我们成功得到了想要的路径映射。&lt;/p&gt;

&lt;h2 id=&#34;为-lambda-创建-upstream&#34;&gt;为 Lambda 创建 Upstream&lt;/h2&gt;

&lt;p&gt;Lambda 是不会被自动发现的，因此我们要手工创建，这里采用交互式的方法：&lt;/p&gt;

&lt;h3 id=&#34;创建-secret&#34;&gt;创建 Secret&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&#34;language-shell&#34;&gt;glooctl create secret aws -i
? Please choose a namespace gloo-system
? name of secret aws
? Enter AWS Access Key ID (leave empty to read credentials from ~/.aws/credentials):  ...
? Enter AWS Secret Key (leave empty to read credentials from ~/.aws/credentials):  ...
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;创建-upstream&#34;&gt;创建 Upstream&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&#34;language-shell&#34;&gt;$ glooctl create upstream -i
? What type of Upstream do you want to create? aws
? What region are the AWS services in for this upstream? us-east-2
? Choose an AWS credentials secret to link to this upstream:  gloo-system.aws
? namespace: gloo-system
? name: hello-lambda
+--------------+------+----------+-------------------------+
|   UPSTREAM   | TYPE |  STATUS  |         DETAILS         |
+--------------+------+----------+-------------------------+
| hello-lambda | AWS  | Accepted | region: us-east-2       |
|              |      |          | secret: gloo-system.aws |
|              |      |          |                         |
+--------------+------+----------+-------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;为-lambda-创建-route&#34;&gt;为 Lambda 创建 Route&lt;/h3&gt;

&lt;p&gt;接下来为服务创建一个 &lt;code&gt;httpbin&lt;/code&gt; 路径：&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-shell&#34;&gt;$ glooctl add route \
  --path-prefix /lambda \
  --dest-name hello-lambda \
  --function hello-world:1
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;再次成功创建之后，调用新生成的 &lt;code&gt;/lambda&lt;/code&gt;，&lt;strong&gt;并未成功&lt;/strong&gt;。&lt;/p&gt;

&lt;h2 id=&#34;为-azure-function-app-创建-route&#34;&gt;为 Azure function app 创建 Route&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;目前并不支持 Azure Secret 的创建。&lt;/strong&gt;，所以就连 Upstream 也无法开始了。&lt;/p&gt;

&lt;h2 id=&#34;总结&#34;&gt;总结&lt;/h2&gt;

&lt;p&gt;梦想很丰满。。参看视频：&lt;/p&gt;


&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
  &lt;iframe src=&#34;https://www.youtube.com/embed/ISR3G0CAZM0&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; allowfullscreen title=&#34;YouTube Video&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;

</description>
    </item>
    
  </channel>
</rss>
