Skip to content

Instantly share code, notes, and snippets.

@frimik
Created September 17, 2019 17:56
Show Gist options
  • Save frimik/85f587c093b35f26d028bf3bb0ebff3e to your computer and use it in GitHub Desktop.
Save frimik/85f587c093b35f26d028bf3bb0ebff3e to your computer and use it in GitHub Desktop.
Local K3D (k3s) cluster base
#!/bin/bash
CLUSTER_NAME="k3s-default"
# Install k3d
k3d --version || wget -q -O - https://raw.githubusercontent.com/rancher/k3d/master/install.sh | bash
# verify it
k3d check-tools
# create a volume and cluster
docker volume create kube-volume
k3d create --name "${CLUSTER_NAME}" --workers 3 --volume kube-volume:/opt/local-path-provisioner --wait 0
KUBECONFIG=$(k3d get-kubeconfig --name "${CLUSTER_NAME}")
echo "Replacing 'default' with '$CLUSTER_NAME' in $KUBECONFIG ..."
sed -i "s/\bdefault\b/${CLUSTER_NAME}/" "${KUBECONFIG}"
kubectl cluster-info
kustomize build --enable_alpha_plugins environments/dev | kubectl apply -f -
@dmarszal
Copy link

For me kubectl only started working after exporting $KUBECONFIG with

export KUBECONFIG=$(k3d get-kubeconfig --name "${CLUSTER_NAME}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment