|
8 | 8 | description: |- |
9 | 9 | This guide covers setting up [ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/) on a kind cluster. |
10 | 10 | --- |
11 | | -## Setting Up An Ingress Controller |
| 11 | +## Compatibility: |
| 12 | +This guide applies to [cloud-provider-kind](https://github.com/kubernetes-sigs/cloud-provider-kind) v0.9.0+. For older versions, refer to historical docs. |
12 | 13 |
|
13 | | -Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. |
| 14 | +## Setting Up Ingress |
14 | 15 |
|
15 | | -1. [Create a cluster](#create-cluster): There are two primary methods to direct external traffic to Services inside the cluster: |
16 | | - 1. using a [LoadBalancer]. |
17 | | - 2. leverage KIND's `extraPortMapping` config option when creating a cluster to forward ports from the host. |
| 16 | +Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. |
18 | 17 |
|
19 | | -2. Deploy an Ingress controller, we document [Ingress NGINX](#ingress-nginx) here but other ingresses may work including [Contour](https://projectcontour.io/docs/main/guides/kind/) and Kong, you should follow their docs if you choose to use them. |
| 18 | +Since cloud-provider-kind v0.9.0, it natively supports Ingress. No third-party ingress controllers are required by default. |
20 | 19 |
|
21 | | -> **NOTE**: You may also want to consider using [Gateway API](https://gateway-api.sigs.k8s.io/) instead of Ingress. |
22 | | -> Gateway API has an [Ingress migration guide](https://gateway-api.sigs.k8s.io/guides/migrating-from-ingress/). |
| 20 | +For third-party ingress solutions (e.g., Ingress NGINX, Contour), please follow their official documentation. |
23 | 21 |
|
24 | | -### Create Cluster |
| 22 | +> **NOTE**: Gateway API is also natively supported (along with Ingress). See the official [Ingress migration guide](https://gateway-api.sigs.k8s.io/guides/migrating-from-ingress/) for details. |
25 | 23 |
|
26 | | -#### Option 1: LoadBalancer |
| 24 | +## Create Cluster |
27 | 25 |
|
28 | | -Create a kind cluster and run [Cloud Provider KIND] |
29 | | -to enable the loadbalancer controller which ingress-nginx will use through the loadbalancer API. |
| 26 | +Create a kind cluster and run [Cloud Provider KIND] that automatically enables LoadBalancer support for Ingress. Create a cluster as follows. |
30 | 27 |
|
31 | 28 | {{< codeFromInline lang="bash" >}} |
32 | 29 | kind create cluster |
33 | 30 | {{< /codeFromInline >}} |
34 | 31 |
|
35 | | -#### Option 2: extraPortMapping |
36 | | - |
37 | | -Create a single node kind cluster with `extraPortMappings` to allow the local host to make requests to the Ingress controller over ports 80/443. |
38 | | - |
39 | | -{{< codeFromInline lang="bash" >}} |
40 | | -cat <<EOF | kind create cluster --config=- |
41 | | -kind: Cluster |
42 | | -apiVersion: kind.x-k8s.io/v1alpha4 |
43 | | -nodes: |
44 | | -- role: control-plane |
45 | | - extraPortMappings: |
46 | | - - containerPort: 80 |
47 | | - hostPort: 80 |
48 | | - protocol: TCP |
49 | | - - containerPort: 443 |
50 | | - hostPort: 443 |
51 | | - protocol: TCP |
52 | | -EOF |
53 | | -{{< /codeFromInline >}} |
54 | | - |
55 | | -If you want to run with multiple nodes you must ensure that your ingress-controller is deployed on the same node where you have configured the PortMapping, in this example you can use a [nodeSelector](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/) to specify the control-plane node name. |
56 | | - |
57 | | -{{< codeFromInline lang="yaml" >}} |
58 | | -nodeSelector: |
59 | | - kubernetes.io/hostname: "kind-control-plane" |
60 | | -{{< /codeFromInline >}} |
61 | | - |
62 | | -### Ingress NGINX |
63 | | - |
64 | | -{{< codeFromInline lang="bash" >}} |
65 | | -kubectl apply -f {{< absURL "examples/ingress/deploy-ingress-nginx.yaml" >}} |
66 | | -{{< /codeFromInline >}} |
67 | | - |
68 | | -Now the Ingress is all setup. Wait until is ready to process requests running: |
69 | | - |
70 | | -{{< codeFromInline lang="bash" >}} |
71 | | -kubectl wait --namespace ingress-nginx \ |
72 | | - --for=condition=ready pod \ |
73 | | - --selector=app.kubernetes.io/component=controller \ |
74 | | - --timeout=90s |
75 | | -{{< /codeFromInline >}} |
76 | | - |
77 | | -Refer [Using Ingress](#using-ingress) for a basic example usage. |
78 | | - |
79 | 32 | ## Using Ingress |
80 | 33 |
|
81 | | -The following example creates simple http-echo services |
82 | | -and an Ingress object to route to these services. |
| 34 | +The following example creates simple http-echo services and an Ingress object to route to these services. |
83 | 35 |
|
84 | 36 | ```yaml |
85 | 37 | {{% readFile "static/examples/ingress/usage.yaml" %}} |
86 | 38 | ``` |
87 | 39 |
|
88 | | -Apply the contents |
| 40 | +Apply the configuration: |
89 | 41 |
|
90 | 42 | {{< codeFromInline lang="bash" >}} |
91 | 43 | kubectl apply -f {{< absURL "examples/ingress/usage.yaml" >}} |
92 | 44 | {{< /codeFromInline >}} |
93 | 45 |
|
94 | | -Now verify that the ingress works |
| 46 | +### Verify Ingress Works |
95 | 47 |
|
96 | | -#### Option 1: LoadBalancer |
97 | | - |
98 | | -Check the External IP assigned to the Ingress controller by the LoadBalancer |
| 48 | +Check the External IP assigned to the Ingress by the built-in LoadBalancer. |
99 | 49 |
|
100 | 50 | {{< codeFromInline lang="bash" >}} |
101 | | -kubectl -n ingress-nginx get services |
102 | | -NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
103 | | -ingress-nginx-controller LoadBalancer 10.96.33.233 192.168.8.5 80:31753/TCP,443:30288/TCP 27d |
104 | | -ingress-nginx-controller-admission ClusterIP 10.96.80.178 <none> 443/TCP 27d |
| 51 | +kubectl get ingress |
| 52 | +NAME CLASS HOSTS ADDRESS PORTS AGE |
| 53 | +example-ingress <none> example.com 172.18.0.5 80 10m |
105 | 54 | {{< /codeFromInline >}} |
106 | 55 |
|
107 | 56 | {{< codeFromInline lang="bash" >}} |
| 57 | +# get the Ingress IP |
108 | 58 |
|
109 | | -# get the loadalancer IP |
110 | | - |
111 | | -LOADBALANCER_IP=$(kubectl get services \ |
112 | | - --namespace ingress-nginx \ |
113 | | - ingress-nginx-controller \ |
114 | | - --output jsonpath='{.status.loadBalancer.ingress[0].ip}') |
115 | | - |
116 | | -# should output "foo-app" |
117 | | - |
118 | | -curl ${LOADBALANCER_IP}/foo |
119 | | - |
120 | | -# should output "bar-app" |
121 | | - |
122 | | -curl ${LOADBALANCER_IP}/bar |
123 | | -{{< /codeFromInline >}} |
124 | | - |
125 | | -#### Option 2: extraPortMapping |
126 | | - |
127 | | -The Ingress controller ports will be exposed in your `localhost` address |
128 | | - |
129 | | -{{< codeFromInline lang="bash" >}} |
| 59 | +INGRESS_IP=$(kubectl get ingress example-ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}') |
130 | 60 |
|
131 | 61 | # should output "foo-app" |
132 | 62 |
|
133 | | -curl localhost/foo |
| 63 | +curl ${INGRESS_IP}/foo |
134 | 64 |
|
135 | 65 | # should output "bar-app" |
136 | | - |
137 | | -curl localhost/bar |
| 66 | +curl ${INGRESS_IP}/bar |
138 | 67 | {{< /codeFromInline >}} |
139 | 68 |
|
140 | 69 | [LoadBalancer]: /docs/user/loadbalancer/ |
|
0 commit comments