K3d - Additional Hacks
Create Cluster (with updated Traefik)
CLUSTERNAME="dev$(date +%H%M)"
k3d cluster create ${CLUSTERNAME} \
--agents 3 \
--api-port 127.0.0.1:6443 \
-p 80:80@loadbalancer \
-p 443:443@loadbalancer \
--k3s-server-arg "--no-deploy=traefik"
helm repo add traefik https://containous.github.io/traefik-helm-chart
helm repo update
helm install traefik traefik/traefik
Access a resource
- Not especially a K3d command, but handy to have around for quick testing of Kubernetes services:
kubectl port-forward ${POD_NAME} SYSTEM_PORT:POD_PORT --namespace ${NAMESPACE} &
Example .bashrc
mods for quick cluster generation
- Add either (or both) of these snippets to your
.bashrc
or.bash_profile
to enable quick cluster creation.- After you add these to your Bash environment, simply:
source ~/.bashrc
k3d_istio_cluster_create mycoolcluster
- After you add these to your Bash environment, simply:
- With Istio:
function k3d_istio_cluster_create() {
export CLUSTER_NAME="${1}"
export K3D_CONTEXT="k3d-${CLUSTER_NAME}"
k3d cluster create ${CLUSTER_NAME} \
--servers 1 \
--agents 3 \
--api-port 127.0.0.1:6443 \
--port 80:80@loadbalancer \
--port 443:443@loadbalancer \
--k3s-arg '--no-deploy=traefik@server:0'
istioctl install -y --set profile=default --context ${K3D_CONTEXT}
kubectx ${K3D_CONTEXT}
kubectl label namespace default istio-injection=enabled
kubectl get all -A
}
- Without Istio:
function k3d_traefik_cluster_create() {
export CLUSTER_NAME="${1}"
export K3D_CONTEXT="k3d-${CLUSTER_NAME}"
k3d cluster create $1 \
--agents 3 \
--api-port 127.0.0.1:6443 \
-p 80:80@loadbalancer \
-p 443:443@loadbalancer
kubectx ${K3D_CONTEXT}
kubectl get all -A
}