Skip to content

Instantly share code, notes, and snippets.

@finchd
Last active June 20, 2019 18:10
Show Gist options
  • Save finchd/faed96176fe8b169fe1d48a55e64b43a to your computer and use it in GitHub Desktop.
Save finchd/faed96176fe8b169fe1d48a55e64b43a to your computer and use it in GitHub Desktop.
K8s Local CLI Setup
#!/usr/bin/env bash
function curl-options(){
curl -sL "$@"
}
## pre-configure
opsys=$(uname -s | tr '[:upper:]' '[:lower:]')
## Install
pip install -q --user --upgrade pip awscli aws-shell cfn-flip cfn-lint yamllint \
&& echo "installed user-level pip things: aws-shell awscli cfn-flip cfn-lint yamllint"
mkdir ~/.local/bin #doesn't get made by `pip --user` if your python comes from brew?
pushd ~/.local/bin #now this should work
# Getting Started with Amazon EKS - Install and Configure <b>kubectl</b> for Amazon EKS - https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html#get-started-kubectl
curl-options -O "https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/${opsys}/amd64/aws-iam-authenticator" \
&& chmod 700 aws-iam-authenticator \
&& echo "installed aws-iam-authenticator 0.4.0 from AWS"
curl-options -O "https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/${opsys}/amd64/kubectl" \
&& chmod 700 kubectl \
&& echo "installed kubectl 1.13.7 from AWS"
#kubectx/kubens #os independent bash only
curl-options -O https://raw.githubusercontent.com/ahmetb/kubectx/master/kubectx \
&& chmod 700 kubectx \
&& echo "installed kubectx"
curl-options -O https://raw.githubusercontent.com/ahmetb/kubectx/master/kubens \
&& chmod 700 kubens \
&& echo "installed kubens"
#kube-ps1.sh #os independent bash only
curl-options -O https://raw.githubusercontent.com/jonmosco/kube-ps1/master/kube-ps1.sh \
&& chmod 700 kubens \
&& echo "installed kube-ps1.sh, read https://github.com/jonmosco/kube-ps1 on how to configure and use in your PS1"
# Kustomize install script
#opsys=linux # or darwin, or windows
# //TODO: check for rate-limiting by GitHub API, lol.
#curl -s https://api.github.com/repos/kubernetes-sigs/kustomize/releases/latest |\
# grep browser_download |\
# grep -i ${opsys} |\
# cut -d '"' -f 4 |\
# xargs curl -s -O -L
# NOPE, just doing it my way, w/ explicit versioning
curl-options -O "https://github.com/kubernetes-sigs/kustomize/releases/download/v2.1.0/kustomize_2.1.0_${opsys}_amd64"
mv kustomize_*_${opsys}_amd64 ~/.local/bin/kustomize
chmod u+x ~/.local/bin/kustomize \
&& echo "installed kustomize"
# jq - JSON Query - awk for JSON
# os names aren't normalized to uname output (darwin vs osx)
# binary name has os and arch embedded, remove it
case ${opsys} in
linux) curl-options -o jq "https://github.com/stedolan/jq/releases/download/jq-1.6/jq-${opsys}64"
;;
darwin) curl-options -o jq "https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64"
;;
# does any of this actually work in windows? WSL vs other bash on windows things?
windows) curl-options -o jq "https://github.com/stedolan/jq/releases/download/jq-1.6/jq-win64"
;;
esac
chmod u+x ~/.local/bin/jq \
&& echo "installed jq"
## Download archive-based things to /tmp/
pushd /tmp
# Helm
# I don't use -O, since tar supports streaming
curl-options "https://get.helm.sh/helm-v2.14.1-${opsys}-amd64.tar.gz" | tar xz -C /tmp
mv /tmp/${opsys}-amd64/helm ~/.local/bin/
echo "installed helm 2"
~/.local/bin/helm init --client-only
# eksctl eksctl.io written by weaveworks
# I don't use -O, since tar supports streaming
curl-options "https://github.com/weaveworks/eksctl/releases/download/0.1.37/eksctl_${opsys}_amd64.tar.gz" | tar xz -C /tmp
mv /tmp/eksctl ~/.local/bin
echo "installed eksctl"
# JSON Incremental Digger - interactive jq-ish
curl-options -O "https://github.com/simeji/jid/releases/download/v0.7.6/jid_${opsys}_amd64.zip"
unzip "/tmp/jid_${opsys}_amd64.zip" #unzip can't accept a stream on stdin
mv /tmp/jid ~/.local/bin
echo "installed jid"
#kubectl 1.12+ only, install the krew kubectl plugin manager, *exactly* with their published instructions to ~/.krew/bin/
(
set -x; cd "$(mktemp -d)" &&
curl -fsSLO "https://storage.googleapis.com/krew/v0.2.1/krew.{tar.gz,yaml}" &&
tar zxvf krew.tar.gz &&
./krew-"$(uname | tr '[:upper:]' '[:lower:]')_amd64" install \
--manifest=krew.yaml --archive=krew.tar.gz
)
#end archive downloads
popd
## Config Files
if [ ! -d ~/.kube ]; then mkdir ~/.kube; fi
# **IF** you made the cluster with this user
# aws eks update-kubeconfig --name cluster_name
# else
#echo "export KUBECONFIG=~/.kube/<thing>:$KUBECONFIG" >> ~/.bashrc
echo "remember to add ~/.krew/bin to your PATH, add KUBECONFIG variable, and kube-ps1 to your PS1 in ~/.bashrc or equivalent and 'source ~/.bashrc'"
## END
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment