2015-07-12 04:04:52 +00:00
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
<!-- BEGIN STRIP_FOR_RELEASE -->
2015-07-16 17:02:26 +00:00
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< h2 > PLEASE NOTE: This document applies to the HEAD of the source tree< / h2 >
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.
< strong >
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 ](http://releases.k8s.io ).
< / strong >
--
2015-07-13 22:15:35 +00:00
2015-07-12 04:04:52 +00:00
<!-- END STRIP_FOR_RELEASE -->
<!-- END MUNGE: UNVERSIONED_WARNING -->
2015-07-20 20:45:36 +00:00
Running Kubernetes locally via Docker
2015-06-22 19:39:35 +00:00
-------------------------------------
2015-06-22 18:56:19 +00:00
2015-06-22 19:39:35 +00:00
**Table of Contents**
2015-06-22 18:56:19 +00:00
2015-06-23 15:20:31 +00:00
- [Overview ](#setting-up-a-cluster )
- [Prerequisites ](#prerequisites )
- [Step One: Run etcd ](#step-one-run-etcd )
- [Step Two: Run the master ](#step-two-run-the-master )
- [Step Three: Run the service proxy ](#step-three-run-the-service-proxy )
- [Test it out ](#test-it-out )
- [Run an application ](#run-an-application )
- [Expose it as a service: ](#expose-it-as-a-service )
- [A note on turning down your cluster ](#a-note-on-turning-down-your-cluster )
2015-06-22 18:56:19 +00:00
2015-06-22 19:39:35 +00:00
### Overview
2015-04-04 00:04:58 +00:00
2015-07-20 20:45:36 +00:00
The following instructions show you how to set up a simple, single node Kubernetes cluster using Docker.
2015-04-04 00:04:58 +00:00
2015-04-07 04:47:04 +00:00
Here's a diagram of what the final result will look like:
![Kubernetes Single Node on Docker ](k8s-singlenode-docker.png )
2015-06-22 19:39:35 +00:00
### Prerequisites
2015-07-17 22:35:41 +00:00
2015-06-22 19:39:35 +00:00
1. You need to have docker installed on one machine.
2015-07-30 21:19:57 +00:00
2. Your kernel should support memory and swap accounting. Ensure that the
following configs are turned on in your linux kernel:
2015-08-01 05:09:34 +00:00
2015-07-31 17:40:18 +00:00
```console
2015-08-01 21:59:11 +00:00
CONFIG_RESOURCE_COUNTERS=y
CONFIG_MEMCG=y
CONFIG_MEMCG_SWAP=y
CONFIG_MEMCG_SWAP_ENABLED=y
CONFIG_MEMCG_KMEM=y
2015-07-31 17:40:18 +00:00
```
2015-08-01 05:09:34 +00:00
2015-07-31 17:40:18 +00:00
3. Enable the memory and swap accounting in the kernel, at boot, as command line
2015-07-30 21:19:57 +00:00
parameters as follows:
2015-08-01 05:09:34 +00:00
2015-07-31 17:40:18 +00:00
```console
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
```
2015-08-01 21:59:11 +00:00
NOTE: The above is specifically for GRUB2.
2015-07-31 17:40:18 +00:00
You can check the command line parameters passed to your kenel by looking at the
output of /proc/cmdline:
2015-08-01 05:09:34 +00:00
2015-07-31 17:40:18 +00:00
```console
2015-08-01 21:59:11 +00:00
$cat /proc/cmdline
2015-07-31 17:40:18 +00:00
BOOT_IMAGE=/boot/vmlinuz-3.18.4-aufs root=/dev/sda5 ro cgroup_enable=memory
swapaccount=1
```
2015-06-22 19:39:35 +00:00
2015-04-04 00:04:58 +00:00
### Step One: Run etcd
2015-07-17 02:01:02 +00:00
2015-04-04 00:04:58 +00:00
```sh
2015-07-28 23:35:56 +00:00
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
2015-04-04 00:04:58 +00:00
```
### Step Two: Run the master
2015-07-17 02:01:02 +00:00
2015-04-04 00:04:58 +00:00
```sh
2015-08-06 16:25:17 +00:00
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 --address=0.0.0.0 --enable-server --hostname-override=127.0.0.1 --config=/etc/kubernetes/manifests
2015-04-04 00:04:58 +00:00
```
2015-07-14 16:37:37 +00:00
This actually runs the kubelet, which in turn runs a [pod ](../user-guide/pods.md ) that contains the other master components.
2015-04-04 00:04:58 +00:00
### Step Three: Run the service proxy
2015-07-17 22:35:41 +00:00
2015-04-04 00:04:58 +00:00
*Note, this could be combined with master above, but it requires --privileged for iptables manipulation*
2015-07-17 02:01:02 +00:00
2015-04-04 00:04:58 +00:00
```sh
2015-07-28 23:35:56 +00:00
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
2015-04-04 00:04:58 +00:00
```
### Test it out
2015-07-17 22:35:41 +00:00
2015-07-24 21:52:18 +00:00
At this point you should have a running Kubernetes cluster. You can test this by downloading the kubectl
2015-04-04 00:04:58 +00:00
binary
2015-07-28 23:35:56 +00:00
([OS X](https://storage.googleapis.com/kubernetes-release/release/v1.0.1/bin/darwin/amd64/kubectl))
([linux](https://storage.googleapis.com/kubernetes-release/release/v1.0.1/bin/linux/amd64/kubectl))
2015-04-04 00:04:58 +00:00
*Note:*
On OS/X you will need to set up port forwarding via ssh:
2015-07-17 02:01:02 +00:00
2015-04-04 00:04:58 +00:00
```sh
boot2docker ssh -L8080:localhost:8080
```
List the nodes in your cluster by running::
```sh
kubectl get nodes
```
This should print:
2015-07-17 02:01:02 +00:00
2015-07-19 02:04:20 +00:00
```console
2015-04-04 00:04:58 +00:00
NAME LABELS STATUS
127.0.0.1 < none > Ready
```
2015-07-20 20:45:36 +00:00
If you are running different Kubernetes clusters, you may need to specify `-s http://localhost:8080` to select the local cluster.
2015-04-04 00:04:58 +00:00
### Run an application
2015-07-17 02:01:02 +00:00
2015-04-04 00:04:58 +00:00
```sh
2015-07-28 23:35:56 +00:00
kubectl -s http://localhost:8080 run nginx --image=nginx --port=80
2015-04-04 00:04:58 +00:00
```
2015-07-19 05:58:13 +00:00
now run `docker ps` you should see nginx running. You may need to wait a few minutes for the image to get pulled.
2015-04-04 00:04:58 +00:00
2015-07-13 18:11:34 +00:00
### Expose it as a service
2015-07-17 02:01:02 +00:00
2015-04-04 00:04:58 +00:00
```sh
kubectl expose rc nginx --port=80
```
This should print:
2015-07-17 02:01:02 +00:00
2015-07-19 02:04:20 +00:00
```console
2015-04-04 00:04:58 +00:00
NAME LABELS SELECTOR IP PORT(S)
2015-07-28 23:35:56 +00:00
nginx run=nginx run=nginx < ip-addr > 80/TCP
2015-04-04 00:04:58 +00:00
```
2015-07-22 22:14:15 +00:00
If ip-addr is blank run the following command to obtain it. Know issue #10836
2015-07-23 21:02:26 +00:00
2015-07-22 22:14:15 +00:00
```sh
kubectl get svc nginx
```
2015-04-04 00:04:58 +00:00
Hit the webserver:
2015-07-17 02:01:02 +00:00
2015-04-04 00:04:58 +00:00
```sh
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.
### A note on turning down your cluster
2015-07-17 22:35:41 +00:00
2015-07-19 05:58:13 +00:00
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
2015-04-04 00:04:58 +00:00
the cluster, you need to first kill the kubelet container, and then any other containers.
2015-04-06 23:29:46 +00:00
2015-07-31 14:55:11 +00:00
You may use `docker kill $(docker ps -aq)` , note this removes _all_ containers running under Docker, so use with caution.
2015-05-14 22:12:45 +00:00
2015-07-14 00:13:09 +00:00
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
2015-05-14 22:12:45 +00:00
[![Analytics ](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/getting-started-guides/docker.md?pixel )]()
2015-07-14 00:13:09 +00:00
<!-- END MUNGE: GENERATED_ANALYTICS -->