Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save naviat/67c18f1f47f8b86a1b729e386769b8e6 to your computer and use it in GitHub Desktop.
Save naviat/67c18f1f47f8b86a1b729e386769b8e6 to your computer and use it in GitHub Desktop.
Simple Kubernetes dashboard management for local development
#!/usr/bin/env bash
# Usage
#
# Start: ./kubernetes-dashboard-dev.sh k8s-dashboard-start
# Stop: ./kubernetes-dashboard-dev.sh k8s-dashboard-stop
#
K8S_DASHBOARD_PORT=30000
k8s-dashboard-start () {
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
until kubectl get pods --namespace=kube-system | grep kubernetes-dashboard &> /dev/null
do
sleep 1
done
kube_dashboard_name=$(kubectl get pods --namespace=kube-system | grep kubernetes-dashboard | awk '{print $1}')
until [ "true" == "$(kubectl get pod --namespace=kube-system ${kube_dashboard_name} -o json | jq -r .status.containerStatuses[0].ready)" ]
do
sleep 1
done
nohup kubectl port-forward $(kubectl get pods --namespace=kube-system | grep kubernetes-dashboard | awk '{print $1}') ${K8S_DASHBOARD_PORT}:8443 --namespace=kube-system &> /dev/null &
echo "Kubernetes dashboard available at https://localhost:${K8S_DASHBOARD_PORT}"
}
k8s-dashboard-stop() {
kubectl delete -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
kill $(lsof -nP -i tcp:${K8S_DASHBOARD_PORT} | grep LISTEN | awk '{print $2}')
}
$*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment