2015-07-12 00:04:52 -04:00
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
<!-- BEGIN STRIP_FOR_RELEASE -->
2015-07-16 13:02:26 -04: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.
2015-12-14 13:37:38 -05:00
<!-- TAG RELEASE_LINK, added by the munger automatically -->
2015-07-16 13:02:26 -04:00
< strong >
2015-11-03 13:17:57 -05:00
The latest release of this document can be found
[here ](http://releases.k8s.io/release-1.1/docs/getting-started-guides/docker.md ).
2015-07-16 13:02:26 -04:00
Documentation for other releases can be found at
[releases.k8s.io ](http://releases.k8s.io ).
< / strong >
--
2015-07-13 18:15:35 -04:00
2015-07-12 00:04:52 -04:00
<!-- END STRIP_FOR_RELEASE -->
<!-- END MUNGE: UNVERSIONED_WARNING -->
2015-07-20 16:45:36 -04:00
Running Kubernetes locally via Docker
2015-06-22 15:39:35 -04:00
-------------------------------------
2015-06-22 14:56:19 -04:00
2015-06-22 15:39:35 -04:00
**Table of Contents**
2015-06-22 14:56:19 -04:00
2015-11-22 04:06:19 -05:00
- [Overview ](#overview )
2015-06-23 11:20:31 -04:00
- [Prerequisites ](#prerequisites )
2015-12-15 05:09:44 -05:00
- [Run it ](#run-it )
- [Download kubectl ](#download-kubectl )
2015-06-23 11:20:31 -04:00
- [Test it out ](#test-it-out )
- [Run an application ](#run-an-application )
2015-09-10 09:58:58 -04:00
- [Expose it as a service ](#expose-it-as-a-service )
2015-12-19 10:36:36 -05:00
- [Deploy a DNS ](#deploy-a-dns )
2015-06-23 11:20:31 -04:00
- [A note on turning down your cluster ](#a-note-on-turning-down-your-cluster )
2015-12-09 07:54:00 -05:00
- [Troubleshooting ](#troubleshooting )
2015-06-22 14:56:19 -04:00
2015-06-22 15:39:35 -04:00
### Overview
2015-04-03 20:04:58 -04:00
2015-07-20 16:45:36 -04:00
The following instructions show you how to set up a simple, single node Kubernetes cluster using Docker.
2015-04-03 20:04:58 -04:00
2015-04-07 00:47:04 -04:00
Here's a diagram of what the final result will look like:

2015-06-22 15:39:35 -04:00
### Prerequisites
2015-07-17 18:35:41 -04:00
2015-06-22 15:39:35 -04:00
1. You need to have docker installed on one machine.
2015-12-09 07:54:00 -05:00
2. Decide what Kubernetes version to use. Set the `${K8S_VERSION}` variable to
2016-02-02 08:34:38 -05:00
a released version of Kubernetes >= "1.2.0-alpha.7"
2015-10-28 13:03:55 -04:00
2015-12-08 05:42:54 -05:00
### Run it
2015-07-16 22:01:02 -04:00
2015-04-03 20:04:58 -04:00
```sh
2015-09-01 10:42:05 -04:00
docker run \
--volume=/:/rootfs:ro \
--volume=/sys:/sys:ro \
2015-10-16 04:30:02 -04:00
--volume=/var/lib/docker/:/var/lib/docker:rw \
2015-09-01 10:42:05 -04:00
--volume=/var/lib/kubelet/:/var/lib/kubelet:rw \
--volume=/var/run:/var/run:rw \
--net=host \
2015-10-23 17:15:30 -04:00
--pid=host \
2015-09-01 10:42:05 -04:00
--privileged=true \
-d \
2016-01-29 16:01:49 -05:00
gcr.io/google_containers/hyperkube-amd64:v${K8S_VERSION} \
2015-12-08 05:42:54 -05:00
/hyperkube kubelet \
--containerized \
--hostname-override="127.0.0.1" \
--address="0.0.0.0" \
--api-servers=http://localhost:8080 \
--config=/etc/kubernetes/manifests \
2015-12-19 10:36:36 -05:00
--cluster-dns=10.0.0.10 \
--cluster-domain=cluster.local \
2016-02-07 15:15:20 -05:00
--allow-privileged=true --v=2
2015-04-03 20:04:58 -04:00
```
2015-12-19 10:36:36 -05:00
> Note that `--cluster-dns` and `--cluster-domain` is used to deploy dns, feel free to discard them if dns is not needed.
2016-02-07 15:15:20 -05:00
> If you would like to mount an external device as a volume, add `--volume=/dev:/dev` to the command above. It may however, cause some problems described in [#18230](https://github.com/kubernetes/kubernetes/issues/18230)
2015-07-14 12:37:37 -04:00
This actually runs the kubelet, which in turn runs a [pod ](../user-guide/pods.md ) that contains the other master components.
2015-04-03 20:04:58 -04:00
2015-12-19 10:36:36 -05:00
### Download `kubectl`
2015-07-17 18:35:41 -04:00
2015-10-28 13:03:55 -04:00
At this point you should have a running Kubernetes cluster. You can test this
by downloading the kubectl binary for `${K8S_VERSION}` (look at the URL in the
following links) and make it available by editing your PATH environment
variable.
2016-02-02 08:34:38 -05:00
([OS X/amd64](http://storage.googleapis.com/kubernetes-release/release/v1.2.0-alpha.7/bin/darwin/amd64/kubectl))
([OS X/386](http://storage.googleapis.com/kubernetes-release/release/v1.2.0-alpha.7/bin/darwin/386/kubectl))
([linux/amd64](http://storage.googleapis.com/kubernetes-release/release/v1.2.0-alpha.7/bin/linux/amd64/kubectl))
([linux/386](http://storage.googleapis.com/kubernetes-release/release/v1.2.0-alpha.7/bin/linux/386/kubectl))
([linux/arm](http://storage.googleapis.com/kubernetes-release/release/v1.2.0-alpha.7/bin/linux/arm/kubectl))
2015-10-28 13:03:55 -04:00
For example, OS X:
```console
$ wget http://storage.googleapis.com/kubernetes-release/release/v${K8S_VERSION}/bin/darwin/amd64/kubectl
$ chmod 755 kubectl
$ PATH=$PATH:`pwd`
```
Linux:
```console
$ wget http://storage.googleapis.com/kubernetes-release/release/v${K8S_VERSION}/bin/linux/amd64/kubectl
$ chmod 755 kubectl
$ PATH=$PATH:`pwd`
```
2015-04-03 20:04:58 -04:00
2015-12-09 08:31:22 -05:00
Create configuration:
2015-10-18 16:50:39 -04:00
```
2015-12-09 08:31:22 -05:00
$ kubectl config set-cluster test-doc --server=http://localhost:8080
$ kubectl config set-context test-doc --cluster=test-doc
$ kubectl config use-context test-doc
2015-10-18 16:50:39 -04:00
```
2015-12-19 10:36:36 -05:00
For Max OS X users instead of `localhost` you will have to use IP address of your docker machine,
which you can find by running `docker-machine env <machinename>` (see [documentation ](https://docs.docker.com/machine/reference/env/ )
2015-12-10 09:38:55 -05:00
for details).
2015-10-18 16:50:39 -04:00
2015-12-09 08:31:22 -05:00
### Test it out
2015-10-18 16:50:39 -04:00
2015-09-10 09:58:58 -04:00
List the nodes in your cluster by running:
2015-04-03 20:04:58 -04:00
```sh
kubectl get nodes
```
This should print:
2015-07-16 22:01:02 -04:00
2015-07-18 22:04:20 -04:00
```console
2015-10-08 02:51:35 -04:00
NAME LABELS STATUS
127.0.0.1 kubernetes.io/hostname=127.0.0.1 Ready
2015-04-03 20:04:58 -04:00
```
### Run an application
2015-07-16 22:01:02 -04:00
2015-04-03 20:04:58 -04:00
```sh
2015-12-09 08:31:22 -05:00
kubectl run nginx --image=nginx --port=80
2015-04-03 20:04:58 -04:00
```
2015-09-10 09:58:58 -04: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-03 20:04:58 -04:00
2015-07-13 14:11:34 -04:00
### Expose it as a service
2015-07-16 22:01:02 -04:00
2015-04-03 20:04:58 -04:00
```sh
kubectl expose rc nginx --port=80
```
2016-02-02 08:34:38 -05:00
Run the following command to obtain the IP of this service we just created. There are two IPs, the first one is internal (CLUSTER_IP), and the second one is the external load-balanced IP (if a LoadBalancer is configured)
2015-07-16 22:01:02 -04:00
2015-10-26 20:47:18 -04:00
```sh
kubectl get svc nginx
2015-04-03 20:04:58 -04:00
```
2015-10-26 20:47:18 -04:00
Alternatively, you can obtain only the first IP (CLUSTER_IP) by running:
2015-07-23 17:02:26 -04:00
2015-07-22 18:14:15 -04:00
```sh
2015-10-26 20:47:18 -04:00
kubectl get svc nginx --template={{.spec.clusterIP}}
2015-07-22 18:14:15 -04:00
```
2015-10-26 20:47:18 -04:00
Hit the webserver with the first IP (CLUSTER_IP):
2015-07-16 22:01:02 -04:00
2015-04-03 20:04:58 -04:00
```sh
2015-10-26 20:47:18 -04:00
curl < insert-cluster-ip-here >
2015-04-03 20:04:58 -04:00
```
Note that you will need run this curl command on your boot2docker VM if you are running on OS X.
2015-12-19 10:36:36 -05:00
## Deploy a DNS
See [here ](docker-multinode/deployDNS.md ) for instructions.
2015-04-03 20:04:58 -04:00
### A note on turning down your cluster
2015-07-17 18:35:41 -04:00
2015-07-19 01:58:13 -04: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-03 20:04:58 -04:00
the cluster, you need to first kill the kubelet container, and then any other containers.
2015-04-06 19:29:46 -04:00
2015-07-31 10:55:11 -04:00
You may use `docker kill $(docker ps -aq)` , note this removes _all_ containers running under Docker, so use with caution.
2015-05-14 18:12:45 -04:00
2015-12-09 07:54:00 -05:00
### Troubleshooting
2015-12-19 10:36:36 -05:00
#### Node is in `NotReady` state
2015-12-09 07:54:00 -05:00
2015-12-19 10:36:36 -05:00
If you see your node as `NotReady` it's possible that your OS does not have memcg and swap enabled.
2015-12-09 07:54:00 -05:00
1. Your kernel should support memory and swap accounting. Ensure that the
following configs are turned on in your linux kernel:
```console
CONFIG_RESOURCE_COUNTERS=y
CONFIG_MEMCG=y
CONFIG_MEMCG_SWAP=y
CONFIG_MEMCG_SWAP_ENABLED=y
CONFIG_MEMCG_KMEM=y
```
2. Enable the memory and swap accounting in the kernel, at boot, as command line
parameters as follows:
```console
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 kernel by looking at the
output of /proc/cmdline:
```console
2016-02-02 08:34:38 -05:00
$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-3.18.4-aufs root=/dev/sda5 ro cgroup_enable=memory swapaccount=1
2015-12-09 07:54:00 -05:00
```
2015-07-13 20:13:09 -04:00
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
2015-05-14 18:12:45 -04:00
[]()
2015-07-13 20:13:09 -04:00
<!-- END MUNGE: GENERATED_ANALYTICS -->