微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹

之前的文章中我们介绍了如何通过 Nocalhost 快速开发 Rainbond 上的微服务,介绍了基本的开发流程。

本文将续接上文继续介绍,使用 Nocalhost 开发配置文件 实现以下内容:

  • 一键 Run 和 远程Debug
  • 持久化配置
  • 开发容器资源限制
  • 端口转发

「什么是开发配置?」

开发配置是围绕 开发模式 来进行的,例如使用什么镜像来进入 开发模式,是否需要开启持久化来保存开发容器的内容,将哪些文件同步到开发容器中,如何一键调试、一键运行容器内的服务等。 配置了正确且合适的开发配置后,可以在使用 Nocalhost 开发模式 时更加得心应手。

部署 Rainbond + SpringCloud

接下来继续以上文中的 SpringCloud Pig 为例,调试 Java Maven 服务的 Pig-auth 模块。

项目 Gitee 地址:https://gitee.com/zhangbigqi/pig

部署 Rainbond

这里就不详细介绍 Rainbond 的安装,请参阅 基于Linux安装Rainbond

部署 SpringCloud

我们在 Rainbond 内对接了开源应用商店后,在开源应用商店内搜索 Spring Cloud Pig 安装 3.5.0 版本。

来自应用商店安装应用组件的英文名称是自动生成的字符串,需要我们设置一下组件的英文名称(Deployment Name),通过 Nocalhost 连接到集群时可以很直观的分清楚 Deployment 对应的组件。

Nocalhost 对接 Rainbond

  1. 安装 Nocalhost JetBrains Plugin 插件,请参阅文档 安装Nocalhost JetBrains Plugin 插件
  2. 获取 K8s Kubeconfig,请参阅文档 获取 Kubeconfig 文件
  3. pig 命名空间下,找到工作负载 pig-auth 右击并选择 Dev Config (开发配置)

  1. 将以下配置文件复制到 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

一键 Run

  1. 右击工作负载 pig-auth
  2. 选择 Remote Run。
  3. Nocalhost 会自动进入 DevMode 并执行 Remote Run。

一键 Debug

  1. 右击工作负载 pig-auth
  2. 选择 Remote Debug。
  3. Nocalhost 会自动进入 DevMode 并执行 Remote Debug。
  4. 在代码中打上断点,发起请求,进入 IDE Debug 模式。

持久化配置

在开发时,我们希望持久化的文件大多数都是 依赖包 日志,本篇文章中也是缓存了 Java 的依赖包。

rainbondvolumerwx 是 Rainbond 默认提供的存储类,填写以下配置后会在当前命名空间下自动创建 PVC,如下:

storageClass: rainbondvolumerwx     
persistentVolumeDirs:
  - path: /root/.m2/repository
    capacity: 10Gi

容器资源限制

限制开发容器的资源,限额能让服务器的资源利用最大化,可以通过以下开发配置修改:

resources:
  limits:
    memory: 4096Mi
    cpu: "2"
  requests:
    memory: 2048Mi
    cpu: "1"

端口转发

转发容器端口到本地,可以通过以下开发配置修改:

portForward:
  - 3999:3000   # 转发容器 3000 端口到本地 3999 端口

最后

当然 Nocalhost 可以同时调试多个微服务,同样的方式只需修改配置文件中的 Deployment Name 和 Containers Name 以及微服务的子模块。

Nocalhost 还有一些开发配置文中没讲到的,比如:开发环境变量、文件同步的两种模式 pattern gitignore 等等,并且 Nocalhost 支持多种语言,Java 只是其中一种,小伙伴们可以自行探索。

Nocalhost + Rainbond 让开发、部署更加高效、便捷。

About Rainbond

❝Rainbond 核心100%开源,使用简单,不需要懂容器和Kubernetes,支持管理多种Kubernetes集群,提供企业级应用的全生命周期管理。
🌟 Github:https://github.com/goodrain/rainbond
💻 官网:https://www.rainbond.com
🏠 微信群:关注 Rainbond 公众号加入技术交流群
🏡 钉钉群:请搜索钉钉群号 31096419

K8S中文社区微信公众号

评论 3

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #3

    Hello Guys, I just completed my divorce with my cheating husband of 10 years with two beautiful kids when i got a solid evidence of his unfaithfulness on extra marital affairs and his infidelity lifestyle, And the various applications he used to hide chats and lot of secret on his cell phone. Then, i decided to hire (Henry clark) an hacker and a PI just to be 100% sure because i don’t want to confront him or take any kinda step without proof, fact and figures because that could leads to defamation… It was with this great, honest, professional and trustworthy Man i got to know my husband is a professional cheater and has been using this app to hide most of his chats. This great hacker helped me broke to into his cell phone activities and wired everything he does on his cell phone directly to my phone and i was able to monitor and track him directly from my phone remotely without him knowing,
    Contact the Ethical hacker via email, Henryclarkethicalhacker@gmail.com you can also reach him on Whatsapp 18134211326..

    Steve Jenna2个月前 (09-19)回复
  2. #2

    Contact him for any type of hacking, he is a professional hacker that specializes in exposing cheating spouses, and every other hacking related issues. he is a cyber guru, he helps catch cheating spouses by hacking their communications like call, Facebook, text, emails, Skype, whats-app and many more. I have used this service before and he did a very good job, he gave me every proof I needed to know that my fiancee was cheating. You can contact him on his email to help you catch your cheating spouse, or for any other hacking related problems, like hacking websites, bank statement, grades and many more. he will definitely help you, he has helped a lot of people, contact him on, Henryclarkethicalhacker@gmail.com, and you can Text/Call &WhatsApp: +1 (262)-236-7526, and figure out your relationship status. I wish you the best.

    Lucy Janet3周前 (11-13)回复
  3. #1

    Tracking cellphones and getting an accurate report has been a bit worrisome, thanks to Jeffrey whose service helped me locate certain cellphones without breaking a sweat. His service made me know that the internet has become the most common method of cheating nowadays, either emotionally or physically. Taking a few extra steps in getting what would serve as proof for leaving a toxic relationship, to see who your spouse texts or chats with on social media isn’t a bad idea, I’d recommend you reach out to Jeffreyethicalhacker@gmail.com
    Text,call or whatsapp on: +1 (747)345-9036
    HJK

    dda liey5541周前 (11-23)回复