Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,16 @@ vagrant ssh -c "/vagrant/scripts/dashboard.sh" controlplane

## Kubernetes Dashboard Access

To get the login token, copy it from _config/token_ or run the following command:
```shell
kubectl -n kubernetes-dashboard get secret/admin-user -o go-template="{{.data.token | base64decode}}"
```
To get the login token, copy it from _config/token

Make the dashboard accessible:
Port forward:
```shell
kubectl proxy
kubectl -n kubernetes-dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443
```

Open the site in your browser:
```shell
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login
https://localhost:8443
```

## To shutdown the cluster,
Expand Down
68 changes: 45 additions & 23 deletions scripts/dashboard.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,56 @@
#!/bin/bash
#
# Deploys the Kubernetes dashboard when enabled in settings.yaml
# Deploys the Kubernetes dashboard using Helm when enabled in settings.yaml

set -euxo pipefail

config_path="/vagrant/configs"

DASHBOARD_VERSION=$(grep -E '^\s*dashboard:' /vagrant/settings.yaml | sed -E -e 's/[^:]+: *//' -e 's/\r$//')

if [ -n "${DASHBOARD_VERSION}" ]; then
while sudo -i -u vagrant kubectl get pods -A -l k8s-app=metrics-server | awk 'split($3, a, "/") && a[1] != a[2] { print $0; }' | grep -v "RESTARTS"; do
# Wait for metrics server to be ready
while sudo -i -u vagrant kubectl get pods -A -l k8s-app=metrics-server | \
awk 'split($3, a, "/") && a[1] != a[2] { print $0; }' | grep -v "RESTARTS"; do
echo 'Waiting for metrics server to be ready...'
sleep 5
done

echo 'Metrics server is ready. Installing dashboard...'

sudo -i -u vagrant kubectl create namespace kubernetes-dashboard
# Install Helm
echo "Installing Helm..."
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

echo "Creating the dashboard user..."
# Add the Kubernetes Dashboard Helm repository
echo "Adding Kubernetes Dashboard Helm repository..."
sudo -i -u vagrant helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
sudo -i -u vagrant helm repo update

cat <<EOF | sudo -i -u vagrant kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
EOF
# Install/upgrade the Kubernetes Dashboard
echo "Installing Kubernetes Dashboard version ${DASHBOARD_VERSION}..."
sudo -i -u vagrant helm upgrade --install kubernetes-dashboard \
kubernetes-dashboard/kubernetes-dashboard \
--create-namespace \
--namespace kubernetes-dashboard \
--version "${DASHBOARD_VERSION}"

# Wait for dashboard to be ready
echo "Waiting for dashboard pods to be ready..."
sudo -i -u vagrant kubectl wait --for=condition=ready pod \
-l app.kubernetes.io/instance=kubernetes-dashboard \
-n kubernetes-dashboard \
--timeout=300s

# Create admin user
echo "Creating the dashboard admin user..."

cat <<EOF | sudo -i -u vagrant kubectl apply -f -
apiVersion: v1
kind: Secret
type: kubernetes.io/service-account-token
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
annotations:
kubernetes.io/service-account.name: admin-user
EOF

cat <<EOF | sudo -i -u vagrant kubectl apply -f -
Expand All @@ -52,14 +68,20 @@ subjects:
namespace: kubernetes-dashboard
EOF

echo "Deploying the dashboard..."
sudo -i -u vagrant kubectl apply -f "https://raw.githubusercontent.com/kubernetes/dashboard/v${DASHBOARD_VERSION}/aio/deploy/recommended.yaml"
sleep 5

sudo -i -u vagrant kubectl -n kubernetes-dashboard get secret/admin-user -o go-template="{{.data.token | base64decode}}" >> "${config_path}/token"
echo "The following token was also saved to: configs/token"
# Generate token (Dashboard 7.x compatible)
echo "Generating admin token..."
sudo -i -u vagrant kubectl -n kubernetes-dashboard create token admin-user --duration=87600h > "${config_path}/token"

# Get the control plane IP
CONTROL_IP=$(grep -E '^\s*control_ip:' /vagrant/settings.yaml | sed -E -e 's/[^:]+: *//' -e 's/\r$//')

echo "Kubernetes Dashboard installed successfully!"

echo "Access Token (saved to configs/token):"
cat "${config_path}/token"
echo "
Use it to log in at:
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/overview?namespace=kubernetes-dashboard
"

echo "Dashboard Access URL:"
echo " https://${CONTROL_IP}:30443"
fi
6 changes: 3 additions & 3 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ nodes:
# vm_path: /vagrant/images
software:
box: bento/ubuntu-24.04
calico: 3.26.0
calico: 3.31.0
# To skip the dashboard installation, set its version to an empty value or comment it out:
dashboard: 2.7.0
kubernetes: 1.31.0-*
dashboard: 7.14.0
kubernetes: 1.34.0-*

os: xUbuntu_24.04