Skip to content

Instantly share code, notes, and snippets.

@metal3d
Last active June 9, 2023 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metal3d/ab34f21e685fc9c7e6aee1832c3ba535 to your computer and use it in GitHub Desktop.
Save metal3d/ab34f21e685fc9c7e6aee1832c3ba535 to your computer and use it in GitHub Desktop.
Create kind cluster + projectcontour ingress controller
#!/bin/bash
# Check helm, kubectl and kind
NEEDED=""
for cmd in helm kubectl kind pkexec; do
if ! command -v $cmd >/dev/null 2>&1; then
NEEDED="$NEEDED $cmd"
fi
done
if [ -n "$NEEDED" ]; then
echo "Please install $NEEDED"
exit 1
fi
# check if a kind cluster is present
if kind get clusters | grep -q kind; then
zenity --question --title="Kind cluster present" --text="A kind cluster is present, do you want to delete it?"
if [ $? -ne 0 ]; then
exit 1
fi
fi
# check if the user can open 80 and 443 ports
if [ $(sysctl -n net.ipv4.ip_unprivileged_port_start) -gt 80 ]; then
zenity --question --title="Ports 80 and 443" --text="Ports 80 and 443 are not open for unprivileged users, you need to run this as root or whith sudo privileges:\n\nsysctl -w net.ipv4.ip_unprivileged_port_start=80\n\nWould you like to apply this? (It will ask for your sudo password)"
if [ $? -ne 0 ]; then
exit 1
fi
pkexec sysctl -w net.ipv4.ip_unprivileged_port_start=80
if [ $? -ne 0 ]; then
zenity --error --title="Error" --text="Error running sysctl"
exit 1
fi
fi
set -ex
(
# start zenity progress pulstation in background and wait message from fifo
echo "# Droping Kind Cluster"
kind delete cluster >/dev/null 2>&1
echo "# Creating Kind Cluster"
>/dev/null kind create cluster --config - <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 80
- containerPort: 443
hostPort: 443
EOF
echo "# Waiting for cluster to be ready"
kubectl wait --for=condition=Ready nodes --all --timeout=60s >/dev/null 2>&1
echo "# Installihtmlng Ingress Controller"
helm upgrade --install \
-n projectcontour --create-namespace \
contour oci://registry-1.docker.io/bitnamicharts/contour >/dev/null 2>&1
echo "100") | zenity --progress --title="Creating Kind Cluster" --text="Creating Kind Cluster" --auto-close --pulsate
zenity --info --title="Kind cluster created" --text="Kind cluster created, you can use it now."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment