Skip to content

Commit

Permalink
feat: support multiple kube config files
Browse files Browse the repository at this point in the history
requires switching to the bash version of kubectx because this is not yet supported
by the golang version see ahmetb/kubectx#211
  • Loading branch information
tekumara committed Jan 26, 2022
1 parent 48d9ad8 commit 0a76fd2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
19 changes: 19 additions & 0 deletions dotfiles/.zshrc.d/kubes.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,29 @@
# https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/kubectl/kubectl.plugin.zsh
# https://github.com/ahmetb/kubectl-aliases
alias k='kubectl'
alias kgp='kubectl get pods'
alias kgpa='kubectl get pods --all-namespaces'
alias kge='kubectl get events --sort-by='{.lastTimestamp}''
keb() {
kubectl exec -i -t "$@" -- /bin/bash
}
kes() {
kubectl exec -i -t "$@" -- /bin/sh
}

unset KUBECONFIG
files=($HOME/.kube/*.yaml(N) $HOME/.k3d/kubeconfig*.yaml(N))
for file in $files; do
KUBECONFIG+="${file}:"
done

export KUBECONFIG

# kube context per shell https://github.com/ahmetb/kubectx/issues/12#issuecomment-557852519
file="$(mktemp -t "kubectx.XXXXXX")"
export KUBECONFIG="${file}:${KUBECONFIG}"
cat <<EOF >"${file}"
apiVersion: v1
kind: Config
current-context: ""
EOF
10 changes: 4 additions & 6 deletions install-root/kubes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,17 @@ popd && rm -rf "$tmp_dir"
echo "Install kubectx"
kubectx_version=0.9.4
tmp_dir=$(mktemp -d) && pushd "$tmp_dir"
curl -fsSLo kubectx.tar.gz "https://github.com/ahmetb/kubectx/releases/download/v${kubectx_version}/kubectx_v${kubectx_version}_linux_x86_64.tar.gz"
echo "db5a48e85ff4d8c6fa947e3021e11ba4376f9588dd5fa779a80ed5c18287db22 kubectx.tar.gz" | sha256sum --check
tar -zxf kubectx.tar.gz
curl -fsSLo kubectx "https://github.com/ahmetb/kubectx/releases/download/v${kubectx_version}/kubectx"
echo "e887e4e2b3dd4c94d0ecdb84270fb4fac2e65c4d5b0ee461e688fb8089fd4900 kubectx" | sha256sum --check
install kubectx /usr/local/bin
popd && rm -rf "$tmp_dir"

# kubens
echo "Install kubens"
kubens_version=0.9.4
tmp_dir=$(mktemp -d) && pushd "$tmp_dir"
curl -fsSLo kubens.tar.gz "https://github.com/ahmetb/kubectx/releases/download/v${kubens_version}/kubens_v${kubens_version}_linux_x86_64.tar.gz"
echo "8b3672961fb15f8b87d5793af8bd3c1cca52c016596fbf57c46ab4ef39265fcd kubens.tar.gz" | sha256sum --check
tar -zxf kubens.tar.gz
curl -fsSLo kubens "https://github.com/ahmetb/kubectx/releases/download/v${kubens_version}/kubens"
echo "509c97c0882e688ae8fad8aa13524cc7c003e4883db447a905bdb47d64c13bdc kubens" | sha256sum --check
install kubens /usr/local/bin
popd && rm -rf "$tmp_dir"

Expand Down

0 comments on commit 0a76fd2

Please sign in to comment.