Skip to content

Latest commit

 

History

History
213 lines (169 loc) · 7.35 KB

File metadata and controls

213 lines (169 loc) · 7.35 KB

Getting started with Kubernetes on Mesos

Table of Contents

About Kubernetes on Mesos

Mesos allows dynamic sharing of cluster resources between Kubernetes and other first-class Mesos frameworks such as Hadoop, Spark, and Chronos. Mesos also ensures applications from different frameworks running on your cluster are isolated and that resources are allocated fairly among them.

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.

This tutorial will walk you through setting up Kubernetes on a Mesos cluster. It provides a step by step walk through of adding Kubernetes to a Mesos cluster and starting your first pod with an nginx webserver.

NOTE: There are known issues with the current implementation and support for centralized logging and monitoring is not yet available. Please file an issue against the kubernetes-mesos project if you have problems completing the steps below.

Prerequisites

Note: You can, but you don't have to deploy Kubernetes-Mesos on the same machine the Mesos master is running on.

Deploy Kubernetes-Mesos

Log into the future Kubernetes master node over SSH, replacing the placeholder below with the correct IP address.

ssh jclouds@${ip_address_of_master_node}

Build Kubernetes-Mesos.

$ git clone https://github.com/GoogleCloudPlatform/kubernetes
$ cd kubernetes
$ export KUBERNETES_CONTRIB=mesos
$ make

Set some environment variables. The internal IP address of the master may be obtained via hostname -i.

$ export KUBERNETES_MASTER_IP=$(hostname -i)
$ export KUBERNETES_MASTER=http://${KUBERNETES_MASTER_IP}:8888

Deploy etcd

Start etcd and verify that it is running:

$ sudo docker run -d --hostname $(uname -n) --name etcd -p 4001:4001 -p 7001:7001 quay.io/coreos/etcd:v2.0.12
$ sudo docker ps
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

It's also a good idea to ensure your etcd instance is reachable by testing it

curl -L http://${KUBERNETES_MASTER_IP}:4001/v2/keys/

If connectivity is OK, you will see an output of the available keys in etcd (if any).

Start Kubernetes-Mesos Services

Update your PATH to more easily run the Kubernetes-Mesos binaries:

$ 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.

$ export MESOS_MASTER=<host:port or zk:// url>

Create a cloud config file mesos-cloud.conf in the current directory with the following contents:

$ 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:

$ km apiserver \
  --address=${KUBERNETES_MASTER_IP} \
  --etcd-servers=http://${KUBERNETES_MASTER_IP}:4001 \
  --service-cluster-ip-range=10.10.10.0/24 \
  --port=8888 \
  --cloud-provider=mesos \
  --cloud-config=mesos-cloud.conf \
  --v=1 >apiserver.log 2>&1 &

$ km controller-manager \
  --master=${KUBERNETES_MASTER_IP}:8888 \
  --cloud-provider=mesos \
  --cloud-config=./mesos-cloud.conf  \
  --v=1 >controller.log 2>&1 &

$ 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 \
  --v=2 >scheduler.log 2>&1 &

Disown your background jobs so that they'll stay running if you log out.

$ disown -a

Validate KM Services

Interact with the kubernetes-mesos framework via kubectl:

$ kubectl get pods
NAME      READY     STATUS    RESTARTS   AGE
# 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

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. Go to the Frameworks tab, and look for an active framework named "Kubernetes".

Spin up a pod

Write a JSON pod description to a local file:

$ cat <<EOPOD >nginx.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
EOPOD

Send the pod description to Kubernetes using the kubectl CLI:

$ kubectl create -f nginx.yaml
pods/nginx

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:

$ kubectl get pods
NAME      READY     STATUS    RESTARTS   AGE
nginx     1/1       Running   0          14s

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.

What next?

Try out some of the standard Kubernetes examples.

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.

NOTE: Please be aware that there are known issues with the current Kubernetes-Mesos implementation.

Analytics