Skip to content

Instantly share code, notes, and snippets.

@michelesr
Created April 6, 2025 18:36
Show Gist options
  • Select an option

  • Save michelesr/6a3bbeb169a32246c64f8262c2844b4e to your computer and use it in GitHub Desktop.

Select an option

Save michelesr/6a3bbeb169a32246c64f8262c2844b4e to your computer and use it in GitHub Desktop.
Colima docker+k3s+ingress+dns setup script
# NOTES
# minikube is used as internal domain for ingress, feel free to change it
# it's just to make it work with apps that were using that domain in minikube
# but it could be anything really
echo 'Installing colima'
brew install colima
echo 'Starting VM'
colima start --cpu=8 --memory=8 --disk=100 --vm-type vz --kubernetes --network-address
echo 'Disabling systemd-resolved and reconfiguring DNS resolver inside VM'
host_ip=$(colima ssh -- cat /etc/hosts | grep 'host.lima.internal' | awk '{print $1}')
colima_ip=$(colima ssh -- resolvectl query colima | grep colima | awk '{print $2}')
colima ssh -- sudo rm -f /etc/resolv.conf
colima ssh -- sudo tee <<<"nameserver ${host_ip}" /etc/resolv.conf
colima ssh -- sudo tee <<<"${colima_ip} colima" -a /etc/hosts
colima ssh -- sudo systemctl disable --now systemd-resolved
echo 'Restarting the VM'
colima restart
echo 'Installing nginx ingress controller'
helm upgrade -n kube-system --install --repo https://kubernetes.github.io/ingress-nginx ingress-nginx ingress-nginx
# if you want to use latest version, you need to deal with https://github.com/ori-edge/k8s_gateway/issues/279
echo 'Installing k8s-gateway to expose ingress domain names'
helm upgrade -n kube-system --install --repo https://ori-edge.github.io/k8s_gateway exdns k8s-gateway --set image.tag=v0.3.4 --set domain=minikube
echo 'Configuring Mac OS DNS to resolve minikube domains'
sudo tee /etc/resolver/minikube <<EOF
domain minikube
nameserver $(kubectl get node -o wide --no-headers | awk '{print $6}')
search_order 1
timeout 5
EOF
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment