2015-07-12 04:04:52 +00:00
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
<!-- BEGIN STRIP_FOR_RELEASE -->
2015-07-15 00:28:47 +00:00
![WARNING ](http://kubernetes.io/img/warning.png )
![WARNING ](http://kubernetes.io/img/warning.png )
![WARNING ](http://kubernetes.io/img/warning.png )
2015-07-13 22:15:35 +00:00
< h1 > PLEASE NOTE: This document applies to the HEAD of the source
2015-07-12 04:04:52 +00:00
tree only. If you are using a released version of Kubernetes, you almost
certainly want the docs that go with that version.< / h1 >
< strong > Documentation for specific releases can be found at
[releases.k8s.io ](http://releases.k8s.io ).</ strong >
2015-07-15 00:28:47 +00:00
![WARNING ](http://kubernetes.io/img/warning.png )
![WARNING ](http://kubernetes.io/img/warning.png )
![WARNING ](http://kubernetes.io/img/warning.png )
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-06-22 19:39:35 +00:00
Getting started with Kubernetes on Mesos
----------------------------------------
2015-03-12 17:31:42 +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
- [About Kubernetes on Mesos ](#about-kubernetes-on-mesos )
- [Prerequisites ](#prerequisites )
- [Deploy Kubernetes-Mesos ](#deploy-kubernetes-mesos )
- [Deploy etcd ](#deploy-etcd )
- [Start Kubernetes-Mesos Services ](#start-kubernetes-mesos-services )
- [Validate KM Services ](#validate-km-services )
- [Spin up a pod ](#spin-up-a-pod )
- [Run the Example Guestbook App ](#run-the-example-guestbook-app )
- [Test Guestbook App ](#test-guestbook-app )
2015-06-22 18:56:19 +00:00
## About Kubernetes on Mesos
2015-03-12 17:31:42 +00:00
<!-- TODO: Update, clean up. -->
Mesos allows dynamic sharing of cluster resources between Kubernetes and other first-class Mesos frameworks such as [Hadoop][1], [Spark][2], and [Chronos][3].
2015-06-15 08:34:47 +00:00
Mesos also ensures applications from different frameworks running on your cluster are isolated and that resources are allocated fairly among them.
2015-03-12 17:31:42 +00:00
2015-06-15 08:34:47 +00:00
Mesos clusters can be deployed on nearly every IaaS cloud provider infrastructure or in your own physical datacenter. Kubernetes on Mesos runs on-top of that and therefore allows you to easily move Kubernetes workloads from one of these environments to the other.
2015-03-12 17:31:42 +00:00
2015-06-02 15:02:53 +00:00
This tutorial will walk you through setting up Kubernetes on a Mesos cluster.
2015-06-15 08:34:47 +00:00
It provides a step by step walk through of adding Kubernetes to a Mesos cluster and starting your first pod with an nginx webserver.
2015-03-12 17:31:42 +00:00
2015-06-15 08:34:47 +00:00
**NOTE:** There are [known issues with the current implementation][7] and support for centralized logging and monitoring is not yet available.
Please [file an issue against the kubernetes-mesos project][8] if you have problems completing the steps below.
2015-06-11 15:10:32 +00:00
2015-03-12 17:31:42 +00:00
### Prerequisites
2015-06-15 08:34:47 +00:00
* Understanding of [Apache Mesos][6]
* A running [Mesos cluster on Google Compute Engine][5]
* A [VPN connection][10] to the cluster
* A machine in the cluster which should become the Kubernetes *master node* with:
* GoLang > 1.2
* make (i.e. build-essential)
* Docker
**Note**: You *can* , but you *don't have to* deploy Kubernetes-Mesos on the same machine the Mesos master is running on.
2015-03-12 17:31:42 +00:00
### Deploy Kubernetes-Mesos
2015-06-15 08:34:47 +00:00
Log into the future Kubernetes *master node* over SSH, replacing the placeholder below with the correct IP address.
2015-03-12 17:31:42 +00:00
```bash
ssh jclouds@${ip_address_of_master_node}
```
Build Kubernetes-Mesos.
```bash
2015-06-15 08:34:47 +00:00
$ git clone https://github.com/GoogleCloudPlatform/kubernetes
$ cd kubernetes
$ export KUBERNETES_CONTRIB=mesos
$ make
2015-03-12 17:31:42 +00:00
```
Set some environment variables.
2015-06-02 15:02:53 +00:00
The internal IP address of the master may be obtained via `hostname -i` .
2015-03-12 17:31:42 +00:00
```bash
2015-06-15 08:34:47 +00:00
$ export KUBERNETES_MASTER_IP=$(hostname -i)
$ export KUBERNETES_MASTER=http://${KUBERNETES_MASTER_IP}:8888
2015-03-12 17:31:42 +00:00
```
2015-06-15 08:34:47 +00:00
2015-03-12 17:31:42 +00:00
### Deploy etcd
Start etcd and verify that it is running:
```bash
2015-06-15 08:34:47 +00:00
$ sudo docker run -d --hostname $(uname -n) --name etcd -p 4001:4001 -p 7001:7001 quay.io/coreos/etcd:v2.0.12
2015-03-12 17:31:42 +00:00
```
```bash
$ sudo docker ps
2015-06-15 08:34:47 +00:00
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd7bac9e2301 quay.io/coreos/etcd:v2.0.12 "/etcd" 5s ago Up 3s 2379/tcp, 2380/... etcd
2015-03-12 17:31:42 +00:00
```
It's also a good idea to ensure your etcd instance is reachable by testing it
```bash
2015-06-15 08:34:47 +00:00
curl -L http://${KUBERNETES_MASTER_IP}:4001/v2/keys/
2015-03-12 17:31:42 +00:00
```
If connectivity is OK, you will see an output of the available keys in etcd (if any).
### Start Kubernetes-Mesos Services
2015-06-15 08:34:47 +00:00
Update your PATH to more easily run the Kubernetes-Mesos binaries:
```bash
$ export PATH="$(pwd)/_output/local/go/bin:$PATH"
```
Identify your Mesos master: depending on your Mesos installation this is either a `host:port` like `mesos_master:5050` or a ZooKeeper URL like `zk://zookeeper:2181/mesos` .
In order to let Kubernetes survive Mesos master changes, the ZooKeeper URL is recommended for production environments.
```bash
$ export MESOS_MASTER=< host:port or zk: / / url >
```
Create a cloud config file `mesos-cloud.conf` in the current directory with the following contents:
```bash
$ cat < < EOF > mesos-cloud.conf
[mesos-cloud]
mesos-master = ${MESOS_MASTER}
EOF
```
Now start the kubernetes-mesos API server, controller manager, and scheduler on the master node:
2015-03-12 17:31:42 +00:00
```bash
2015-06-15 08:34:47 +00:00
$ km apiserver \
--address=${KUBERNETES_MASTER_IP} \
--etcd-servers=http://${KUBERNETES_MASTER_IP}:4001 \
2015-05-24 04:59:46 +00:00
--service-cluster-ip-range=10.10.10.0/24 \
2015-03-12 17:31:42 +00:00
--port=8888 \
2015-06-15 08:34:47 +00:00
--cloud-provider=mesos \
--cloud-config=mesos-cloud.conf \
2015-03-12 17:31:42 +00:00
--v=1 >apiserver.log 2>& 1 &
2015-06-15 08:34:47 +00:00
$ km controller-manager \
--master=${KUBERNETES_MASTER_IP}:8888 \
--cloud-provider=mesos \
--cloud-config=./mesos-cloud.conf \
2015-03-12 17:31:42 +00:00
--v=1 >controller.log 2>& 1 &
2015-06-15 08:34:47 +00:00
$ km scheduler \
--address=${KUBERNETES_MASTER_IP} \
--mesos-master=${MESOS_MASTER} \
--etcd-servers=http://${KUBERNETES_MASTER_IP}:4001 \
--mesos-user=root \
--api-servers=${KUBERNETES_MASTER_IP}:8888 \
2015-03-12 17:31:42 +00:00
--v=2 >scheduler.log 2>& 1 &
```
Disown your background jobs so that they'll stay running if you log out.
```bash
$ disown -a
```
#### Validate KM Services
Interact with the kubernetes-mesos framework via `kubectl` :
```bash
2015-06-15 08:34:47 +00:00
$ kubectl get pods
2015-07-08 18:20:49 +00:00
NAME READY STATUS RESTARTS AGE
2015-03-12 17:31:42 +00:00
```
```bash
2015-06-15 08:34:47 +00:00
# NOTE: your service IPs will likely differ
$ kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
k8sm-scheduler component=scheduler,provider=k8sm < none > 10.10.10.113 10251/TCP
kubernetes component=apiserver,provider=kubernetes < none > 10.10.10.1 443/TCP
2015-03-12 17:31:42 +00:00
```
2015-06-15 08:34:47 +00:00
Lastly, look for Kubernetes in the Mesos web GUI by pointing your browser to
`http://<mesos_master_ip:port>` . Make sure you have an active VPN connection.
2015-04-02 18:24:20 +00:00
Go to the Frameworks tab, and look for an active framework named "Kubernetes".
2015-03-12 17:31:42 +00:00
## Spin up a pod
Write a JSON pod description to a local file:
```bash
2015-06-15 08:34:47 +00:00
$ cat < < EOPOD > nginx.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
2015-03-12 17:31:42 +00:00
EOPOD
```
Send the pod description to Kubernetes using the `kubectl` CLI:
```bash
2015-06-15 08:34:47 +00:00
$ kubectl create -f nginx.yaml
pods/nginx
2015-03-12 17:31:42 +00:00
```
Wait a minute or two while `dockerd` downloads the image layers from the internet.
We can use the `kubectl` interface to monitor the status of our pod:
```bash
2015-06-15 08:34:47 +00:00
$ kubectl get pods
2015-07-08 18:20:49 +00:00
NAME READY STATUS RESTARTS AGE
2015-06-15 08:34:47 +00:00
nginx 1/1 Running 0 14s
2015-03-12 17:31:42 +00:00
```
Verify that the pod task is running in the Mesos web GUI. Click on the
Kubernetes framework. The next screen should show the running Mesos task that
started the Kubernetes pod.
2015-06-15 08:34:47 +00:00
## What next?
2015-03-12 17:31:42 +00:00
2015-06-15 08:34:47 +00:00
Try out some of the standard [Kubernetes examples][9].
2015-03-12 17:31:42 +00:00
2015-06-15 08:34:47 +00:00
**NOTE:** Some examples require Kubernetes DNS to be installed on the cluster.
Future work will add instructions to this guide to enable support for Kubernetes DNS.
2015-03-12 17:31:42 +00:00
2015-06-15 08:34:47 +00:00
**NOTE:** Please be aware that there are [known issues with the current Kubernetes-Mesos implementation][7].
2015-03-12 17:31:42 +00:00
[1]: http://mesosphere.com/docs/tutorials/run-hadoop-on-mesos-using-installer
[2]: http://mesosphere.com/docs/tutorials/run-spark-on-mesos
[3]: http://mesosphere.com/docs/tutorials/run-chronos-on-mesos
2015-06-15 08:34:47 +00:00
[5]: http://open.mesosphere.com/getting-started/cloud/google/mesosphere/
[6]: http://mesos.apache.org/
[7]: https://github.com/mesosphere/kubernetes-mesos/blob/master/docs/issues.md
[8]: https://github.com/mesosphere/kubernetes-mesos/issues
[9]: ../../examples/
[10]: http://open.mesosphere.com/getting-started/cloud/google/mesosphere/#vpn-setup
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/mesos.md?pixel )]()
2015-07-14 00:13:09 +00:00
<!-- END MUNGE: GENERATED_ANALYTICS -->