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
kubectlconfigured 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. ReplaceAPISIX_ADMIN_KEYwith 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 keySteps
Step 1: Create the example Service with appProtocol
Create a manifest for the httpbin Service that defines two ports with different appProtocol values:
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: httpsApply the manifest:
kubectl apply -f httpbin-service.yamlStep 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.
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: 443apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: aic
name: httpbin-route
spec:
ingressClassName: apisix
rules:
- http:
paths:
- path: /anything
pathType: Exact
backend:
service:
name: httpbin
port:
number: 443apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
namespace: aic
name: httpbin-route
spec:
ingressClassName: apisix
http:
- name: httpbin-route
match:
paths:
- /anything
backends:
- serviceName: httpbin
servicePort: 443Apply the manifest:
kubectl apply -f httpbin-https.yamlValidate
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}" | jqIn 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.yamlStop the local port-forward process if it is still running:
kill %1 2>/dev/null || trueTroubleshoot
| Symptom | Cause | Fix |
|---|---|---|
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. |