Created
July 21, 2020 15:05
-
-
Save JasonvanBrackel/39c155e35fc466aa2205e8b817d9a27e to your computer and use it in GitHub Desktop.
theranchcast-21-July-2020.sh
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
| # Links | |
| https://kubernetes.io/docs/tasks/tools/install-kubectl/ | |
| https://k3d.io | |
| #!/bin/sh | |
| k3d_version=v3.0.0 | |
| cluster_name=theranchcast | |
| agent_count=3 | |
| cluster_api_port=6550 | |
| loadbalancer_port_insecure=8088 | |
| loadbalancer_port_secure=8443 | |
| ingress_domain_name=vbthinkpad.local | |
| # Install kubectl if it does not exist | |
| if [ $(command -v kubectl) ] | |
| then | |
| echo "kubectl found. Continuing." | |
| else | |
| echo "kubectl not installed. Installing" | |
| curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl | |
| chmod +x ./kubectl | |
| sudo mv ./kubectl /usr/local/bin/kubectl | |
| fi | |
| # Install k3d if it does not exist | |
| if [ $(command -v k3d) ] | |
| then | |
| echo "k3d found. Continuing." | |
| else | |
| echo "K3d not installed. Installing" | |
| curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | TAG=$k3d_version bash | |
| fi | |
| # Remove a existing clusters if applicable | |
| k3d cluster get $cluster_name | |
| if [ $? -eq 0 ]; then | |
| k3d cluster delete $cluster_name | |
| rm ~/.kube/$cluster_name.conf | |
| unset KUBECONFIG | |
| sleep 5 | |
| fi | |
| # Standup a cluster | |
| k3d cluster create theranchcast --agents=$agent_count --api-port=$cluster_api_port --port=$loadbalancer_port_insecure:80@loadbalancer --port=$loadbalancer_port_secure:443@loadbalancer --update-default-kubeconfig=false --switch-context=false | |
| # Setup KUBECONFIG | |
| k3d kubeconfig get $cluster_name > ~/.kube/$cluster_name.conf | |
| while [ $? -ne 0 ] | |
| do | |
| echo "Waiting for $cluster_name to come up" | |
| sleep 2 | |
| k3d kubeconfig get $cluster_name > ~/.kube/$cluster_name.conf | |
| done | |
| export KUBECONFIG="$HOME/.kube/$cluster_name.conf" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment