-
-
Save sjmach/532d71dfda07cc20d06e8507d106e5ca to your computer and use it in GitHub Desktop.
curl -sSL https://gist.githubusercontent.com/sjmach/532d71dfda07cc20d06e8507d106e5ca/raw/eb289dcf5297b1c9a46cfa8959af34d6a2ec9301/k3sup-gce.sh | bash -s up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -u | |
up() { | |
INSTANCE_TYPE=${INSTANCE_TYPE:-n1-standard-1} | |
curl -sLS https://get.k3sup.dev | sh | |
sudo install k3sup /usr/local/bin/ | |
( | |
set -x | |
gcloud config set compute/zone us-central1-a | |
gcloud compute instances create k3s-1 \ | |
--machine-type "$INSTANCE_TYPE" \ | |
--tags k3s,k3s-master | |
gcloud compute instances create k3s-2 k3s-3 \ | |
--machine-type "$INSTANCE_TYPE" \ | |
--tags k3s,k3s-worker | |
gcloud compute config-ssh | |
) | |
primary_server_ip=$(gcloud compute instances list \ | |
--filter=tags.items=k3s-master \ | |
--format="get(networkInterfaces[0].networkIP)") | |
( | |
set -x | |
gcloud config set compute/zone us-central1-a | |
k3sup install --ip "${primary_server_ip}" --context k3s --ssh-key ~/.ssh/google_compute_engine --user $(whoami) | |
gcloud compute firewall-rules create k3s --allow=tcp:6443 --target-tags=k3s | |
gcloud compute instances list \ | |
--filter=tags.items=k3s-worker \ | |
--format="get(networkInterfaces[0].accessConfigs.natIP)" | \ | |
xargs -L1 k3sup join \ | |
--server-ip $primary_server_ip \ | |
--ssh-key ~/.ssh/google_compute_engine \ | |
--user $(whoami) \ | |
--ip | |
) | |
export KUBECONFIG=`pwd`/kubeconfig | |
kubectl get nodes | |
} | |
down() { | |
set -x | |
gcloud config set compute/zone us-central1-a | |
gcloud compute instances list \ | |
--filter=tags.items=k3s --format="get(name)" | \ | |
xargs gcloud compute instances delete -q | |
gcloud compute firewall-rules delete k3s | |
} | |
usage() { | |
echo "Bootstrap or tear down a k3s cluster on GCE" | |
echo " up" | |
echo " down" | |
} | |
case "${1:-usage}" in | |
up) | |
shift | |
up "$@" | |
;; | |
down) | |
shift | |
down "$@" | |
;; | |
*) | |
usage | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment