Skip to content

Instantly share code, notes, and snippets.

@brandocorp
Created October 19, 2021 00:48
Show Gist options
  • Save brandocorp/e1662dc50b75bda68af6f63f1a7197f1 to your computer and use it in GitHub Desktop.
Save brandocorp/e1662dc50b75bda68af6f63f1a7197f1 to your computer and use it in GitHub Desktop.
Setup local Kubernetes cluster with ingress-nginx
#!/bin/bash -e
# Dependencies:
# - k3d (github.com/rancher/k3d)
# - kubectl (github.com/kubernetes/kubectl)
# - jq (github.com/stedolan/jq)
setup_cluster() {
k3d cluster create dev \
--agents 1 \
--k3s-arg "--disable=traefik@server:0" \
--k3s-arg "--disable=servicelb@server:0" \
--no-lb \
--wait
}
install_metallb() {
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.10.3/manifests/namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.10.3/manifests/metallb.yaml
}
configure_metallb() {
lb_cidr="$(
docker network inspect k3d-dev \
| jq -r '.[0].IPAM.Config[0].Subnet' \
| awk '{split($0,i,"."); print sprintf("%d.%d.%d.%s", i[1],i[2],i[3], "240/29")}'
)"
cat <<EOF | kubectl apply -f
apiVersion: v1
kind: ConfigMap
metadata:
name: config
namespace: metallb-system
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- $lb_cidr
EOF
}
install_ingress_nginx() {
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.4/deploy/static/provider/baremetal/deploy.yaml
kubectl patch svc ingress-nginx-controller -n ingress-nginx -p '{"spec": {"type": "LoadBalancer"}}'
}
main() {
setup_cluster
install_metallb
configure_metallb
install_ingress_nginx
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment