You are browsing documentation for an older version. See the latest documentation here.
Expose an external application
Learn to expose a service located outside the Kubernetes cluster using an Ingress.
Before you begin ensure that you have Installed Kong Ingress Controller in your Kubernetes cluster and are able to connect to Kong.
Before you begin ensure that you have Installed Kong Ingress Controller in your Kubernetes cluster and are able to connect to Kong.
Prerequisites
Install Kong
You can install Kong in your Kubernetes cluster using Helm.
-
Add the Kong Helm charts:
helm repo add kong https://charts.konghq.com helm repo update
-
Install Kong Ingress Controller and Kong Gateway with Helm:
helm install kong kong/ingress -n kong --create-namespace
Test connectivity to Kong
Kubernetes exposes the proxy through a Kubernetes service. Run the following commands to store the load balancer IP address in a variable named PROXY_IP
:
-
Populate
$PROXY_IP
for future commands:export PROXY_IP=$(kubectl get svc --namespace kong kong-gateway-proxy -o jsonpath='{.status.loadBalancer.ingress[0].ip}') echo $PROXY_IP
-
Ensure that you can call the proxy IP:
curl -i $PROXY_IP
The results should look like this:
HTTP/1.1 404 Not Found Content-Type: application/json; charset=utf-8 Connection: keep-alive Content-Length: 48 X-Kong-Response-Latency: 0 Server: kong/3.0.0 {"message":"no Route matched with those values"}
Create a Kubernetes Service
-
Deploy a Kubernetes Service type=ExternalName using the hostname of the application you want to expose.
echo " kind: Service apiVersion: v1 metadata: name: proxy-to-httpbin spec: ports: - protocol: TCP port: 80 type: ExternalName externalName: httpbin.konghq.com " | kubectl apply -f -
The results should look like this:
service/proxy-to-httpbin created
-
Create an Ingress to expose the service at the path
/httpbin
The results should look like this:
Test the Service
curl -i -H 'Host:kong.example' $PROXY_IP/httpbin/anything
The results should look like this:
HTTP/1.1 200 OK
Date: Thu, 15 Dec 2022 21:31:47 GMT
Content-Type: application/json
Content-Length: 341
Connection: keep-alive
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
X-Kong-Upstream-Latency: 2
X-Kong-Proxy-Latency: 1
Via: kong/3.1.1
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Host": "httpbin.konghq.com",
"User-Agent": "curl/7.86.0",
"X-Amzn-Trace-Id": "Root=1-639b9243-7cdb670008b8189a5948d619"
},
"json": null,
"method": "GET",
"origin": "136.25.153.9",
"url": "https://httpbin.konghq.com/anything"
}