Skip to content

Instantly share code, notes, and snippets.

@jloveland
Last active December 17, 2021 17:50
Show Gist options
  • Save jloveland/df1bdec4705220eb5990 to your computer and use it in GitHub Desktop.
Save jloveland/df1bdec4705220eb5990 to your computer and use it in GitHub Desktop.
# Reference:
https://www.cloudgear.net/blog/2015/5-minutes-kubernetes-setup/
# install homebrew and cask
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# install virtualbox
brew cask install virtualbox
# install dockertoolbox
brew cask install dockertoolbox
# add this to your bash profile and source into current shell
eval $(docker-machine env dev)
# clone demo kubernetes
cd ~/Code
git clone https://github.com/cloudgear-net/demo-kubernetes.git
# bring up kubernetes
cd demo-kubernetes
docker-compose up
# install kubernetes
brew install kubernetes-cli
# setup ssh tunnel for kubectl which uses port 8080
docker-machine ssh default -L 8080:localhost:8080
# use kubectl to list the nodes
kubectl get nodes
###########################################################
# NAME LABELS STATUS AGE
# default kubernetes.io/hostname=default Ready 36m
###########################################################
# Create demo service
kubectl run service-demo --image=geku/go-app:0.1 --port=5000
kubectl get pods -l run=service-demo
# Scale service to 3 instances
kubectl scale rc service-demo --replicas=3
kubectl get pods -l run=service-demo
# list replication controllers
kubectl get rc
######################################################################################
# CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE
# service-demo service-demo geku/go-app:0.1 run=service-demo 3 11m
######################################################################################
# expose our service on port 80
kubectl expose rc service-demo --port=80 --target-port=5000 --type=NodePort
# This creates a load balancer and assigns our service a virtual IP where we can reach a random instance of our service.
# Additionally it maps it to a random port on our host server.
# get the node port on your host server
kubectl get -o yaml service/service-demo | grep nodePort
# this returns nodePort: 31538
# now you can curl the load balanced service multiple times and get results from the different machines
curl $(docker-machine ip default):32382/json
################################################################################
# {"hostname":"service-demo-qk3kf","env":["PATH=/usr/local/sbin:/usr/local/bin
################################################################################
curl $(docker-machine ip default):32382/json
################################################################################
# {"hostname":"service-demo-i1tdt","env":["PATH=/usr/local/sbin:/usr/local/bin
################################################################################
# By sending multiple requests you can see that they are answered by different instances (varying hostname).
# remove all pods and the service
kubectl delete service/service-demo
kubectl delete rc/service-demo
@hannes-angst
Copy link

brew changed the docker toolbox package to:
brew cask install docker-toolbox

@thekostya
Copy link

eval $(docker-machine env dev)
Docker machine "dev" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.

should I run?
$ docker-machine create dev

@thekostya
Copy link

docker-machine ssh default -L 8080:localhost:8080
Docker machine "default" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.

should it be "dev"?
or
docker-machine create default ?

@mvitor
Copy link

mvitor commented Jan 27, 2018

Second one: docker-machine create default

@shaoxt
Copy link

shaoxt commented Mar 3, 2018

Run "brew cask install docker-toolbox" instead of "brew cask install docker-toolbox"
Run "docker-machine create dev" before "eval $(docker-machine env dev)"

@punnapr
Copy link

punnapr commented Jun 21, 2018

clone demo kubernetes

##Make directory name "Code"
cd ~/Code
git clone https://github.com/cloudgear-net/demo-kubernetes.git

bring up kubernetes

cd demo-kubernetes
docker-compose up ### this is taking more than 5 minutes ...

docker-compose up is running for more than 30 mins ... Please advise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment