Using the Kong Ingress Controller Addon

Kong Ingress Controller (KIC) running on your minikube server.

  1. Start minikube

    1. minikube start

    It will take a few minutes to get all resources provisioned.

    1. kubectl get nodes

Deploy the Kong Ingress Controller

Enable Kong Ingress Controller via minikube command.

  1. $ minikube addons enable kong
  2. 🌟 The 'kong' addon is enabled

Note: this process could take up to five minutes the first time.

Setup environment variables

Next, we will set up an environment variable with the IP address at which Kong is accessible. We can use it to send requests into the Kubernetes cluster.

  1. $ export PROXY_IP=$(minikube service -n kong kong-proxy --url | head -1)
  2. $ echo $PROXY_IP
  3. http://192.168.99.100:32728

Alternatively, you can use minikube tunnel command.

  1. # open another terminal window and run
  2. minikube tunnel
  3. # you may need to enter an admin password because minikube need to use ports 80 and 443

Let’s test if KIC is up and running.

  1. $ curl -v localhost
  2. * Trying 127.0.0.1:80...
  3. * Connected to localhost (127.0.0.1) port 80 (#0)
  4. > GET / HTTP/1.1
  5. > Host: localhost
  6. > User-Agent: curl/7.86.0
  7. > Accept: */*
  8. >
  9. * Mark bundle as not supporting multiuse
  10. < HTTP/1.1 404 Not Found
  11. < Date: Wed, 03 May 2023 01:34:31 GMT
  12. < Content-Type: application/json; charset=utf-8
  13. < Connection: keep-alive
  14. < Content-Length: 48
  15. < X-Kong-Response-Latency: 0
  16. < Server: kong/3.2.2
  17. <
  18. * Connection #0 to host localhost left intact
  19. {"message":"no Route matched with those values"}%

Creating Ingress object

To proxy requests, you need an upstream application to proxy to. Deploying this echo server provides a simple application that returns information about the Pod it’s running in:

  1. echo "
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. labels:
  6. app: echo
  7. name: echo
  8. spec:
  9. ports:
  10. - port: 1025
  11. name: tcp
  12. protocol: TCP
  13. targetPort: 1025
  14. - port: 1026
  15. name: udp
  16. protocol: TCP
  17. targetPort: 1026
  18. - port: 1027
  19. name: http
  20. protocol: TCP
  21. targetPort: 1027
  22. selector:
  23. app: echo
  24. ---
  25. apiVersion: apps/v1
  26. kind: Deployment
  27. metadata:
  28. labels:
  29. app: echo
  30. name: echo
  31. spec:
  32. replicas: 1
  33. selector:
  34. matchLabels:
  35. app: echo
  36. strategy: {}
  37. template:
  38. metadata:
  39. creationTimestamp: null
  40. labels:
  41. app: echo
  42. spec:
  43. containers:
  44. - image: kong/go-echo:latest
  45. name: echo
  46. ports:
  47. - containerPort: 1027
  48. env:
  49. - name: NODE_NAME
  50. valueFrom:
  51. fieldRef:
  52. fieldPath: spec.nodeName
  53. - name: POD_NAME
  54. valueFrom:
  55. fieldRef:
  56. fieldPath: metadata.name
  57. - name: POD_NAMESPACE
  58. valueFrom:
  59. fieldRef:
  60. fieldPath: metadata.namespace
  61. - name: POD_IP
  62. valueFrom:
  63. fieldRef:
  64. fieldPath: status.podIP
  65. resources: {}
  66. " | kubectl apply -f -

Next, we will create routing configuration to proxy /echo requests to the echo server:

  1. echo "
  2. apiVersion: networking.k8s.io/v1
  3. kind: Ingress
  4. metadata:
  5. name: echo
  6. annotations:
  7. konghq.com/strip-path: 'true'
  8. spec:
  9. ingressClassName: kong
  10. rules:
  11. - host: kong.example
  12. http:
  13. paths:
  14. - path: /echo
  15. pathType: ImplementationSpecific
  16. backend:
  17. service:
  18. name: echo
  19. port:
  20. number: 1027
  21. " | kubectl apply -f -

Let’s test our ingress object.

  1. $ curl -i localhost/echo -H "Host: kong.example"
  2. HTTP/1.1 200 OK
  3. Content-Type: text/plain; charset=utf-8
  4. Content-Length: 133
  5. Connection: keep-alive
  6. Date: Wed, 03 May 2023 01:59:25 GMT
  7. X-Kong-Upstream-Latency: 1
  8. X-Kong-Proxy-Latency: 1
  9. Via: kong/3.2.2
  10. Welcome, you are connected to node minikube.
  11. Running on Pod echo-f4fdf987c-qdv7s.
  12. In namespace default.
  13. With IP address 10.244.0.6.

Next

Note: Read more about KIC and different use cases in official documentation.

Last modified July 7, 2023: Add addon readmes to website (cf976f6dd)