Skip to content

APISIX gateway

Overview

We run two APISIX clusters:

Cluster Location Version Route Type
DO (DigitalOcean) <DO_GITLAB_HAPROXY_PUBLIC_IP> Old (1.x) ApisixRoute
Local (NUC via Tailscale) <HOME_LAN_HOST_IP> 2.0.1 HTTPRoute (Gateway API)

Traffic flow for services hosted locally:

Client → DO APISIX → Tailscale (<NUC_A_TAILSCALE_IP>) → Local APISIX → Service Pod


Architecture

Internet
    │
    ▼
<DO_GITLAB_HAPROXY_PUBLIC_IP> (MetalLB VIP)
    │
    ▼
DO APISIX (3 pods across 3 nodes)
    │
    ├── Local services (direct)
    │
    └── Remote services → Tailscale (<NUC_A_TAILSCALE_IP>:80) → Local APISIX
                                                            │
                                                            └── Local K8s Services

Environments

DigitalOcean Cluster

  • Namespace: ingress-apisix
  • Admin service: apisix-admin.ingress-apisix.svc.cluster.local:9180
  • Admin key: stored in Helm values
  • LoadBalancer IP: <DO_GITLAB_HAPROXY_PUBLIC_IP> (MetalLB apisix-pool)
  • etcd: 3 replicas with Longhorn persistence

Local Cluster (NUC via Tailscale)

  • Namespace: apisix
  • Admin service: apisix-admin.apisix.svc.cluster.local:9180 (<APISIX_ADMIN_SERVICE_IP>)
  • Admin key: <APISIX_ADMIN_KEY> (stored in Helm values; see "Find APISIX admin key" below)
  • LoadBalancer IPs: <K3S_NODE_A_LAN_IP>, <K3S_NODE_B_LAN_IP>, <K3S_NODE_D_LAN_IP> (K3s ServiceLB)
  • Tailscale IP: <NUC_A_TAILSCALE_IP>

APISIX 2.0 Migration

Old Way (ApisixRoute — DO cluster)

apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: myapp-route
  namespace: staging
spec:
  http:
  - name: myapp
    match:
      hosts:
      - myapp.example.com
      paths:
      - "/*"
    backends:
    - serviceName: myapp
      servicePort: 80

New Way (HTTPRoute — Local cluster)

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: myapp-route
  namespace: staging
spec:
  parentRefs:
  - name: apisix-gateway
    namespace: apisix
  hostnames:
  - myapp.example.com
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /
    backendRefs:
    - name: myapp-service
      port: 80

