当前位置:网站首页>Deliver cloud-native microservices applications with Zadig
Deliver cloud-native microservices applications with Zadig
2022-08-02 00:07:00 【JavaMonsterr】
微服务示例
Here we use the open source project is https://github.com/GoogleCloudPlatform/microservices-demo,The open source project called Online Boutique(https://onlineboutique.dev/),Is a native of cloud services demo application,其中包含 11 个微服务,The application is a based on Web The e-commerce application,In which users can browse the goods、Add them to the cart and buy them.
Based on the project for Zadig Optimized modification,项目地址: https://github.com/cnych/microservices-demo
该项目由 11 A micro services written in different languages,它们通过 gRPC 相互通信.架构如下所示.
微服务架构
The function of each service description shown in the following table.
服务功能
Zadig 项目
接下来我们来使用 Zadig To delivery of the services,Use front and similar.
首先新建一个名为 microservices-demo 的项目,项目类型为 K8s YAML 项目.
新建项目
Click the new button immediately,And then into the project initialization page.
项目初始化
Click next to enter service configuration page,We know that service template can manually create、Code synchronization in warehouse or existing K8s Resources in the import and to.We here in service template code warehouse,So choose to synchronize from the code base,选择对应的代码仓库、Branch and the corresponding resource directory listing,Then click the sync button to synchronize the corresponding service to Zadig 中来.
同步服务
We can see contains after synchronization to come over here 12 个服务,Each service template were directly display the,But because it is through the warehouse synchronous,A template is a read-only mode,On the right side will be read automatically to the corresponding image information service.
注意:Zadig After reading the resource list, 会以 K8s YAML The container name as the only key 进行去重 ,所以在编写 K8s YAML Don't let the container name repeat,Otherwise the import will be lost after service.
服务模板
Click on the right side of the read behind the image of the service component of add build button,To configure the service image of how to build.
First of all need to add the service code source information,The code here in GitLab 上面,So to add the corresponding code warehouse and branch information.We here all service code in the code for the warehouse under the root directory of src 目录下.
代码结构
这属于典型的 Monorepo 类型的仓库(单体),Each service and we are not configured to submodule,So all throughout the code to each service the build warehouse Clone 下来,But actually we only need one of these services can be,Git Is to support the operation of,For example, we now just want to get adservice The service data,Could be obtained by the following way.
$ mkdir microservices-demo && cd microservices-demo
$ git init
$ git remote add origin [email protected]:course/microservices-demo.git
$ git config core.sparsecheckout true
$ git sparse-checkout set "src/adservice"
$ git pull --depth 1 origin main
remote: Enumerating objects: 307, done.
remote: Counting objects: 100% (307/307), done.
remote: Compressing objects: 100% (234/234), done.
remote: Total 307 (delta 72), reused 185 (delta 39), pack-reused 0
Receiving objects: 100% (307/307), 9.55 MiB | 5.28 MiB/s, done.
Resolving deltas: 100% (72/72), done.
From git.k8s.local:course/microservices-demo
* branch main -> FETCH_HEAD
* [new branch] main -> origin/main
$ ls -la src
total 0
drwxr-xr-x 3 cnych staff 96 Jul 15 14:10 .
drwxr-xr-x 4 cnych staff 128 Jul 15 14:10 ..
drwxr-xr-x 12 cnych staff 384 Jul 15 14:10 adservice
Through the above ways can only obtain the specified directory code,但是遗憾的是 Zadig This function does not currently support,Subsequent may support!
After the code source configuration,The most important is to add general build script.
构建服务
We have here is actually configure how to build the mirror,The corresponding script as shown below:
#!/bin/bash
set -e
cd $WORKSPACE/$REPONAME_0/src/adservice
docker build -t $IMAGE -f Dockerfile .
docker push $IMAGE
First you need to enter to the current service under the root directory of the code,我们这里使用的是 cd $WORKSPACE/$REPONAME_0/src/adservice 命令,其中的 $WORKSPACE、$REPONAME_0、$IMAGE Both for the construction of the built-in variables,$WORKSPACE Said work root directory,而 $REPONAME_0 The name of the first code warehouse said configuration,也就是 microservices-demo.
构建变量
After entering into the service under the root directory,我们只需要执行 docker build Command to build the mirror can be,Each service is provided for under the root directory of the Dockerfile 文件,Build image using variable $IMAGE 代替,Will use add the default image of warehouse.
The default image of naming rules as shown in the following,We can also custom.
The mirror command rules
After finish build configuration,Remember to save building,Configuration in the same way all service build.
After the completion of the service configuration start next to join the environment,Also by default will automatically create a set of dev 和 qa 的环境以及 3 条工作流.
加入环境
After joining the environment can see the corresponding 3 The workflow,点击完成即可.
工作流
执行工作流
这样项目就创建成功了,Now we are in dev Environment to run the workflow.点击执行工作流,Can choose what we want to build service in service,You can select a can also select multiple services.
执行任务
After the same task execution will perform the configuration general-purpose scripting,And then the corresponding service deployment to K8s 集群中去.
任务详情
Will carry out in the environment after the completion of all services page can see all of the service status and the latest image information.
dev环境
Each service deployed to properly dev 环境后,查看对应的 Pod 状态:
$ kubectl get pods -n microservices-demo-env-dev
NAME READY STATUS RESTARTS AGE
adservice-5b5b97cf59-b7d6g 1/1 Running 0 21m
cartservice-7d66bd5c4-wxd6v 1/1 Running 0 15m
checkoutservice-6dbc8cdc46-fqrnx 1/1 Running 0 14m
currencyservice-54fccf7b9f-c29h5 1/1 Running 0 13m
emailservice-844b6c9b58-j5smc 1/1 Running 0 13m
frontend-649699cc5-s5ggp 1/1 Running 0 12m
loadgenerator-565cdbb5dc-6dtrb 1/1 Running 0 5m42s
paymentservice-fd8f95f79-4889n 1/1 Running 0 11m
productcatalogservice-775db476b6-l4s2t 1/1 Running 0 6m47s
recommendationservice-79f558bc9b-jx69n 1/1 Running 0 6m47s
redis-cart-f9bdd7959-qtc9n 1/1 Running 0 34m
shippingservice-f789c4494-ktbnz 1/1 Running 0 6m43s
$ kubectl get svc -n microservices-demo-env-dev
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
adservice ClusterIP 10.96.40.23 <none> 9555/TCP 41m
cartservice ClusterIP 10.110.0.136 <none> 7070/TCP 41m
checkoutservice ClusterIP 10.109.209.29 <none> 5050/TCP 41m
currencyservice ClusterIP 10.98.43.229 <none> 7000/TCP 41m
emailservice ClusterIP 10.101.67.47 <none> 5000/TCP 41m
frontend ClusterIP 10.96.37.222 <none> 80/TCP 41m
frontend-external LoadBalancer 10.109.168.181 192.168.0.53 80:30090/TCP 41m
paymentservice ClusterIP 10.105.223.48 <none> 50051/TCP 41m
productcatalogservice ClusterIP 10.102.112.64 <none> 3550/TCP 41m
recommendationservice ClusterIP 10.99.127.143 <none> 8080/TCP 41m
redis-cart ClusterIP 10.111.15.205 <none> 6379/TCP 41m
shippingservice ClusterIP 10.104.122.207 <none> 50051/TCP 41m
The last is through the service frontend-external 这个 LoadBalancer 类型的 Service To expose the service,We can directly through the distribution of IP 192.168.0.53 来访问服务了.
frontend external
触发器
We can also give same service add a trigger to trigger the task,In the workflow editor page click on the left side of the trigger to add,勾选 Webhook -> 添加配置,We can add a only for first adservice The service of the trigger,Select the corresponding code library、To deploy the service,File directory is the most critical part of the configuration,What is the code in the warehouse file changes would trigger our mission,我们的配置为:
src/adservice/ !.md !.gitignore
The representation of the segment configuration when code in the warehouse src/adservice/ Folder has the following code changes,并且不是 .md 或者 .gitignore File will trigger the task.
触发器
Remember to keep the configuration when.Now we can go to modify the adservice 服务中的代码,修改代码 src/adservice/src/main/java/hipstershop/AdService.java,比如我们将 177 行的 50%修改为 60%,然后提交代码到 main 分支.
修改代码
When we refer to the above code push 到 main 分支后,Zadig Immediately triggered a new task.
webhook trigger
The task execution after the success we can go to see if the product's page effect.
验证修改
Here I will realize the micro services continue to build,Also we can go to manually create an environment for delivery,Operating the same way.
测试用例
In addition we can also to create new test cases,In the test page click the test button to create new test cases.
新建测试
For example, we here for a go Service to do a simple test,In dependent packages can choose corresponding rely on,If there is no corresponding packages,则可以新建一个.
软件依赖
比如我们需要一个 1.17 版本的 go 环境,可以通过 系统设置 -> 软件包管理 新建一个软件包.
新建软件包
And then we back to create a test case,选择相应的依赖,The same configuration corresponding source code and test script.
测试脚本
After creation can be in the same way to perform this test case.
执行测试
Test details page and the workflow task basically consistent.
测试详情
Also can see the corresponding test report.
测试报告
In addition we can also be automated testing and workflow associated,After the update daily operation workflow environment,会自动执行自动化测试.Can be achieved as long as the environment changes,Is the first time to do the test automation.
Associated workflow
Associated after start the workflow task can see the test case.
测试用例
工作流
Zadig Will also help us build data statistics,Provide building efficiency、Deployment efficiency data such as.
Building efficiency
到这里我们就完成了使用 Zadig Continuous integration and micro service project for delivery,Of course in the actual production conditions and specific project business relationship,This needs to be able to in combination with actual needs to practice.
边栏推荐
- [Camp Experience Post] 2022 Cybersecurity Summer Camp
- security 会话并发管理
- yay 报错 response decoding failed: invalid character ‘<‘ looking for beginning of value;
- 伸展树的特性及实现
- 使用Jenkins做持续集成,这个知识点必须要掌握
- Get piggy homestay (short-term rental) data
- @Resource和@Autowired的区别
- Loading configuration of Nacos configuration center
- A brief analysis of mobile APP security testing in software testing, shared by a third-party software testing agency in Beijing
- CDH6的Hue打开出现‘ascii‘ codec can‘t encode characters
猜你喜欢
技术分享 | 接口测试中如何使用Json 来进行数据交互 ?
[LeetCode304 Weekly Competition] Two questions about the base ring tree 6134. Find the closest node to the given two nodes, 6135. The longest cycle in the graph
windows sql server 如何卸载干净?
Bean的生命周期
Data Organization --- Chapter 5 Trees and Binary Trees --- The Concept of Binary Trees --- Application Questions
SphereEx苗立尧:云原生架构下的Database Mesh研发实践
【MySQL系列】 MySQL表的增删改查(进阶)
cdh的hue上oozie启动报错,Cannot allocate containers as requested resource is greater than maximum allowed
A brief analysis of mobile APP security testing in software testing, shared by a third-party software testing agency in Beijing
一款简洁的文件传输工具
随机推荐
LocalDateTime转为Date类型
TexturePacker使用文档
ICLR 2022 Best Paper: Partial Label Learning Based on Contrastive Disambiguation
DOM 事件及事件委托
【Leetcode】470. Implement Rand10() Using Rand7()
路径压缩、、
FAST-LIO2 code analysis (2)
字节跳动面试官:请你实现一个大文件上传和断点续传
深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练
Thymeleaf简介
1个月写900多条用例,二线城市年薪33W+的测试经理能有多卷?
Various Joins of Sql
使用Ganache、web3.js和remix在私有链上部署并调用合约
security CSRF漏洞保护
检查 Oracle 版本的 7 种方法
CDH6的Hue打开出现‘ascii‘ codec can‘t encode characters
在MySQL中使用MD5加密【入门体验】
QML包管理
【Leetcode】479. Largest Palindrome Product
使用 Zadig 交付云原生微服务应用