Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rewrite your Windows .kube/config to be usable by Linux kubectl inside WSL
#!/bin/bash
win_profile_dir=$(wslpath "$(cmd.exe /c "echo %USERPROFILE%" | tr -d '\r')")
win_dot_kube_dir="${win_profile_dir}/.kube"
win_kube_config="${win_dot_kube_dir}/config"
wsl_dot_kube_dir="${HOME}/.kube"
mkdir -p "${wsl_dot_kube_dir}"
wsl_kube_config="${wsl_dot_kube_dir}/config"
embed=0
if [ "$1" = '--embed' ]
then
embed=1
fi
inline () {
local line="$1" key value wsl_file
IFS=: read -r key value <<<"${line}"
value="${value# }"
wsl_file=$(wslpath "${value}")
if [ -n "${wsl_file}" ] && [ -s "${wsl_file}" ]
then
value="${wsl_file}"
if [ "${embed}" -eq 1 ]
then
value=$(base64 -w0 <"${wsl_file}")
key="${key}-data"
fi
fi
printf '%s: %s\n' "${key}" "${value}"
}
while IFS= read -r line
do
case "${line}" in
*' certificate-authority:'*|*' client-certificate:'*|*' client-key:'*)
inline "${line}"
;;
*)
printf '%s\n' "${line}"
;;
esac
done <"${win_kube_config}" >"${wsl_kube_config}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.