-
-
Save briscula/d16d7d74441dd0954016a1d7f2f27607 to your computer and use it in GitHub Desktop.
curl -sSL https://gist.githubusercontent.com/drnic/9c5f2d58865c8595fe3aa77672f3ebc8/raw/cf7b10072da392c07257ee33367f3daab2d484d7/k3sup-gce.sh | bash -s up
This file contains 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} | |
( | |
set -x | |
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].accessConfigs.natIP)") | |
( | |
set -x | |
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 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