Enable Gateway Debug Mode
Learn how to enable gateway debug mode in a Kubernetes environment to troubleshoot and monitor the gateway’s runtime behavior effectively.
The gateway provides a debug mode to help developers better understand and troubleshoot the runtime behavior of the gateway. The debug mode configuration can be found in debug.yaml.
This guide will show you how to enable the gateway basic debug mode in a Kubernetes environment to inspect what plugins are enabled on the requested route. For information about the advanced debug mode, see Advanced Debug Mode.
Prerequisites
- Complete Set Up Ingress Controller and Gateway.
Enable Basic Debug Mode
Enabling the basic debug mode will allow you to inspect what plugins are enabled on the requested route in the Apisix-Plugins header.
By default, the debug mode is turned off. To enable the debug mode, you can set basic.enable to true in your debug.yaml file.
Create a ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: apisix-debug
namespace: aic
data:
debug.yaml: |
basic:
enable: true
#ENDApply the ConfigMap to your cluster:
kubectl apply -f apisix-debug-cm.yamlTo mount the ConfigMap, first export all values (including defaults):
helm get values -n aic apisix --all > values.yamlIn the values file, update the following section values as such:
extraVolumes:
- name: debug-config
configMap:
name: apisix-debug
extraVolumeMounts:
- name: debug-config
mountPath: /usr/local/apisix/conf/debug.yaml
subPath: debug.yamlUpgrade the release:
helm upgrade -n aic apisix apisix/apisix -f values.yamlThe debug.yaml configurations should end with #END, or else the gateway will not load the configurations. This means you can also use the #END flag as a breakpoint for the gateway to only load configurations up to the specified point.
Verify
To verify, create a route without any plugin:
apiVersion: v1
kind: Service
metadata:
namespace: aic
name: httpbin-external-domain
spec:
type: ExternalName
externalName: httpbin.org
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: aic
name: getting-started-anything
spec:
parentRefs:
- name: apisix
rules:
- matches:
- path:
type: Exact
value: /anything
backendRefs:
- name: httpbin-external-domain
port: 80apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
namespace: aic
name: httpbin-external-domain
spec:
externalNodes:
- type: Domain
name: httpbin.org
---
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
namespace: aic
name: getting-started-anything
spec:
ingressClassName: apisix
http:
- name: getting-started-anything
match:
paths:
- /anything
upstreams:
- name: httpbin-external-domainApply the configuration to your cluster:
kubectl apply -f httpbin-route.yamlSend a request to the route:
curl -i "http://127.0.0.1:9080/anything"You should receive an HTTP/1.1 200 OK response and observe the following headers:
Content-Type: application/json
Content-Length: 390
Connection: keep-alive
Apisix-Plugins: no plugin
...Update the route with a plugin:
apiVersion: v1
kind: Service
metadata:
namespace: aic
name: httpbin-external-domain
spec:
type: ExternalName
externalName: httpbin.org
---
apiVersion: apisix.apache.org/v1alpha1
kind: PluginConfig
metadata:
namespace: aic
name: limit-count-plugin-config
spec:
plugins:
- name: limit-count
config:
count: 5
time_window: 10
rejected_code: 429
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: aic
name: getting-started-anything
spec:
parentRefs:
- name: apisix
rules:
- matches:
- path:
type: Exact
value: /anything
filters:
- type: ExtensionRef
extensionRef:
group: apisix.apache.org
kind: PluginConfig
name: limit-count-plugin-config
backendRefs:
- name: httpbin-external-domain
port: 80Additionally, update your GatewayProxy manifest to enable prometheus as a global plugin:
To view the current GatewayProxy configuration before adding additional configuration, run:
kubectl get gatewayproxy apisix-config -o yamlapiVersion: apisix.apache.org/v1alpha1
kind: GatewayProxy
metadata:
namespace: aic
name: apisix-config
spec:
provider:
type: ControlPlane
controlPlane:
auth:
adminKey:
value: edd1c9f034335f136f87ad84b625c8f1
type: AdminKey
service:
name: apisix-admin
port: 9180
plugins:
- name: prometheus
enabled: trueApply the configuration to your cluster:
kubectl apply -f httpbin-route.yaml -f gateway-proxy.yamlUpdate the route with a plugin:
apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
namespace: aic
name: httpbin-external-domain
spec:
externalNodes:
- type: Domain
name: httpbin.org
---
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
namespace: aic
name: getting-started-anything
spec:
ingressClassName: apisix
http:
- name: getting-started-anything
match:
paths:
- /anything
upstreams:
- name: httpbin-external-domain
plugins:
- name: limit-count
enable: true
config:
count: 5
time_window: 10
rejected_code: 429Additionally, create a Kubernetes manifest file for a global Prometheus plugin:
apiVersion: apisix.apache.org/v2
kind: ApisixGlobalRule
metadata:
namespace: aic
name: global-prometheus
spec:
ingressClassName: apisix
plugins:
- name: prometheus
enable: trueApply the configuration to your cluster:
kubectl apply -f httpbin-route.yaml -f global-prometheus.yamlSend another request to the route:
curl -i "http://127.0.0.1:9080/anything"You should receive an HTTP/1.1 200 OK response with headers similar to the following:
Content-Type: application/json
Content-Length: 388
Connection: keep-alive
X-RateLimit-Limit: 5
X-RateLimit-Remaining: 4
X-RateLimit-Reset: 10
Apisix-Plugins: limit-count, prometheus
...If the plugin information cannot be included in a response header (e.g. L4 stream plugins), the debug information will be logged in the error log at the warn severity level.