1
头图
Author of this article: Huang Xinxin-Core Developer of Nocalhost Project
Tencent Cloud CODING DevOps R&D engineer. Graduated from the School of Data Science and Computer, Sun Yat-sen University. He was responsible for Ping An Cloud Host and Container Cloud Platform of the National Supercomputing Center. He is familiar with virtual machines, containers, and K8s related technologies, focusing on the cloud native field.

Introduction

This article uses Nocalhost to seamlessly connect the local development machine to a remote Kubernetes cluster, and uses Goland locally to develop and debug 061c28db5270ac in the Apache APISIX ingress controller cluster. Nocalhost allows us to use the existing technology stack to smoothly develop and debug K8s applications APISIX ingress controller

This article includes:

  1. APISIX Ingress controller to the remote Kubernetes cluster in the IDE
  2. Use Nocalhost to develop and debug 061c28db52710f on a APISIX ingress controller

Environmental preparation

Deploy APISIX Ingress Controller

Follow the steps below to deploy APISIX Ingress Controller via Nocalhost in GoLand:

  1. Open the Nocalhost plugin in GoLand
  2. Select the namespace where APISIX Ingress Controller will be deployed
  3. Right-click on the selected namespace, select Deploy Application , and then select Helm Repo as the installation method
  4. In the dialog box Name input: apisix-ingress-controller , in Chart URL input: https://charts.apiseven.com

部署 APISIX ingress controller

After the deployment is complete, we test apisix-ingress-controller by enabling port forwarding in the IDE:

  1. apisix-ingress-controller in Workloads of Nocalhost plug-in, right click and select Port Forward
  2. Add port forwarding 8080:8080
  3. Visit http://127.0.0.1:8080/healthz and check the result

测试部署是否成功

Develop APISIX Ingress Controller

Step 1. Enter DevMode

  1. Right click on apisix-ingress-controller workload and select Start DevMode
  2. If you have cloned the source code locally, please select the source code directory. Or by entering apisix-ingress-controller source address of the warehouse https://github.com/apache/apisix-ingress-controller.git to make the source code to the local clone Nocalhost
  3. Wait for the operation to complete, Nocalhost will open the remote terminal in the IDE after entering DevMode

apisix-ingress-controller process by entering the following command in the remote terminal:

go run main.go ingress --config-path conf/config-default.yaml

apisix-ingress-controller started, http://127.0.0.1:8080/healthz and check the result:

进入开发模式

Step 2. Modify the code and check the result

Now let's modify the code and see the effect:

  1. Stop the apisix-ingress-controller process
  2. Search for healthz in Goland and find the router.go file. Change the status code of healthzResponse from ok to Hello Nocalhost
  3. Restart the process and check the results of the changes locally

You can see that we don't need to rebuild the image, and we can see the result of the change in a few seconds:

修改源码

Step 3. End the development mode

After the development is completed, we can end DevMode through the following steps:

  1. Right click apisix-ingress-controller
  2. Select and click End DevMode

Nocalhost will let apisix-ingress-controller end DevMode and reset apisix-ingress-controller to its original version. Enable port forwarding to see the result after ending DevMode:
结束开发

It should be noted that in DevMode mode, all code changes only take effect in the development container. After exiting DevMode, Nocalhost will reset the remote container to its original state (entering the previous version of DevMode). In this way, after exiting DevMode, the modifications made in DevMode will not affect the original environment.

Debug APISIX Ingress Controller

Debugging applications is a hassle, and debugging applications in a Kubernetes cluster is even more troublesome. Nocalhost can help us get the same experience when debugging programs in a Kubernetes cluster and debugging local programs directly in the IDE.

Step 1. Enable remote debugging

We can start remote debugging in the following ways:

  1. Right click apisix-ingress-controller and select Remote Debug
  2. Nocalhost will first let apisix-ingress-controller enter DevMode and run the debugging commands defined dev config

开启远程调试

Step 2. Set a breakpoint

We set a breakpoint on the healthz function. After setting the breakpoint, visit http://127.0.0.1:8080/healthz in the browser, the breakpoint will be triggered, and GoLand will jump to the foreground. Click the debugging related button to debug the program:

调试断点

Run APISIX Ingress Controller remotely

Nocalhost can not only be used for remote debugging of applications, but also allows us to quickly run the application under development in the Kubernetes cluster Remote Run
We can use the Remote Run function through the following steps:

  1. Right click apisix-ingress-controller and select Remote Run
  2. Nocalhost will first let apisix-ingress-controller enter DevMode , and run the run command defined dev config
    Every time the code is changed, Nocalhost will automatically trigger the run command to run the program:

Remote Run

Summarize

Through the above steps, we have learned how to use Nocalhost to develop and debug the APISX ingress controller in the Kubernetes cluster. With Nocalhost, we no longer need to wait for slow local development loop feedback, but get fast feedback through an efficient cloud-native development method.

Quote

One-click to open the cloud native development environment

CODING DevOps.png


CODING
3.3k 声望4k 粉丝

CODING 是腾讯云旗下一站式 DevOps 研发管理平台,向广大开发者及企业研发团队提供代码托管、项目协同、测试管理、持续集成、制品库、持续部署、云原生应用管理 Orbit、团队知识库等系列工具产品,支持 SaaS 模式...