Created
January 6, 2024 13:11
-
-
Save alexolinux/eee407e6e599086422098a93e68e365c to your computer and use it in GitHub Desktop.
script for creating and deleting kubernetes cluster with K3d
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 | |
create_k3d_cluster() { | |
local cluster_name=$1 | |
echo "Creating k3d cluster $cluster_name..." | |
k3d cluster create "$cluster_name" \ | |
--agents 3 \ | |
--k3s-node-label topology.kubernetes.io/zone=zone-a@agent:0 \ | |
--k3s-node-label topology.kubernetes.io/zone=zone-b@agent:1 \ | |
--k3s-node-label topology.kubernetes.io/zone=zone-c@agent:2 | |
} | |
delete_k3d_cluster() { | |
local cluster_name=$1 | |
echo "Deleting k3d cluster $cluster_name..." | |
k3d cluster delete "$cluster_name" | |
} | |
if [ "$#" -lt 2 ]; then | |
echo "Usage: $0 {create|delete} <cluster_name>" | |
exit 1 | |
fi | |
action=$1 | |
cluster_name=$2 | |
case "$action" in | |
create) | |
create_k3d_cluster "$cluster_name" | |
;; | |
delete) | |
delete_k3d_cluster "$cluster_name" | |
;; | |
*) | |
echo "Usage: $0 {create|delete} <cluster_name>" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment