In the previous article, we introduced how to quickly develop microservices on Rainbond through Nocalhost , and introduced the basic development process.
This article will continue the introduction above and use the Nocalhost development configuration file to achieve the following:
- One-click Run and Remote Debug
- persistent configuration
- Development Container Resource Limits
- port forwarding
What is a development configuration?
The development configuration revolves around 开发模式
, such as what image to use to enter 开发模式
, whether to enable persistence to save the content of the development container, and which files to synchronize to the development container, How to debug with one click, run services in the container with one click, etc. After configuring the correct and suitable development configuration, you can use Nocalhost 开发模式
more easily.
Deploy Rainbond + SpringCloud
Next, continue to take SpringCloud Pig as an example to debug the Pig-auth module of the Java Maven service.
Project Gitee address: https://gitee.com/zhangbigqi/pig
Deploy Rainbond
The installation of Rainbond will not be introduced in detail here, please refer to Installing Rainbond on Linux .
Deploy SpringCloud
After we connected the open source app store in Rainbond, we searched the open source app store for Spring Cloud Pig
installation 3.5.0
version.
The English name of the installed application component from the application store is an automatically generated string. We need to set the English name of the component (Deployment Name). When connecting to the cluster through Nocalhost, you can clearly distinguish the components corresponding to the Deployment.
Nocalhost docks Rainbond
- To install the Nocalhost JetBrains Plugin, please refer to the documentation to install the Nocalhost JetBrains Plugin .
- To get the K8s Kubeconfig, please refer to the documentation to get the Kubeconfig file .
- Under the
pig
namespace, find the workloadpig-auth
right-click and selectDev Config
(development configuration)
- Copy the following configuration file into
Dev Config
.
# Deployment Name
name: pig-auth
serviceType: deployment
containers:
# Deployment 主容器名称
- name: auth
dev:
# 开发镜像,该镜像包含了 Java Maven 环境
image: registry.cn-hangzhou.aliyuncs.com/zqqq/maven:3.8.6-openjdk-8
# 默认终端为 bash
shell: bash
# Rainbond 提供的 StorageClass Name
storageClass: rainbondvolumerwx
# 配置开发容器资源
resources:
limits:
memory: 4096Mi
cpu: "2"
requests:
memory: 2048Mi
cpu: "1"
persistentVolumeDirs:
# Maven 依赖包缓存路径,配合 storageClass 一起食用
- path: /root/.m2/repository
capacity: 10Gi
command:
# 一键启动命令,安装依赖包和启动 pig-auth 子模块
run:
- mvn
- install
- '&&'
- mvn
- spring-boot:run
- -pl
# 指定子模块启动
- pig-auth
# 一键 Debug 命令,安装依赖包和 Debug pig-auth 子模块
debug:
- mvn
- install
- '&&'
- mvn
- spring-boot:run
- -pl
# 指定子模块启动
- pig-auth
# Java Debug 命令
- -Dspring-boot.run.jvmArguments=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005
debug:
# 远程端口,对应Debug命令中的 address=5005
remoteDebugPort: 5005
# 选择 Java 语言
language: java
# 热加载
hotReload: true
# 文件同步
sync:
type: send
mode: gitIgnore
deleteProtection: true
# 端口转发,转发容器内的3000端口到本地3999
portForward:
- 3999:3000
One-click Run
- Right click on the workload
pig-auth
. - Select Remote Run.
- Nocalhost will automatically enter DevMode and execute Remote Run.
One-click Debug
- Right click on the workload
pig-auth
. - Select Remote Debug.
- Nocalhost will automatically enter DevMode and perform Remote Debug.
- Put a breakpoint in the code, initiate a request, and enter the IDE Debug mode.
persistent configuration
During development, most of the files we want to persist are 依赖包
日志
, and Java dependencies are also cached in this article.
rainbondvolumerwx
is the storage class provided by Rainbond by default. After filling in the following configuration, a PVC will be automatically created in the current namespace, as follows:
storageClass: rainbondvolumerwx
persistentVolumeDirs:
- path: /root/.m2/repository
capacity: 10Gi
Container Resource Limits
Limit the resources of the development container. The limit can maximize the resource utilization of the server. It can be modified by the following development configuration:
resources:
limits:
memory: 4096Mi
cpu: "2"
requests:
memory: 2048Mi
cpu: "1"
port forwarding
Forwarding the container port to the local can be modified by the following development configuration:
portForward:
- 3999:3000 # 转发容器 3000 端口到本地 3999 端口
at last
Of course, Nocalhost can debug multiple microservices at the same time. In the same way, you only need to modify the Deployment Name and Containers Name in the configuration file and the submodules of the microservice.
Nocalhost also has some things that are not mentioned in the development configuration text, such as: development environment variables, two modes of file synchronization pattern
gitignore
and so on, and Nocalhost supports multiple languages, Java only One of them, friends can explore on their own.
Nocalhost + Rainbond makes development and deployment more efficient and convenient.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。