|
| 1 | +--- |
| 2 | +title: "Using Kong Ingress Controller Addon" |
| 3 | +linkTitle: "Kong Ingress" |
| 4 | +weight: 1 |
| 5 | +date: 2022-01-25 |
| 6 | +--- |
| 7 | +Kong Ingress Controller (KIC) running on your minikube server. |
| 8 | + |
| 9 | +1. Start `minikube` |
| 10 | + |
| 11 | + ```bash |
| 12 | + minikube start |
| 13 | + ``` |
| 14 | + |
| 15 | + It will take a few minutes to get all resources provisioned. |
| 16 | + |
| 17 | + ```bash |
| 18 | + kubectl get nodes |
| 19 | + ``` |
| 20 | + |
| 21 | +## Deploy the Kong Ingress Controller |
| 22 | + |
| 23 | +Enable Kong Ingress Controller via `minikube` command. |
| 24 | + |
| 25 | +```bash |
| 26 | +$ minikube addon enable kong |
| 27 | +``` |
| 28 | + |
| 29 | +> Note: this process could take up to five minutes the first time. |
| 30 | +
|
| 31 | +## Setup environment variables |
| 32 | + |
| 33 | +Next, we will set up an environment variable with the IP address at which |
| 34 | +Kong is accessible. |
| 35 | +We can use it to send requests into the Kubernetes cluster. |
| 36 | + |
| 37 | +```bash |
| 38 | +$ export PROXY_IP=$(minikube service -n kong kong-proxy --url | head -1) |
| 39 | +$ echo $PROXY_IP |
| 40 | +http://192.168.99.100:32728 |
| 41 | +``` |
| 42 | + |
| 43 | +Alternatively, you can use `minikube tunnel` command. |
| 44 | + |
| 45 | +```bash |
| 46 | + |
| 47 | +# open another terminal window and run |
| 48 | +minikube tunnel |
| 49 | + |
| 50 | +# you may need to enter an admin password because minikube need to use ports 80 and 443 |
| 51 | +``` |
| 52 | + |
| 53 | +Let's test if KIC is up and running. |
| 54 | + |
| 55 | +```bash |
| 56 | +$ curl -v localhost |
| 57 | + |
| 58 | +* Trying 127.0.0.1:80... |
| 59 | +* Connected to localhost (127.0.0.1) port 80 (#0) |
| 60 | +> GET / HTTP/1.1 |
| 61 | +> Host: localhost |
| 62 | +> User-Agent: curl/7.77.0 |
| 63 | +> Accept: */* |
| 64 | +> |
| 65 | +* Mark bundle as not supporting multiuse |
| 66 | +< HTTP/1.1 404 Not Found |
| 67 | +< Date: Tue, 25 Jan 2022 22:35:27 GMT |
| 68 | +< Content-Type: application/json; charset=utf-8 |
| 69 | +< Connection: keep-alive |
| 70 | +< Content-Length: 48 |
| 71 | +< X-Kong-Response-Latency: 0 |
| 72 | +< Server: kong/2.7.0 |
| 73 | +< |
| 74 | +* Connection #0 to host localhost left intact |
| 75 | +{"message":"no Route matched with those values"}% |
| 76 | +```` |
| 77 | + |
| 78 | +## Creating Ingress object |
| 79 | + |
| 80 | +Let's create a service. |
| 81 | +As an example, we use `tyoe-ExternalName` to point to https://httpbin.org |
| 82 | +
|
| 83 | +```bash |
| 84 | +echo " |
| 85 | +kind: Service |
| 86 | +apiVersion: v1 |
| 87 | +metadata: |
| 88 | + name: proxy-to-httpbin |
| 89 | +spec: |
| 90 | + ports: |
| 91 | + - protocol: TCP |
| 92 | + port: 80 |
| 93 | + type: ExternalName |
| 94 | + externalName: httpbin.org |
| 95 | +" | kubectl create -f - |
| 96 | +``` |
| 97 | +
|
| 98 | +Next, we will create the ingress object points to httpbin service. |
| 99 | +
|
| 100 | +```bash |
| 101 | +echo ' |
| 102 | +apiVersion: networking.k8s.io/v1 |
| 103 | +kind: Ingress |
| 104 | +metadata: |
| 105 | + name: proxy-from-k8s-to-httpbin |
| 106 | + annotations: |
| 107 | + konghq.com/strip-path: "true" |
| 108 | +spec: |
| 109 | + ingressClassName: kong |
| 110 | + rules: |
| 111 | + - http: |
| 112 | + paths: |
| 113 | + - path: /foo |
| 114 | + pathType: ImplementationSpecific |
| 115 | + backend: |
| 116 | + service: |
| 117 | + name: proxy-to-httpbin |
| 118 | + port: |
| 119 | + number: 80 |
| 120 | +' | kubectl create -f - |
| 121 | +``` |
| 122 | +
|
| 123 | +Let's test our ingress object. |
| 124 | + |
| 125 | +```bash |
| 126 | +$ curl -i localhost/foo -H "Host: httpbin.org" |
| 127 | +
|
| 128 | +
|
| 129 | +HTTP/1.1 200 OK |
| 130 | +Content-Type: text/plain; charset=utf-8 |
| 131 | +Content-Length: 4 |
| 132 | +Connection: keep-alive |
| 133 | +X-App-Name: |
| 134 | +X-App-Version: 0.2.4 |
| 135 | +Date: Tue, 25 Jan 2022 22:44:57 GMT |
| 136 | +X-Kong-Upstream-Latency: 1 |
| 137 | +X-Kong-Proxy-Latency: 1 |
| 138 | +Via: kong/2.7.0 |
| 139 | +
|
| 140 | +foo |
| 141 | +``` |
| 142 | + |
| 143 | +## Next |
| 144 | + |
| 145 | +**Note:** Read more about KIC and different use cases in official |
| 146 | +[documentation](https://docs.konghq.com/kubernetes-ingress-controller/2.1.x/guides/overview/). |
0 commit comments