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:
${K8S_VERSION}
variable to
a released version of Kubernetes >= “v1.2.0”. If you’d like to use the current stable version of Kubernetes, run the following:export K8S_VERSION=$(curl -sS https://storage.googleapis.com/kubernetes-release/release/stable.txt)
and for the latest available version (including unstable releases):
export K8S_VERSION=$(curl -sS https://storage.googleapis.com/kubernetes-release/release/latest.txt)
export ARCH=amd64
docker run -d \
--volume=/:/rootfs:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:rw \
--volume=/var/lib/kubelet/:/var/lib/kubelet:rw \
--volume=/var/run:/var/run:rw \
--net=host \
--pid=host \
--privileged \
gcr.io/google_containers/hyperkube-${ARCH}:${K8S_VERSION} \
/hyperkube kubelet \
--containerized \
--hostname-override=127.0.0.1 \
--api-servers=http://localhost:8080 \
--config=/etc/kubernetes/manifests \
--cluster-dns=10.0.0.10 \
--cluster-domain=cluster.local \
--allow-privileged --v=2
Note that
--cluster-dns
and--cluster-domain
is used to deploy dns, feel free to discard them if dns is not needed.
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
Architectures other than
amd64
are experimental and sometimes unstable, but feel free to try them out! Valid values:arm
,arm64
andppc64le
. ARM is available with Kubernetes versionv1.3.0-alpha.2
and higher. ARM 64-bit and PowerPC 64 little-endian are available withv1.3.0-alpha.3
and higher. Track progress on multi-arch support here
This actually runs the kubelet, which in turn runs a pod that contains the other master components.
** SECURITY WARNING ** services exposed via Kubernetes using Hyperkube are available on the host node’s public network interface / IP address. Because of this, this guide is not suitable for any host node/server that is directly internet accessible. Refer to #21735 for addtional info.
kubectl
At this point you should have a running Kubernetes cluster. You can test it out
by downloading the kubectl binary for ${K8S_VERSION}
(in this example: v1.2.0
).
Downloads:
linux/amd64
: http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/linux/amd64/kubectllinux/386
: http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/linux/386/kubectllinux/arm
: http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/linux/arm/kubectllinux/arm64
: http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/linux/arm64/kubectllinux/ppc64le
: http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/linux/ppc64le/kubectlOS X/amd64
: http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/darwin/amd64/kubectlOS X/386
: http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/darwin/386/kubectlwindows/amd64
: http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/windows/amd64/kubectlwindows/386
: http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/windows/386/kubectlThe generic download path is:
http://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/${GOOS}/${GOARCH}/${K8S_BINARY}
An example install with linux/amd64
:
curl -sSL "http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/linux/amd64/kubectl" > /usr/bin/kubectl
chmod +x /usr/bin/kubectl
On OS X, to make the API server accessible locally, setup a ssh tunnel.
docker-machine ssh `docker-machine active` -N -L 8080:localhost:8080
Setting up a ssh tunnel is applicable to remote docker hosts as well.
(Optional) Create kubernetes cluster configuration:
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
List the nodes in your cluster by running:
kubectl get nodes
This should print:
NAME STATUS AGE
127.0.0.1 Ready 1h
kubectl 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 deployment nginx --port=80
Run the following command to obtain the cluster local IP of this service we just created:
ip=$(kubectl get svc nginx --template={{.spec.clusterIP}})
echo $ip
Hit the webserver with this IP:
kubectl get svc nginx --template={{.spec.clusterIP}}
On OS X, since docker is running inside a VM, run the following command instead:
docker-machine ssh `docker-machine active` curl $ip
See here for instructions.
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 rm -f $(docker ps -aq)
, note this removes all containers running under Docker, so use with caution.
On OS X, first ssh into the docker VM:
docker-machine ssh `docker-machine active`
sudo umount `cat /proc/mounts | grep /var/lib/kubelet | awk '{print $2}'`
sudo rm -rf /var/lib/kubelet
NotReady
stateIf you see your node as NotReady
it’s possible that your OS does not have memcg enabled.
CONFIG_RESOURCE_COUNTERS=y
CONFIG_MEMCG=y
GRUB_CMDLINE_LINUX="cgroup_enable=memory=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:
$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-3.18.4-aufs root=/dev/sda5 ro cgroup_enable=memory=1
## Support Level
IaaS Provider | Config. Mgmt | OS | Networking | Docs | Conforms | Support Level |
---|---|---|---|---|---|---|
Docker Single Node | custom | N/A | local | docs | Project (@brendandburns) |
For support level information on all solutions, see the Table of solutions chart.
Please see the Kubernetes docs for more details on administering and using a Kubernetes cluster.