-
-
Save damselem/4b674b52b66dba5e57df to your computer and use it in GitHub Desktop.
Kubernetes on Mac OS X 10.11 El Capitan with Docker Machine
This file contains hidden or 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
#!/usr/bin/env bash | |
k8s(){ | |
local choice=$1 | |
K8S_VERSION=1.2.0 | |
if [ ! -f $HOME/.google-cloud-sdk/bin/kubectl ]; then | |
echo "No kubectl bin exists! Install the bin to continue :)." | |
return 1 | |
fi | |
if [[ $choice == "up" ]]; then | |
echo "-----Launching local k8s cluster-----" | |
docker run \ | |
--volume=/:/rootfs:ro \ | |
--volume=/sys:/sys:ro \ | |
--volume=/var/lib/docker/:/var/lib/docker:rw \ | |
--volume=/var/lib/kubelet/:/var/lib/kubelet:rw \ | |
--volume=/var/run:/var/run:rw \ | |
--net=host \ | |
--pid=host \ | |
--privileged=true \ | |
-d \ | |
gcr.io/google_containers/hyperkube-amd64:v${K8S_VERSION} \ | |
/hyperkube kubelet \ | |
--containerized \ | |
--hostname-override="127.0.0.1" \ | |
--address="0.0.0.0" \ | |
--api-servers=http://localhost:8080 \ | |
--config=/etc/kubernetes/manifests \ | |
--cluster-dns=10.0.0.10 \ | |
--cluster-domain=cluster.local \ | |
--allow-privileged=true --v=2 | |
echo "-----Setting up SSH tunnel to Docker Machine-----" | |
ssh -f -T -N -L 8082:127.0.0.1:8080 -i ~/.docker/machine/machines/dev/id_rsa docker@$(docker-machine ip dev) &> /dev/null | |
echo "-----Waiting for k8s to initialize-----" | |
until curl http://127.0.0.1:8082 &> /dev/null; | |
do | |
echo ... | |
sleep 1 | |
done | |
echo "-----Launched!-----" | |
echo "-----Setting local dev variables-----" | |
kubectl config set-cluster dev --server=http://127.0.0.1:8082 | |
kubectl config set-context dev --cluster=dev --user=default | |
kubectl config use-context dev | |
kubectl config set-credentials default --token=foobar | |
echo "-----Ready for development!-----" | |
elif [[ $choice == "down" ]]; then | |
# Run twice due to issue with aufs debian driver | |
echo "-----Removing all k8s containers-----" | |
for run in {0..2} | |
do | |
docker ps -a | grep 'k8s_' | awk '{print $1}' | xargs docker rm -f | |
docker ps -a | grep 'gcr.io/google_containers/hyperkube-amd64' | awk '{print $1}' | xargs docker rm -f | |
done | |
echo "-----Stopping SSH tunnel to Docker Machine-----" | |
ps -ef | grep 'ssh.*8082' | grep -v grep | awk '{print $2}' | xargs kill -9 | |
rm ~/.kube/config | |
elif [[ $choice == "restart" ]]; then | |
k8s down | |
k8s up | |
else | |
echo "Kubernetes dev environment" | |
echo "Usage: k8s {up|down|restart}" | |
fi | |
} | |
k8s $* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on http://www.charliedrage.com/kubernetes-dev-in-one-command