If you are using a released version of Kubernetes, you should refer to the docs that go with that version.
The latest 1.0.x release of this document can be found [here](http://releases.k8s.io/release-1.0/docs/getting-started-guides/docker.md).Documentation for other releases can be found at releases.k8s.io.
Table of Contents
- Overview
- Prerequisites
- Step One: Run etcd
- Step Two: Run the master
- Step Three: Run the service proxy
- Test it out
- Run an application
- Expose it as a service:
- A note on turning down your cluster
The following instructions show you how to set up a simple, single node Kubernetes cluster using Docker.
Here's a diagram of what the final result will look like:
-
You need to have docker installed on one machine.
-
Your kernel should support memory and swap accounting. Ensure that the following configs are turned on in your linux kernel:
CONFIG_RESOURCE_COUNTERS=y CONFIG_MEMCG=y CONFIG_MEMCG_SWAP=y CONFIG_MEMCG_SWAP_ENABLED=y CONFIG_MEMCG_KMEM=y
-
Enable the memory and swap accounting in the kernel, at boot, as command line parameters as follows:
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
NOTE: The above is specifically for GRUB2. You can check the command line parameters passed to your kenel by looking at the output of /proc/cmdline:
$cat /proc/cmdline BOOT_IMAGE=/boot/vmlinuz-3.18.4-aufs root=/dev/sda5 ro cgroup_enable=memory swapaccount=1
docker run --net=host -d gcr.io/google_containers/etcd:2.0.12 /usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data
docker run --net=host --privileged -d -v /sys:/sys:ro -v /var/run/docker.sock:/var/run/docker.sock gcr.io/google_containers/hyperkube:v1.0.1 /hyperkube kubelet --api-servers=http://localhost:8080 --v=2 --insecure-bind-address=0.0.0.0 --enable-server --hostname-override=127.0.0.1 --config=/etc/kubernetes/manifests
This actually runs the kubelet, which in turn runs a pod that contains the other master components.
Note, this could be combined with master above, but it requires --privileged for iptables manipulation
docker run -d --net=host --privileged gcr.io/google_containers/hyperkube:v1.0.1 /hyperkube proxy --master=http://127.0.0.1:8080 --v=2
At this point you should have a running Kubernetes cluster. You can test this by downloading the kubectl binary (OS X) (linux)
Note: On OS/X you will need to set up port forwarding via ssh:
boot2docker ssh -L8080:localhost:8080
List the nodes in your cluster by running::
kubectl get nodes
This should print:
NAME LABELS STATUS
127.0.0.1 <none> Ready
If you are running different Kubernetes clusters, you may need to specify -s http://localhost:8080
to select the local cluster.
kubectl -s http://localhost:8080 run nginx --image=nginx --port=80
now run docker ps
you should see nginx running. You may need to wait a few minutes for the image to get pulled.
kubectl expose rc nginx --port=80
This should print:
NAME LABELS SELECTOR IP PORT(S)
nginx run=nginx run=nginx <ip-addr> 80/TCP
If ip-addr is blank run the following command to obtain it. Know issue #10836
kubectl get svc nginx
Hit the webserver:
curl <insert-ip-from-above-here>
Note that you will need run this curl command on your boot2docker VM if you are running on OS X.
Many of these containers run under the management of the kubelet
binary, which attempts to keep containers running, even if they fail. So, in order to turn down
the cluster, you need to first kill the kubelet container, and then any other containers.
You may use docker kill $(docker ps -aq)
, note this removes all containers running under Docker, so use with caution.