##Install Kubernetes CLI Tools
- Available via homebrew:
brew install kubernetes-cli
##Install Docker and Docker Machine locally
- Easiest way to do this is with Docker Toolbox.
- Link is here: https://www.docker.com/toolbox
- Standard install should work fine and will detect and upgrade components if necessary (even virtualbox).
##Create Docker Machine
- Once install has completed above, create a new Docker Machine inside of Virtualbox with the following command:
docker-machine create --driver virtualbox vbox-dev
- When new machine is created issue
docker-machine env vbox-dev
:
Spencers-MBP:~ spencer$ docker-machine env vbox-dev
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/spencer/.docker/machine/machines/vbox-dev"
export DOCKER_MACHINE_NAME="vbox-dev"
# Run this command to configure your shell:
# eval "$(docker-machine env vbox-dev)"
-
Issue the eval command at the end of the previous output to load the Docker variables into your terminal session. This eval command is one to take note of, as weird behavior can occur when you don't have these variables present in your session.
-
Verify you can talk to your new machine with
docker ps
. Should return empty:
Spencers-MBP:~ spencer$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- In the same terminal session, setup some port forwarding over SSH to allow us to communicate with our up coming Kubernetes cluster. Issue the following:
ssh -i $DOCKER_CERT_PATH/id_rsa -f -N -L 8080:localhost:8080 [email protected]
- Verify this is running in the background with
ps aux | grep ssh
:
Spencers-MBP:~ spencer$ ps aux | grep ssh
root 26710 0.0 0.0 2461204 444 ?? Ss 7:10PM 0:00.00 ssh -i /Users/spencer/.docker/machine/machines/vbox-dev/id_rsa -f -N -L 80:localhost:80 -L 8080:localhost:8080 [email protected]
##Launch the cluster
-
Double check your env vars are set with
eval "$(docker-machine env vbox-dev)"
-
Run etcd:
docker run --net=host -d gcr.io/google_containers/etcd:2.0.9 /usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data
- Run master:
docker run --net=host -d -v /var/run/docker.sock:/var/run/docker.sock gcr.io/google_containers/hyperkube:v0.21.2 /hyperkube kubelet --api_servers=http://localhost:8080 --v=2 --address=0.0.0.0 --enable_server --hostname_override=127.0.0.1 --config=/etc/kubernetes/manifests
- Run service proxy:
docker run -d --net=host --privileged gcr.io/google_containers/hyperkube:v0.21.2 /hyperkube proxy --master=http://127.0.0.1:8080 --v=2
- Show them running with
docker ps
:
Spencers-MBP:~ spencer$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
52bb21a56f4e gcr.io/google_containers/hyperkube:v0.21.2 "/hyperkube scheduler" 27 seconds ago Up 26 seconds k8s_scheduler.b725e775_k8s-master-127.0.0.1_default_9b44830745c166dfc6d027b0fc2df36d_a5aaa5f2
755e4bfc18b4 gcr.io/google_containers/hyperkube:v0.21.2 "/hyperkube apiserver" 27 seconds ago Up 26 seconds k8s_apiserver.70750283_k8s-master-127.0.0.1_default_9b44830745c166dfc6d027b0fc2df36d_60fef499
c1c53207e962 gcr.io/google_containers/hyperkube:v0.21.2 "/hyperkube proxy --m" 27 seconds ago Up 26 seconds elated_elion
b33013e46f2d gcr.io/google_containers/hyperkube:v0.21.2 "/hyperkube controlle" 27 seconds ago Up 26 seconds k8s_controller-manager.aad1ee8f_k8s-master-127.0.0.1_default_9b44830745c166dfc6d027b0fc2df36d_28679b13
f10a6c3d3977 gcr.io/google_containers/pause:0.8.0 "/pause" 37 seconds ago Up 36 seconds k8s_POD.e4cc795_k8s-master-127.0.0.1_default_9b44830745c166dfc6d027b0fc2df36d_b6c936d4
7f484f8411ea gcr.io/google_containers/hyperkube:v0.21.2 "/hyperkube kubelet -" 38 seconds ago Up 37 seconds distracted_jones
e24b500bd17c gcr.io/google_containers/etcd:2.0.9 "/usr/local/bin/etcd " 43 seconds ago Up 42 seconds tender_curie
##Test and Run
- Verify you can connect to the cluster with
kubectl -s http://localhost:8080 get nodes
Spencers-MBP:~ spencer$ kubectl -s http://localhost:8080 get nodesNAME LABELS STATUS
127.0.0.1 kubernetes.io/hostname=127.0.0.1 Ready
- Run NGINX
kubectl -s http://localhost:8080 run-container nginx --image=nginx --port=80
- Make it a service (Not sure what that means yet. I think some assurance that it's always running or something.)
kubectl -s http://localhost:8080 expose rc nginx --port=80
- Double check the local IP of the NGINX container (10.0.0.99 in this example):
Spencers-MBP:~ spencer$ kubectl -s http://localhost:8080 get services
NAME LABELS SELECTOR IP(S) PORT(S)
kubernetes component=apiserver,provider=kubernetes <none> 10.0.0.1 443/TCP
nginx run=nginx run=nginx 10.0.0.99 80/TCP
- SSH into our Docker Machine VM and check if we can curl it with
docker-machine ssh vbox-dev -- curl 10.0.0.99
. The -- at the end of the docker-machine ssh command just allows you to append a single command to run and exit.
Spencers-MBP:~ spencer$ docker-machine ssh vbox-dev -- curl 10.0.0.99
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 612 100 612 0 0 866k 0 --:--:-- --:--:-- --:--:-- 597k
Hi, the last step for curl, it didn't works, even i can't ping the ip, do u know why? how can i debug?