Created
September 14, 2022 00:14
-
-
Save JimHume/b39a89a3ac2b7e3d014d41bd778ba70f to your computer and use it in GitHub Desktop.
Launch the currently-active-kubernetes-cluster's dashboard while copying the token out of the kube config. This gets around the "REDACTED" issue with kubectl taking out the certs & tokens when asking for details directly out of the config.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note: One would want to wrap this in a batch file that contains this: | |
# PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\LaunchKubernetesDashboard.ps1'" | |
# (or whatever you name the file) | |
clear | |
# Get the currently-active cluster name | |
$clusterName = $(kubectl config current-context) | |
# Get the user name for the active context | |
$contextUser = $(kubectl config view -o jsonpath="{.contexts[?(@.name == '$clusterName')].context.user}") | |
# Assign the token by: | |
# - Load the kube config file while looking for the context user. | |
# - Get the 4 lines after the match (-context 0,4) | |
# - Get the last line returned in the context ([-1]) | |
# - Split that entry by spaces (while removing empty entries) | |
# - Get the last entry in the array ([-1]) | |
$token = $((sls -path .\.kube\config -pattern "name: $contextUser" -context 0,4).Context.PostContext[-1].Split(" ", [System.StringSplitOptions]::RemoveEmptyEntries)[-1]) | |
# Copy it to the clipboard for easy access | |
Set-Clipboard $token | |
# Find the name of the dashboard pod | |
$podName=$(kubectl get pods --namespace 'kube-system' -l k8s-app==kubernetes-dashboard -o jsonpath='{.items[].metadata.name}') | |
# Fire up the browser with "Start" so that it heads into the background | |
Start "https://localhost:10000" | |
# Then start the port forwarding to localhost | |
kubectl port-forward pods/$podName 10000:8443 -n kube-system | |
# Use CTRL+C CTRL+C to exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment