Skip to content

Instantly share code, notes, and snippets.

@Duologic
Created February 7, 2020 09:56
Show Gist options
  • Save Duologic/7cb75af28328951244e6667709585177 to your computer and use it in GitHub Desktop.
Save Duologic/7cb75af28328951244e6667709585177 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
CLUSTER_NAME=example
BASEDIR=$(dirname $(realpath "$0"))
API_PORT=8555
EXPOSE=30041:30041/tcp
SERVER=${SERVER-localhost}
VOLUME=$BASEDIR/.volume
k3d create \
--name $CLUSTER_NAME \
--volume $VOLUME:/kubernetes \
--volume $VOLUME/local:/opt/local-path-provisioner \
--api-port $SERVER:$API_PORT \
--publish $EXPOSE \
--auto-restart
echo -n 'creating'
set +e
k3d get-kubeconfig --name=$CLUSTER_NAME >/dev/null 2>&1
while [ $? -ne 0 ]; do
sleep 1
echo -n '.'
k3d get-kubeconfig --name=$CLUSTER_NAME >/dev/null 2>&1
done
set -e
echo 'done'
export KUBECONFIG="$(k3d get-kubeconfig --name=$CLUSTER_NAME):$HOME/.kube/config"
kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
kubectl patch storageclass local-path -p '{"metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
kubectl config use-context $CLUSTER_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment