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:
APISIX Ingress controller
to the remote Kubernetes cluster in the IDE- Use Nocalhost to develop and debug 061c28db52710f on a
APISIX ingress controller
Environmental preparation
- Prepare a usable Kubernetes cluster. Any Kubernetes cluster with namespace management permissions can be used
- Helm v3.0+ has been installed locally
- APISIX (APISIX Ingress controller dependency) has been installed in the cluster
- GoLand IDE 2020.03+
- Install Nocalhost JetBrains plug-in
- Install Go 1.13 and above
Deploy APISIX Ingress Controller
Follow the steps below to deploy APISIX Ingress Controller via Nocalhost in GoLand:
- Open the Nocalhost plugin in GoLand
- Select the namespace where APISIX Ingress Controller will be deployed
- Right-click on the selected namespace, select
Deploy Application
, and then selectHelm Repo
as the installation method - In the dialog box
Name
input:apisix-ingress-controller
, inChart URL
input:https://charts.apiseven.com
After the deployment is complete, we test apisix-ingress-controller
by enabling port forwarding in the IDE:
apisix-ingress-controller
in Workloads of Nocalhost plug-in, right click and selectPort Forward
- Add port forwarding
8080:8080
- Visit
http://127.0.0.1:8080/healthz
and check the result
Develop APISIX Ingress Controller
Step 1. Enter DevMode
- Right click on
apisix-ingress-controller
workload and selectStart DevMode
- If you have cloned the source code locally, please select the source code directory. Or by entering
apisix-ingress-controller
source address of the warehousehttps://github.com/apache/apisix-ingress-controller.git
to make the source code to the local clone Nocalhost - 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:
- Stop the
apisix-ingress-controller
process - Search for healthz in Goland and find the router.go file. Change the status code of healthzResponse from ok to Hello Nocalhost
- 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:
- Right click
apisix-ingress-controller
- 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:
- Right click
apisix-ingress-controller
and selectRemote Debug
- 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:
- Right click
apisix-ingress-controller
and selectRemote Run
- Nocalhost will first let
apisix-ingress-controller
enterDevMode
, and run the run command defineddev config
Every time the code is changed, Nocalhost will automatically trigger the run command to run the program:
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.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。