Docs
Ingress ControllerManage traffic and APIsTraffic ManagementDetect Upstream Protocol with appProtocol

Detect Upstream Protocol with appProtocol

Use APISIX or API7 Ingress Controller to automatically configure upstream protocols based on a Service port's appProtocol value.

Applies to:API7 Ingress Controller (drives API7 Gateway)APISIX Ingress Controller (drives Apache APISIX)

Goal

Configure the Ingress Controller to detect a backend Service's expected upstream protocol from the appProtocol field on the Service port.

Before you begin

  • Complete Set Up Ingress Controller and Gateway.
  • You have kubectl configured against the cluster used in the setup guide.
  • You have jq installed to view the Admin API response.
  • The examples use APISIX in standalone mode with the Admin API on port 9180. Replace APISIX_ADMIN_KEY with your Admin API key.

Set the variables this guide uses:

export GATEWAY_ADMIN_SERVICE="apisix-admin"
export ADMIN_API_PORT="9180"
export ADMIN_API_FORWARD_PORT="9180"
export APISIX_ADMIN_URL="http://127.0.0.1:${ADMIN_API_FORWARD_PORT}"
export APISIX_ADMIN_KEY="YOUR_ADMIN_KEY"   # replace with your Admin API key

Steps

Step 1: Create the example Service with appProtocol

Create a manifest for the httpbin Service that defines two ports with different appProtocol values:

httpbin-service.yaml
apiVersion: v1
kind: Service
metadata:
  namespace: aic
  name: httpbin
spec:
  selector:
    app: httpbin
  ports:
    - name: http
      port: 80
      targetPort: 80
      appProtocol: http
    - name: https
      port: 443
      targetPort: 443
      appProtocol: https

Apply the manifest:

kubectl apply -f httpbin-service.yaml

Step 2: Create a route that references the https port

Create a route that points to the Service port 443. The Ingress Controller reads appProtocol: https from that port and sets the upstream scheme to https automatically.

httpbin-https.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  namespace: aic
  name: httpbin-route
spec:
  parentRefs:
  - name: apisix
  rules:
  - matches:
    - path:
        type: Exact
        value: /anything
    backendRefs:
    - name: httpbin
      port: 443

Apply the manifest:

kubectl apply -f httpbin-https.yaml

Validate

Forward the APISIX Admin API port to your local machine:

kubectl port-forward "service/${GATEWAY_ADMIN_SERVICE}" "${ADMIN_API_FORWARD_PORT}:${ADMIN_API_PORT}" -n aic &

Query the Admin API for the gateway configuration and inspect the upstream scheme:

curl "${APISIX_ADMIN_URL}/apisix/admin/configs" -H "X-API-KEY: ${APISIX_ADMIN_KEY}" | jq

In the upstreams section of the response, the scheme for the managed upstream should be https:

{
  "scheme": "https",
  "labels": {
    "managed-by": "apisix-ingress-controller"
  },
  "name": "aic_httpbin-route_0",
  "id": "..."
}

If you are using API7 Enterprise, the API7 Dashboard should also show the upstream scheme set to https.

Roll back / Clean up

Delete the manifests created in this guide:

kubectl delete -f httpbin-https.yaml
kubectl delete -f httpbin-service.yaml

Stop the local port-forward process if it is still running:

kill %1 2>/dev/null || true

Troubleshoot

SymptomCauseFix
The upstream scheme is still http.The route references the wrong Service port, or appProtocol is not set on that port.Confirm the backendRefs or backends entry selects port 443, and that the Service declares appProtocol: https for that port.
curl returns 401 Unauthorized from the Admin API.APISIX_ADMIN_KEY is incorrect or missing.Verify the key in the APISIX deployment and re-export APISIX_ADMIN_KEY.
kubectl port-forward fails to bind.Another process is using port 9180 locally, or the Admin API Service does not exist.Set ADMIN_API_FORWARD_PORT to a free port and use the same value in APISIX_ADMIN_URL.