#!/usr/bin/env bash if [ -z "$KUBECONFIG" ]; then echo "KUBECONFIG is not set!" echo echo "You can add it to your .bashrc or .zshrc:" echo '> export KUBECONFIG="$HOME/.kube/config"' exit 1 fi # set -x ### === Initial K3D Setup === k3d cluster create inception-of-things # Setup a metrics-server to prevent dumb errors kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml kubectl patch deployment metrics-server -n kube-system --type='json' \ -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--kubelet-insecure-tls"}]' echo '> metrics-server is starting (this takes around ~3 minutes)...' kubectl wait --for=condition=available deployment/metrics-server -n kube-system --timeout=500s ### === ArgoCD === kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml echo "> ArgoCD is starting (this takes around ~6 minutes)..." kubectl wait --namespace argocd \ --for=condition=ready pod \ --selector=app.kubernetes.io/name=argocd-server \ --timeout=300s \ 1>/dev/null 2>/dev/null echo '> Starting watch...' sleep 5 # So we have a progress-ish indicator visual while true; do ready=$(kubectl get pods -n argocd --no-headers 2>/dev/null | grep -E "([0-9]+)/\1" | wc -l) total=$(kubectl get pods -n argocd --no-headers 2>/dev/null | wc -l) clear kubectl get pods -n argocd if [ "$ready" -eq "$total" ] && [ "$total" -gt 0 ]; then break fi sleep 30 done echo "ArgoCD is ready!" echo '> To setup port-forwarding, run:' echo '> kubectl port-forward -n argocd svc/argocd-server 8080:443' kubectl port-forward -n argocd svc/argocd-server 8080:443 1>/dev/null 2>/dev/null & #TODO: The app will be imported via Gitlab, don't import it here # so we don't have 2 of the same deployment. # # SCRIPT_PATH="$(realpath "${BASH_SOURCE[0]}")" # SCRIPT_DIR="$(dirname "$SCRIPT_PATH")" # # kubectl create namespace dev # kubectl apply -n argocd -f "$SCRIPT_DIR/../confs/argocd-app.yml" # echo '>' # echo '> App is starting (this takes around ~30 seconds)...' # echo '>' # sleep 5 # THIS SLEEP IS REQUIRED, IT BREAKS WITHOUT IT, TRUST -kiroussa # kubectl wait --namespace dev \ # --for=condition=ready pod \ # --selector=app=app-p3 \ # --timeout=300s # echo 'App imported in ArgoCD' # sleep 2 ### === Gitlab === kubectl create namespace gitlab helm repo add gitlab https://charts.gitlab.io/ helm repo update # This is the second time a MAJOR SERVICE's prod has gone down while we're the day before the push. # I hate this world. helm upgrade --install gitlab gitlab/gitlab \ -f https://gitlab.com/gitlab-org/charts/gitlab/raw/master/examples/values-minikube-minimum.yaml \ --namespace gitlab \ --timeout 1200s \ --set global.hosts.domain=gitlab-app.com \ --set global.hosts.externalIP=0.0.0.0 \ --set global.hosts.https=false \ --disable-openapi-validation echo '>' echo '> GitLab is starting (this takes around ~10 minutes)...' echo '>' echo '> To watch the pods status, run:' echo '> kubectl get pods -n gitlab -w' echo '>' sleep 5 kubectl wait --namespace gitlab \ --for=condition=available \ --timeout=1200s \ deployment/gitlab-webservice-default echo 'GitLab is ready!' echo echo '> To setup port-forwarding, run:' echo '> kubectl port-forward -n gitlab svc/gitlab-webservice-default 8081:8181' kubectl port-forward -n gitlab svc/gitlab-webservice-default 8081:8181 1>/dev/null 2>/dev/null & ### === Setup /etc/hosts === function add_host() { local ip=$1 local domain=$2 local service=$3 # If it's already there, remove it if grep -q $domain /etc/hosts; then sudo sed -i "/$domain/d" /etc/hosts fi # Add it echo "$ip $domain" | sudo tee -a "/etc/hosts" echo "$service is now reachable at $domain" } TRAEFIK_IP=$(kubectl get service -n kube-system traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}') add_host "$TRAEFIK_IP" "argo-app.com" "ArgoCD" add_host "$TRAEFIK_IP" "gitlab-app.com" "Gitlab" ### === Login === echo "=== Login into ArgoCD with: ===" echo Username: admin echo -n "Password: " kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d echo echo "===============================" echo echo "=== Login into Gitlab with: ===" echo Username: root echo -n "Password: " kubectl -n gitlab get secret gitlab-gitlab-initial-root-password -o jsonpath='{.data.password}' | base64 -d echo echo "==============================="