Last active
December 8, 2023 15:45
-
-
Save atomatt/5c30f5e4e61a02e5b1b9a8eb4c6702fa to your computer and use it in GitHub Desktop.
kind cluster with ingress bound to 127.0.0.1 (or your preferred address)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -eu | |
| # Use INGRESS_LISTEN_ADDRESS to override the bind address, e.g. if you need to | |
| # put ingress on a different network because something else has 127.0.0.1 | |
| # | |
| # $ sudo ip addr add 10.10.10.10/32 dev lo | |
| # $ INGRESS_LISTEN_ADDRESS=10.10.10.10 kind-create-cluster-localhost-ingress.sh | |
| ingress_listen_address="${INGRESS_LISTEN_ADDRESS:-127.0.0.1}" | |
| kind create cluster --config - <<EOF | |
| kind: Cluster | |
| apiVersion: kind.x-k8s.io/v1alpha4 | |
| nodes: | |
| - role: control-plane | |
| kubeadmConfigPatches: | |
| - | | |
| kind: InitConfiguration | |
| nodeRegistration: | |
| kubeletExtraArgs: | |
| node-labels: "ingress-ready=true" | |
| extraPortMappings: | |
| - listenAddress: ${ingress_listen_address} | |
| protocol: TCP | |
| containerPort: 80 | |
| hostPort: 80 | |
| - listenAddress: ${ingress_listen_address} | |
| protocol: TCP | |
| containerPort: 443 | |
| hostPort: 443 | |
| EOF | |
| echo | |
| echo 'Installing "ingress-nginx" ...' | |
| kubectl apply \ | |
| -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml | |
| echo | |
| echo 'Waiting until "ingress-nginx" controller is ready ...' | |
| while [[ "$(kubectl --namespace ingress-nginx get pod --selector=app.kubernetes.io/component=controller -o name)" == "" ]]; do | |
| sleep 1; | |
| done | |
| kubectl wait \ | |
| --namespace ingress-nginx \ | |
| --for=condition=ready pod \ | |
| --selector=app.kubernetes.io/component=controller \ | |
| --timeout=90s |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Once you have the cluster running, your Ingress rule's
hostcan be, e.g. "my-service.127.0.0.1.nip.io". Any host name works as long as it ends in ".127.0.0.1.nip.io".The advantage of this is that some applications assume they're mounted at the root of a web server and don't like to be mounted on subpaths. With this setup, there's no custom port or path, the only thing that's different is the address or base URL.
If you bind ingress to a different address swap out "127.0.0.1". If you prefer a different wildcard DNS service, use that instead of "nip.io".