Rio Shoubashoujiao learn: how to create a container of one-stop application deployment experience

November 19, the industry's most widely used Kubernetes management platform creator Rancher Labs (hereinafter referred to as Rancher) announced that Rio has released beta version, which is deploying Kubernetes application engine. It launched in May this year, and now the latest version is v0.6.0. Rio combines a variety of native cloud technology, which simplifies the code released from a test environment to a production environment processes, while ensuring a strong and secure code experience.

What is Rio?

The figure is Rio's architecture:

Rio using techniques such as Kubernetes, knative, linkerd, cert-manager, buildkit gloo and the like, and combining them to provide a complete environment for the application deployment user.

Rio has the following features:

  1. Construction of the code from the source code, and deploy them to the cluster Kubernetes

  2. DNS record is automatically created for the application and use Let's Encrypt TLS certificate to protect these endpoints

  3. QPS based on workload indicators and automatic scaling capacity

  4. Support canary publishing, publishing, and blue and green A / B deployment

  5. Supports routing traffic through the Service Grid

  6. Support for serverless volume reduction to zero of the workload

  7. Git trigger deployment

Rancher ecological products

Rio is part of the ecology of the entire product Rancher, these products support the deployment and operation and maintenance of the container from the operating system to the application of the application. When such as Rio and Rancher 2.3, k3s RKE and other products used in conjunction with, companies can get the full experience of deploying and managing applications and containers.

Depth understanding of Rio

To learn how to achieve these functions Rio, we come to understand some of the concepts and works.

Installation Rio

Preparatory

  • Kubernetes version 1.15 or more clusters of Kubernetes

  • Configured for the cluster kubeconfig (ie, the context is that you want to install the Rio clusters)

  • Installed in your $ PATH Rio CLI tool, refer to the following links to learn how to install the CLI:
    https://github.com/rancher/rio/blob/master/README.md

installation

使用安装好的Rio CLI工具,调用rio install。你可能需要考虑以下情况:

ip-address:节点的IP地址的逗号分隔列表。你可以在以下情况使用:

  • 你不使用(或不能使用)layer-4的负载均衡器

  • 你的节点IP不是你希望流量到达的IP地址(例如,你使用有公共IP的EC2实例)

服 务

在Rio中,service是一个基本的执行单位。从Git仓库或容器镜像实例化之后,一个service由单个容器以及服务网格的关联sidecar组成(默认启用)。例如,运行使用Golang构建的一个简单的“hello world”应用程序。

rio run https://github.com/ebauman/rio-demo

或者运行容器镜像版本:

rio run ebauman/demo-rio:v1

还有其他选项也可以传递给rio run,如需要公开的任意端口(-p 80:8080/http),或者自动扩缩的配置(--scale 1-10)。你可以通过这一命令rio help run,查看所有可传递的选项。

想要查看你正在运行的服务,请执行rio ps

$ rio ps
NAME            IMAGE                               ENDPOINT
demo-service    default-demo-service-4dqdw:61825    https://demo-service...

每次你运行一个新的服务,Rio将会为这一服务生成一个全局性的端点:

$ rio endpoints
NAME           ENDPOINTS
demo-service   https://demo-service-default.op0kj0.on-rio.io:30282

请注意,此端点不包括版本——它指向由一个common name标识的服务,并且流量根据服务的权重进行路由。

自动DNS&TLS

默认情况下,所有Rio集群都将为自己创建一个on-rio.io主机名,并以随机字符串开头(如lkjsdf.on-rio.io)。该域名成为通配符域名,它的记录解析到集群的网关。如果使用NodePort服务,则该网关可以是layer-4负载均衡器,或者是节点本身。

除了创建这个通配符域名,Rio还会使用Let’s Encrypt为这个域名生成一个通配符证书。这会允许自动加密任何HTTP工作负载,而无需用户进行配置。要启动此功能,请传递-p参数,将http指定为协议,例如:

rio run -p 80:8080/http ...

自动扩缩容

Rio可以根据每秒所查询到的指标自动扩缩服务。为了启用这一特性,传递--scale 1-10作为参数到rio run,例如:

rio run -p 80:8080/http -n demo-service --scale 1-10 ebauman/rio-demo:v1