Key differences: - /* becomes PathPrefix: / - No ApisixUpstream needed for local services - Must reference parentRefs pointing to the Gateway


Setting Up Gateway API

Prerequisites — Check CRDs

kubectl get crd | grep gateway

Required CRDs: - gatewayproxies.apisix.apache.org - gatewayclasses.gateway.networking.k8s.io - gateways.gateway.networking.k8s.io - httproutes.gateway.networking.k8s.io

Step 1 — GatewayProxy

apiVersion: apisix.apache.org/v1alpha1   # NOTE: v1alpha1 not v2
kind: GatewayProxy
metadata:
  name: apisix-proxy
  namespace: apisix
spec:
  provider:
    type: ControlPlane
    controlPlane:
      endpoints:
      - http://apisix-admin.apisix.svc.cluster.local:9180
      auth:
        type: AdminKey
        adminKey:
          value: <APISIX_ADMIN_KEY>

Step 2 — GatewayClass

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: apisix
spec:
  # IMPORTANT: must be apisix-ingress-controller not gateway-controller
  controllerName: apisix.apache.org/apisix-ingress-controller

Step 3 — Gateway

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: apisix-gateway
  namespace: apisix
spec:
  gatewayClassName: apisix
  infrastructure:
    parametersRef:
      group: apisix.apache.org
      kind: GatewayProxy
      name: apisix-proxy
  listeners:
  - name: http
    protocol: HTTP
    port: 80
    allowedRoutes:
      namespaces:
        from: All    # Allow routes from ALL namespaces

Common mistakes: - Using controllerName: apisix.apache.org/gateway-controller → wrong, causes Unknown status - Using allowedRoutes.namespaces.from: Same → blocks routes from other namespaces - GatewayProxy apiVersion: apisix.apache.org/v2 → wrong, must be v1alpha1

Verify Setup

kubectl get gatewayclass apisix          # Should show ACCEPTED: True
kubectl get gateway -n apisix            # Should show PROGRAMMED: True
kubectl get httproute -n <namespace>     # Should show your routes

Adding New Routes

Local Cluster (HTTPRoute only)

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: myapp-route
  namespace: my-namespace
spec:
  parentRefs:
  - name: apisix-gateway
    namespace: apisix
  hostnames:
  - myapp.castis.io
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /
    backendRefs:
    - name: my-service
      port: 80

DO Cluster routing to Local via Tailscale

Requires both ApisixRoute + ApisixUpstream:

apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
  name: myapp-upstream
  namespace: staging
spec:
  externalNodes:
  - type: Domain
    name: "<NUC_A_TAILSCALE_IP>"
    port: 80
    weight: 1
  scheme: http
  loadbalancer:
    type: roundrobin
---
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: myapp-route
  namespace: staging
spec:
  http:
  - name: myapp
    match:
      hosts:
      - myapp.castis.io
      paths:
      - "/*"
    upstreams:
    - name: myapp-upstream
      weight: 100
    plugins:
    - name: proxy-rewrite
      enable: true
      config:
        headers:
          set:
            X-Forwarded-Proto: "https"
            X-Forwarded-Host: "myapp.castis.io"

Multi-Node APISIX Setup

Scale APISIX across all nodes:

# Check current pods
kubectl get pods -n ingress-apisix -l app.kubernetes.io/name=apisix -o wide

# Scale to 3 replicas (one per node)
# NOTE: use replicaCount at top level, not apisix.replicaCount
helm upgrade apisix apisix/apisix -n ingress-apisix \
  --reuse-values \
  --no-hooks \
  --set replicaCount=3

Important: The Helm chart key is replicaCount (top-level), NOT apisix.replicaCount. Use --no-hooks to skip the broken etcd pre-upgrade job (uses wrong image).


MetalLB LoadBalancer

DO Cluster

Uses MetalLB with a single VIP from apisix-pool:

kubectl get ipaddresspool -n metallb-system    # Shows pool: <DO_GITLAB_HAPROXY_PUBLIC_IP>/32
kubectl get l2advertisement -n metallb-system  # Shows L2 advertisement config

Local Cluster

Uses K3s ServiceLB (Klipper) — assigns one IP per node: - <K3S_NODE_A_LAN_IP> → node 1 - <K3S_NODE_B_LAN_IP> → node 2 - <K3S_NODE_D_LAN_IP> → node 3

Make Gateway LoadBalancer (if reverted to NodePort)

kubectl patch svc apisix-gateway -n ingress-apisix -p '{"spec": {"type": "LoadBalancer"}}'

Enable SSL on Gateway Service

helm upgrade apisix apisix/apisix -n ingress-apisix \
  --reuse-values \
  --no-hooks \
  --set apisix.ssl.enabled=true \
  --set service.type=LoadBalancer

HAProxy Removal

HAProxy was running on the ubuntu-mashup-gitlab-haproxy node and intercepting port 80/443 before MetalLB. It was removed since MetalLB handles LoadBalancing natively.

systemctl stop haproxy
systemctl disable haproxy

Why it was a problem: HAProxy owned the node IP <DO_GITLAB_HAPROXY_PUBLIC_IP> on ports 80/443, so MetalLB couldn't route directly. Also HAProxy used pod IPs which change on every restart.


Tailscale Cross-Cluster Routing

Problem

Only the ubuntu-mashup-gitlab-haproxy node has Tailscale installed. When APISIX pods on other nodes try to reach <NUC_A_TAILSCALE_IP>, they fail — causing intermittent 504 errors.

Fix — Install Tailscale on all nodes

# On each node (worker-node-a, ubuntu-24-04-lts-control-plane)
curl -fsSL https://tailscale.com/install.sh | sh
tailscale up --login-server=https://headscale.castis.io --authkey=<key>

Generate Headscale Auth Key

# Get user ID first
kubectl exec -it -n headscale $(kubectl get pod -n headscale -o name | head -1) \
  -- headscale users list

# Generate key with user ID
kubectl exec -it -n headscale $(kubectl get pod -n headscale -o name | head -1) \
  -- headscale preauthkeys create --reusable --expiration 24h --user <user-id>

Admin API Access

APISIX Admin API requires IP allowlist. The ingress controller pod must be in the allowed range.

Check current allow list

kubectl exec -it -n ingress-apisix $(kubectl get pod -n ingress-apisix \
  -l app.kubernetes.io/name=apisix -o name | head -1) \
  -- cat /usr/local/apisix/conf/config.yaml | grep -A5 "allow_admin"

Fix via Helm (correct key)

helm upgrade apisix apisix/apisix -n ingress-apisix \
  --reuse-values \
  --no-hooks \
  --set apisix.admin.allow.ipList[0]="127.0.0.1/24" \
  --set apisix.admin.allow.ipList[1]="<POD_CIDR>"

Note: Pod CIDR is <POD_CIDR> for K3s clusters. Ingress controller pod must be in this range.


Troubleshooting

GatewayClass stuck at Unknown

kubectl describe gatewayclass apisix
- Check controllerName matches exactly: apisix.apache.org/apisix-ingress-controller - If wrong (immutable), delete and recreate:
kubectl delete gatewayclass apisix
kubectl apply -f gatewayclass.yaml

no GatewayProxy configs provided in logs

  • Check configmap has correct provider config:
    kubectl get configmap apisix-ingress-controller-ingress-config -n apisix -o yaml
    
  • Verify controller_name in configmap matches GatewayClass controllerName

Gateway shows gateway proxy not found

  • Add infrastructure.parametersRef to Gateway spec pointing to GatewayProxy
  • Set allowedRoutes.namespaces.from: All if HTTPRoute is in a different namespace

HTTPRoute has empty status

  • Gateway not accepting the route — check attachedRoutes count on Gateway
  • Verify parentRefs namespace and name match the Gateway

504 on services routed via Tailscale

  • Only one node has Tailscale → other APISIX pods can't reach <NUC_A_TAILSCALE_IP>
  • Fix: install Tailscale on all nodes

403 on Admin API

  • Ingress controller IP not in allow_admin list
  • Fix via Helm: --set apisix.admin.allow.ipList[1]="<POD_CIDR>"

HAProxy blocking port 443

ss -tlnp | grep 443    # Check if haproxy is listening
systemctl stop haproxy
systemctl disable haproxy

APISIX pods IPs change after restart

  • Don't use pod IPs in HAProxy — use ClusterIP or NodePort instead
  • After scaling, always check new IPs: kubectl get pods -n ingress-apisix -o wide

etcd pre-upgrade job failing

# Always use --no-hooks when upgrading
helm upgrade apisix apisix/apisix -n ingress-apisix --reuse-values --no-hooks ...

# Clean up failed jobs
kubectl delete pods -n ingress-apisix --field-selector=status.phase=Failed

Find APISIX admin key

# From Helm values
helm get values apisix -n <namespace>

# From running pod config
kubectl exec -it -n <namespace> $(kubectl get pod -n <namespace> \
  -l app.kubernetes.io/name=apisix -o name | head -1) \
  -- cat /usr/local/apisix/conf/config.yaml | grep -A5 admin_key