Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.