执行这个命令将会构建ebauman/rio-demo并且部署它。如果我们使用一个工具来添加负载到端点,我们就能够观察到自动扩缩容。为了证明这一点,我们需要使用HTTP端点(而不是HTTPS),因为我们使用的工具不支持TLS:

$ rio inspect demo-service
<snipped>
endpoints:
- https://demo-service-v0-default.op0kj0.on-rio.io:30282
- http://demo-service-v0-default.op0kj0.on-rio.io:31976
<snipped>

rio inspect除了端点之外还会显示其他信息,但我们目前所需要的是端点信息。使用HTTP端点以及HTTP基准测试工具rakyll / hey,我们可以添加综合负载:

hey -n 10000 http://demo-service-v0-default.op0kj0.on-rio.io:31976

这将会发送10000个请求到HTTP端点,Rio将会提高QPS并适当扩大规模,执行另一个rio ps将会展示已经扩大的规模:

$ rio ps
NAME            ...     SCALE       WEIGHT
demo-service    ...     2/5 (40%)   100%

分阶段发布、金丝雀部署以及权重

注意

对于每个服务,都会创建一个全局端点,该端点将根据基础服务的权重路由流量。

Rio可以先交付新的服务版本,然后再推广到生产环境。分阶段发布一个新的版本十分简单:

rio stage --image ebauman/rio-demo:v2 demo-service v2

这一命令使用版本v2,分阶段发布demo-service的新版本,并且使用容器镜像ebauman/rio-demo:v2。我们通过执行rio ps这一命令,可以看到新阶段的发布:

$ rio ps
NAME                IMAGE                   ENDPOINT                    WEIGHT
demo-service@v2     ebauman/rio-demo:v2     https://demo-service-v2...  0%
demo-service        ebauman/rio-demo:v1     https://demo-service-v0...  100%

请注意,新服务的端点具有v2的新增功能,因此即使权重设置为0%,访问此端点仍将带你进入服务的v2。这可以让你能够在向其发送流量之前验证服务的运行情况。

说到发送流量:

$ rio weight demo-service@v2=5%
$ rio ps
NAME                IMAGE                   ENDPOINT                    WEIGHT
demo-service@v2     ebauman/rio-demo:v2     https://demo-service-v2...  5%
demo-service        ebauman/rio-demo:v1     https://demo-service-v0...  95%

使用rio weight命令,我们现在将发送我们5%的流量(从全局的服务端点)到新版本。当我们觉得demo-service的v2性能感到满意之后,我们可以将其提升到100%:

$ rio promote --duration 60s demo-service@v2
demo-service@v2 promoted

超过60秒之后,我们的demo-service@v2服务将会逐渐提升到接收100%的流量。在这一过程中任意端点上,我们可以执行rio ps,并且查看进程:

$ rio ps
NAME                IMAGE                   ENDPOINT                    WEIGHT
demo-service@v2     ebauman/rio-demo:v2     https://demo-service-v2...  34%
demo-service        ebauman/rio-demo:v1     https://demo-service-v0...  66%

路由(Routing)

Rio可以根据主机名、路径、方法、标头和cookie的任意组合将流量路由到端点。Rio还支持镜像流量、注入故障,配置retry逻辑和超时。

创建一个路由器

为了开始制定路由决策,我们必须首先创建一个路由器。路由器代表一个主机名和一组规则,这些规则确定发送到主机名的流量如何在Rio集群内进行路由。你想要要定义路由器,需要执行rio router add。例如,要创建一个在默认测试时接收流量并将其发送到demo-service的路由器,请使用以下命令:

rio route add testing to demo-service

这将创建以下路由器:

$ rio routers
NAME             URL                            OPTS    ACTION      TARGET
router/testing   https://testing-default.0pjk...        to          demo-service,port=80

发送到https://testing-default...的流量将通过端口80转发到demo-service。

请注意,此处创建的路由为testing-default. 。Rio将始终使用命名空间资源,因此在这种情况下,主机名测试已在默认命名空间中进行了命名。要在其他命名空间中创建路由器,请将 -n <namespace>传递给rio命令:

rio -n <namespace> route add ...

基于路径的路由

为了定义一个基于路径的路由,当调用rio route add时,指定一个主机名加上一个路径。这可以是新路由器,也可以是现有路由器。

$ rio route add testing/old to demo-service@v1

以上命令可以创建一个基于路径的路由,它会在https://testing-default. /old接收流量,并且转发流量到 demo-service@v1服务。

标头和基于方法的路由

Rio支持基于HTTP标头和HTTP verbs的值做出的路由策略。如果你想要创建基于特定标头路由的规则,请在rio route add命令中指定标头:

$ rio route add --header X-Header=SomeValue testing to demo-service

以上命令将创建一个路由规则,它可以使用一个X-Header的HTTP标头和SomeValue的值将流量转发到demo-service。类似地,你可以为HTTP方法定义规则:

$ rio route add --method POST testing to demo-service

故障注入

Rio路由有一项有趣的功能是能够将故障注入响应中。通过定义故障路由规则,你可以设置具有指定延迟和HTTP代码的失败流量百分比:

$ rio route add --fault-httpcode 502 --fault-delay-milli-seconds 1000 --fault-percentage 75 testing to demo-service

其他路由选项

Rio支持按照权重分配流量、为失败的请求重试逻辑、重定向到其他服务、定义超时以及添加重写规则。要查看这些选项,请参阅以下链接:

https://github.com/rancher/rio

自动构建

将git仓库传递给rio run将指示Rio在提交到受监控的branch(默认值:master)之后构建代码。对于Github仓库,你可以通过Github webhooks启动此功能。对于任何其他git repo,或者你不想使用webhooks,Rio都会提供一项“gitwatcher”服务,该服务会定期检查您的仓库中是否有更改。

Rio还可以根据受监控的branch的拉取请求构建代码。如果你想要进行配置,请将--build-pr传递到rio run。还有其他配置这一功能的选项,包括传递Dockerfile的名称、自定义构建的镜像名称以及将镜像推送到指定的镜像仓库。

堆栈和Riofile

Rio使用称为Riofile的docker-compose-style manifest定义资源

configs:
  conf:
    index.html: |-
      <!DOCTYPE html>
      <html>
      <body>

      <h1>Hello World</h1>

      </body>
      </html>
services:
  nginx:
    image: nginx
    ports:
    - 80/http
    configs:
    - conf/index.html:/usr/share/nginx/html/index.html

Riofile定义了一个简单的nginx Hello World网页所有必要的组件。通过rio up部署它,会创建一个Stack(堆栈),它是Riofile定义的资源的集合。

Riofile具有许多功能,例如观察Git库中的更改以及使用Golang模板进行模板化。

其他Rio组件

Rio还有许多功能,例如configs、secrets以及基于角色访问控制(RBAC)。详情可参阅:

https://rio.io/

Rio可视化

Rio Dashboard

Rio的beta版本包括了一个全新的仪表盘,使得Rio组件可视化。要访问此仪表盘,请执行命令:rio dashboard。在有GUI和默认浏览器的操作系统上,Rio将自动打开浏览器并加载仪表盘。

你可以使用仪表盘来创建和编辑堆栈、服务、路由等。此外,可以直接查看和编辑用于各种组件技术(Linkerd、gloo等)的对象,尽管不建议这样做。仪表盘目前处于开发的早期阶段,因此某些功能的可视化(如自动缩放和服务网格)尚不可用。

Linkerd

作为Rio的默认服务网格,Linked附带了一个仪表盘作为产品的一部分。该仪表盘可以通过执行rio linkerd来使用,它将代理本地本地主机流量到linkerd仪表盘(不会在外部公开)。与Rio仪表盘类似,有GUI和默认浏览器的操作系统上,Rio将自动打开浏览器并加载仪表盘:

Linkerd仪表盘显示了Rio集群的网格配置、流量和网格组件。Linkerd提供了Rio路由的某些功能组件,因此这些配置可能会显示在此仪表盘上。还有一些工具可用于测试和调试网格配置和流量。

结 论

Rio为用户提供许多功能,是一款强大的应用程序部署引擎。这些组件可以在部署应用程序时为开发人员提供强大的功能,使流程稳定而安全,同时轻松又有趣。在Rancher产品生态中,Rio提供了企业部署和管理应用程序和容器的强大功能。

如果你想了解Rio的更多信息,欢迎访问Rio主页或Github主页:

https://rio.io

https://github.com/rancher/rio

Guess you like

Origin www.cnblogs.com/rancherlabs/p/11926447.html