Environment to prepare

  • Prepare a usable Kubernetes cluster. You can use any Kubernetes cluster that has namespace management rights

  • The Helm V3.0 + is installed on the local PC

  • Apache APISIX has been installed in the cluster

  • GoLand IDE 2020.03+ (version 2021.2 is used in this article)

  • Install the Nocalhost JetBrains plugin

  • Install Go 1.13 or later

The Apache APISIX Ingress Controller is deployed

Install Apache APISIX Ingress Controller with Nocalhost in GoLand.

  1. Open the Nocalhost plugin in GoLand

  2. Select the namespace in which the APISIX Ingress Controller will be deployed

  3. Right-click on the selected namespace, select Deploy Application, and then Helm Repo as the install method

  4. In the following dialog:

  • Enter apisix-ingress-controller in Name

  • Input in the Chart URL: https://charts.apiseven.com

After deployment, we tested the Apisix-Ingress-Controller by enabling port forwarding within the IDE:

  1. Go to the Apisix-Ingress-Controller in the Workloads of the Nocalhost plugin, right click and select Port Forward

  2. Example Add port forwarding 8080:8080

  3. In local visit http://127.0.0.1:8080/healthz and check the results

The development of

Step 1: Enter development mode

  1. Right-click the Apisix-Ingress-Controller workload and select Start DevMode

  2. If you have cloned the source code locally, select your source directory. Otherwise, enter the warehouse address github.com/apache/apis… To have Nocalhost clone your source code locally

  3. After the operation completes, Nocalhost will open the remote terminal in the IDE after entering DevMode

Now start the apisix-Ingress-Controller process by entering the following command from the remote terminal:

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

Apisix ingress – controller starts, accessible via http://127.0.0.1:8080/healthz service, and check the results.

Step 2: Modify the code and check the results

Now let’s modify the code and see what happens:

  1. Stop the apisix-Ingress-Controller process

  2. Search for healthz in Goland and find the router.go file. Change the status code for healthzResponse from OK to Hello Nocalhost

  3. Restart the process and check the changes locally

Step 3: End development mode

Now close the development window and exit development mode:

  1. Right-click on Apisix-Ingress-Controller

  2. Select the End DevMode

Nocalhost will cause the apisix-Ingress-Controller to end DevMode and reset the apisix-Ingress-Controller to its original version. Enable port forwarding to see what happens when you leave development mode.

Note: When you modify code in development mode, all code changes take effect only in the development container.

After exiting DevMode, Nocalhost will reset the remote container to its original state (prior to DevMode). This way, after exiting DevMode, changes to the code will not change or affect the original environment.

debugging

Debugging an application is a hassle, and debugging an application in a Kubernetes cluster is even more troublesome. However, Nocalhost can help you get the same experience when debugging applications in the Kubernetes cluster as when debugging native applications directly in the IDE.

Step 1: Enable remote debugging

Remote debugging can be enabled in the following ways

  • Right-click Apisix-Ingress-Controller and select Remote Debug

  • Nocalhost will first make apisix-Ingress-Controller go to DevMode and run the debugging commands defined in dev config

Step 2: Set breakpoints

Set a breakpoint on the healthz function. Hover to the left of the line and click the red dot. Set breakpoints, visit http://127.0.0.1:8080/healthz in the browser, can trigger breakpoints, GoLand jump to the front desk. Click the debug button to debug the program.

Also, because we have dev.hotreload enabled, Nocalhost automatically rerunks the debug command every time the code changes. This makes it much easier to change and debug code frequently.

Remote operation

Nocalhost not only enables remote debugging, but also provides an easier way to run services in a Kubernetes cluster and hot load.

You can use the Remote Run feature by doing the following:

  • Right-click Apisix-Ingress-Controller and select Remote Run

  • Nocalhost will first make apisix-Ingress-Controller go to DevMode and run the run command defined in dev config

After each code change, Nocalhost automatically triggers a command to run the program.

conclusion

In this article, we have shown you how to use Nocalhost to develop and debug Apache APISIX Ingress Controller in Kubernetes cluster. With Nocalhost’s capabilities, we no longer have to wait for a slow on-site development process, but can deploy and iterate quickly with immediate feedback and an efficient cloud-on-site development environment.

About the author

Huang Xinxin – Core developer of Nocalhost Project. Tencent Cloud CODING DevOps R&D engineer. Responsible for ping An Cloud host and national Supercomputer Center container cloud platform and other related businesses, familiar with virtual machine, container, K8s related technology, focus on cloud native field.