Alodi: Creating the environment has never been easier

Imagine you meet a variety of quick and easy generation system temporary environment

In "Alodi: To maintain secrecy I developed a system," the article mentioned we have developed a system to quickly generate temporary test environment, just three months Hundreds environment has been created to simplify the work and save time, but also by the small partners affirmation of this article to introduce the principle of Alodi achieve, as well as updated features

achieved goals

Alodi main purpose is the easiest and fastest way to create a test environment, while generating a random access address provided temporary access

Create an environment exactly how simple it? Such as the following: Select an item -> click on "Create environment" -> Input Tag -> click on the "Build & Deploy" -> wait created

Once created, you can find the task to create the environment in the deployment list, where you can access directly through the newly created domain environment, or a number of management, such as the creation of a log view, container Log view, into the container terminal troubleshooting, bind the new domain name, or the destruction of the environment

Creation process

Create a temporary environment through Celery Django's to asynchronous completion, through Channels Django is to establish a WebSocket channel real-time access task log output

The same process of launching a project to deploy a unified template will be written, for example JavaWeb project will write a template for all JavaWeb projects, NodeJS project will write a template for all NodeJS projects, create a temporary environment is actually carried out by a task template Celery

In the task template defines the task to do, generally includes the following: create a temporary directory -> Pull Code -> compile -> Generate DOCKERFILE -> Packaging Docker image -> image uploaded to a private warehouse - -> create Kubernetes resources -> check Pod status -> Finish

每一次任务都会生成一个全新的环境,一个全新的域名,所以无论有多少个版本多少个用户在并行测试都不会相互影响

临时域名

每一次都生成一个临时的域名提供访问,这样做的初衷是希望自己生成的环境只有自己知道,避免公共域名的传播,在一定程度上实现保密

域名绑定Kubernetes的ingress,可以实现通过域名访问到对应的容器,这里需要思考的一个问题是:需要给每个临时域名创建DNS解析吗?

员工的电脑上都配置了内部DNS,而这个DNS不支持API操作,所以在开始的时候考虑的两种方案

  1. 用户自己绑定hosts
  2. 新建DNS,支持API

这两种方案都不是很好,新建DNS还需要用户都修改自己的DNS指向到新DNS,而绑定hosts无疑会增加使用成本,那该如何处理呢?

DNS泛域名解析,利用通配符*来做次级域名以实现所有的次级域名均指向同一IP地址

在内部DNS上创建一条匹配所有的次级域名的记录,指向到Kubernetes的Ingress服务器,例如

*.ops-coffee.cn -> 192.168.107.143

这样无论生成任何xxx.ops-coffee.cn的域名都可以请求到Kubernetes的Ingress,然后Ingress转发请求到对应的service,最终到pod,完美的解决了这个问题

域名绑定

解决了域名访问的问题,还面临另外一个问题就是用户有需求绑定生产域名进行测试,因为有一些第三方平台,例如微信分享等是有域名白名单的,只有白名单内的域名可以进行操作,这种情况下生成的临时域名就无法使用了,需要支持绑定生产域名进行测试

Alodi系统内绑定新域名也非常简单,只需要点击“绑定新域名”按钮,填写对应的域名提交就好

绑定新域名实现原理是多添加一个Ingress,与已存在的service相关联,同时会维护一个新绑定域名与Service的关系表,主要目的是在绑定新域名时判断域名是否已经被绑定,因为Ingress绑定的域名不能重复,如果发现有用户绑定已经被绑定过的域名则会提示其与先绑定的用户协商使用

由于可以绑定任意域名,所以没办法添加DNS解析,故这里需要用户自己绑定hosts了

容器操作

毕竟是测试环境,出现问题是难免的,一旦有问题用户就需要拉日志,甚至是登陆系统debug排查

应用内的日志有接入ELK系统,容器的启动日志Alodi系统也提供查看功能,点击“Log”按钮即可查看

Log查看通过调用Kubernetes API的read_namespaced_pod_log方法来实现,Kubernetes的API比较多,鉴于篇幅不在文章中细说,有整理一份文档:Kubernetes Python API中文使用说明

SSH进入Pod容器也给集成到了Alodi系统中,之前有一篇文章专门介绍:Django实现WebSSH操作Kubernetes Pod,有很多小伙伴按照文章内容实现了集成

销毁环境

Alodi系统希望用户能够快速创建环境,用完销毁环境,不长时间占用资源,所以设计了定期销毁和用户主动销毁策略,定期销毁是会销毁超过n天没有使用的环境,而主动销毁只需要点击“点击销毁”按钮即可

销毁环境会删除创建的临时目录,拉取的代码,生成的文件,以及Kubernetes上的各种资源

扫码关注公众号查看更多实用文章

这便是Alodi,一个快速创建临时环境的系统


相关文章推荐阅读:

Guess you like

Origin www.cnblogs.com/37Y37/p/12190404.html