117 lines
3.3 KiB
Bash
Executable File
117 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
function installFavApps() {
|
|
sudo apt update
|
|
# Install my favorite applications and required packages
|
|
sudo apt install htop tmux docker.io conntrack haproxy kubectl
|
|
# Install helm
|
|
curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -
|
|
sudo apt-get install apt-transport-https --yes
|
|
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
|
|
sudo apt-get update
|
|
sudo apt-get install helm
|
|
sudo usermod -aG docker $USER
|
|
echo "Please log out and log back in"
|
|
}
|
|
|
|
function installMinikube() {
|
|
# Download and install minikube
|
|
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
|
|
sudo dpkg -i minikube_latest_amd64.deb
|
|
}
|
|
|
|
function startMinikube() {
|
|
# Start minikube with Docker driver
|
|
minikube start --driver=docker
|
|
}
|
|
|
|
function stopMinikube() {
|
|
minikube tunnel --cleanup
|
|
minikube stop
|
|
}
|
|
|
|
function installHelmApps() {
|
|
helm repo add nginx-stable https://helm.nginx.com/stable
|
|
helm repo add jetstack https://charts.jetstack.io
|
|
helm repo update
|
|
# Install ingress-nginx See: https://artifacthub.io/packages/helm/ingress-nginx/ingress-nginx
|
|
helm install ingress-nginx nginx-stable/nginx-ingress --namespace ingress-nginx --create-namespace -f nginx-values.yml
|
|
# Install cert-manager See: https://artifacthub.io/packages/helm/cert-manager/cert-manager
|
|
helm install ert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true
|
|
}
|
|
|
|
function configureHaproxy(){
|
|
# This is required to emulate a LoadBalancer..
|
|
minikube service -n=ingress-nginx ingress-nginx-nginx-ingress
|
|
# Get ip of loadbalancer
|
|
# This is a Go template that extracts the ports corresponding to the nginx controller service's 80 and 443 ports
|
|
# For more information see: https://stackoverflow.com/questions/37648553/is-there-anyway-to-get-the-external-ports-of-the-kubernetes-cluster
|
|
# This is then passed to the prepared template haproxy configuration and the service is restarted
|
|
NGINXPORTS=( $(kubectl get svc -n=ingress-nginx -o go-template='{{range .items}}{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}{{end}}') )
|
|
echo "${NGINXPORTS[0]}"
|
|
sed -i "s|##INSECSERVERPORT##|${NGINXPORTS[0]}|" haproxy-template.cfg
|
|
echo "${NGINXPORTS[1]}"
|
|
sed -i "s|##SERVERPORT##|${NGINXPORTS[1]}|" haproxy-template.cfg
|
|
sudo cp haproxy-template.cfg /etc/haproxy/haproxy.cfg
|
|
sudo systemctl restart haproxy
|
|
}
|
|
|
|
function applyyaml(){
|
|
kubectl apply -f 000-namespace.yml
|
|
kubectl apply -f 001-configmap.yml
|
|
kubectl apply -f 002-deployment.yml
|
|
kubectl apply -f 003-service.yml
|
|
kubectl apply -f 004-cluserissuer.yml
|
|
kubectl apply -f 005-ingress.yml
|
|
}
|
|
|
|
function listCommands() {
|
|
cat << EOT
|
|
Available commands:
|
|
|
|
prepare
|
|
install
|
|
start
|
|
stop
|
|
reconfigurehaproxy
|
|
reapplyyaml
|
|
help
|
|
|
|
|
|
EOT
|
|
}
|
|
|
|
# Commands
|
|
|
|
case $1 in
|
|
"prepare")
|
|
installFavApps
|
|
;;
|
|
"install")
|
|
installMinikube
|
|
startMinikube
|
|
installHelmApps
|
|
configureHaproxy
|
|
applyyaml
|
|
;;
|
|
"start")
|
|
startMinikube
|
|
;;
|
|
"stop")
|
|
stopMinikube
|
|
;;
|
|
"reconfigurehaproxy")
|
|
configureHaproxy
|
|
;;
|
|
"reapplyyaml")
|
|
applyyaml
|
|
;;
|
|
"help")
|
|
listCommands
|
|
;;
|
|
*)
|
|
echo "No command found."
|
|
echo
|
|
listCommands
|
|
esac
|