Files
kind/site/content/docs/user/ingress.md
Manuel Alejandro de Brito Fontes 31e2eecc94 Update ingress-nginx version
2020-02-24 10:01:29 -03:00

4.1 KiB

title, menu
title menu
Ingress
main
parent identifier weight
user user-ingress 3

Ingress

This guide covers setting up ingress on a kind cluster.

Setting Up An Ingress Controller

We can leverage KIND's extraPortMapping config option when creating a cluster to forward ports from the host to an ingress controller running on a node.

We can also setup a custom node label by using node-labels in the kubeadm InitConfiguration, to be used by the ingress controller nodeSelector.

  1. Create a cluster
  2. Deploy an Ingress controller, the following ingress controllers are known to work:

Create Cluster

Create a kind cluster with extraPortMappings and node-labels.

  • extraPortMappings allow the local host to make requests to the Ingress controller over ports 80/443
  • node-labels only allow the ingress controller to run on a specific node(s) matching the label selector

{{< codeFromInline lang="bash" >}} cat <<EOF | kind create cluster --config=- kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes:

  • role: control-plane kubeadmConfigPatches:
    • | kind: InitConfiguration nodeRegistration: kubeletExtraArgs: node-labels: "ingress-ready=true" authorization-mode: "AlwaysAllow" extraPortMappings:
    • containerPort: 80 hostPort: 80 protocol: TCP
    • containerPort: 443 hostPort: 443 protocol: TCP EOF {{< /codeFromInline >}}

Contour

Deploy Contour components.

{{< codeFromInline lang="bash" >}} kubectl apply -f https://projectcontour.io/quickstart/contour.yaml {{< /codeFromInline >}}

Apply kind specific patches to forward the hostPorts to the ingress controller, set taint tolerations and schedule it to the custom labelled node.

{{% readFile "static/examples/ingress/contour/patch.json" %}}

Apply it by running:

{{< codeFromInline lang="bash" >}} kubectl patch daemonsets -n projectcontour envoy -p '{{< minify file="static/examples/ingress/contour/patch.json" >}}' {{< /codeFromInline >}}

Now the Contour is all setup to be used. Refer to Using Ingress for a basic example usage.

Additional information about Contour can be found at: projectcontour.io

Ingress NGINX

Apply the mandatory ingress-nginx components

{{< codeFromInline lang="bash" >}} kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/mandatory.yaml {{< /codeFromInline >}}

and expose the nginx service using NodePort.

{{< codeFromInline lang="bash" >}} kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/provider/baremetal/service-nodeport.yaml {{< /codeFromInline >}}

Apply kind specific patches to forward the hostPorts to the ingress controller, set taint tolerations and schedule it to the custom labelled node.

{{% readFile "static/examples/ingress/nginx/patch.json" %}}

Apply it by running:

{{< codeFromInline lang="bash" >}} kubectl patch deployments -n ingress-nginx nginx-ingress-controller -p '{{< minify file="static/examples/ingress/nginx/patch.json" >}}' {{< /codeFromInline >}}

Now the Ingress is all setup to be used. Refer Using Ingress for a basic example usage.

Using Ingress

The following example creates simple http-echo services and an Ingress object to route to these services.

{{% readFile "static/examples/ingress/usage.yaml" %}}

Apply the contents

{{< codeFromInline lang="bash" >}} kubectl apply -f {{< absURL "examples/ingress/usage.yaml" >}} {{< /codeFromInline >}}

Now verify that the ingress works

{{< codeFromInline lang="bash" >}}

should output "foo"

curl localhost/foo

should output "bar"

curl localhost/bar {{< /codeFromInline >}}