You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

This page is a placeholder for information and processes surrounding Kubernetes (K8).

A quick-start guide can be found here: http://kubernetes.io/docs/getting-started-guides/docker/

This will set up a Kubernetes cluster running locally on your VM.

Deploy a Kubernetes Cluster

Starting a Single-Node (Local Development) Cluster

Provided in the source code for NDS Labs is a script called kube-up.sh which will launch a local kubernetes cluster on your machine.

It will also download kubectl for you, as described above, and place it into the ~/bin/ folder.

#!/bin/sh
docker run \
    --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 \
    --volume=`pwd`/manifests/etcd.json:/etc/kubernetes/manifests/etcd.json \
    --net=host \
    --pid=host \
    --privileged=true \
    -d \
    gcr.io/google_containers/hyperkube-amd64:v{K8S_VERSION} \
    /hyperkube kubelet \
        --containerized \
        --hostname-override="127.0.0.1" \
        --address="0.0.0.0" \
        --api-servers=http://localhost:8080 \
        --config=/etc/kubernetes/manifests \
        --allow-privileged=true --v=2
mkdir -p ~/bin
if [ ! -e ~/bin/kubectl ]; then
	curl http://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl -o ~/bin/kubectl
	chmod +x ~/bin/kubectl
fi

 

NOTE: The first time you start your cluster, Kubernetes will tell docker to download several images.

This happens in the background and can take several minutes, so please be patient.

Downloading kubectl

The following set of commands can be used to install kubectl on your machine. You may need to change the version number below:

export K8S_VERSION=1.1.7
mkdir ~/bin
curl -L "https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl" > .
export PATH=$PATH:`pwd`
chmod +x ~/bin/* 

Deploying a Multi-Node (Production) Cluster

OpenStack (Nebula)

More information is needed on what would be involved in this process

kubectl create / delete

Pods

A Kubernetes Pod consists of one or more Docker containers running on the same local network.

This allows related or tightly-coupled services to run together with ease, communicating via localhost.

The Kubernetes Pod Spec

Pods can be configured to run with any number of custom configuration options, such as:

  • Ports utilized / exposed
  • Environment variables
  • Custom commands and arguments
  • Custom labels for further specification of functionality or purpose

See http://kubernetes.io/docs/user-guide/pods/multi-container/#the-spec-schema for more details on the Kubernetes spec.

Replication Controllers

Pods are mortal, and can crash when things go wrong.

In such cases, it is wise to set up something to monitor a pod or pods and recreate them when necessary.

Enter Replication Controllers, which perform just the task we need!

You can specify all of the inputs to each image of the pod in the same "spec" fashion described above, but also specifying a number of replicas to keep running.

This tells the Controller the if it does not have the desired number of pods, to create or destroy them as necessary to maintain our desired state.

This is immensely powerful in keeping production system running long-term. 

Services

A Kubernetes Service allows a set of pods to receive traffic from within the cluster, which is accomplished by sharing the IPs and Ports of the services is through injected environment variables:

"SPARK_MASTER_SERVICE_HOST=10.132.232.14",
"SPARK_MASTER_SERVICE_PORT=7077",
"SPARK_MASTER_PORT=tcp://10.132.232.14:7077",
"SPARK_MASTER_PORT_7077_TCP=tcp://10.132.232.14:7077",
"SPARK_MASTER_PORT_7077_TCP_PROTO=tcp",
"SPARK_MASTER_PORT_7077_TCP_PORT=7077",
"SPARK_MASTER_PORT_7077_TCP_ADDR=10.132.232.14",
"SERVICE_HOST=10.132.232.14",

 

Any Replication Controllers started after a service will have several environment variable injected into it regarding the connection details of that service.

You can then reference these environment variable in the RC / Pod spec to use the injected values.

NodePort

Setting up a service with a NodePort will allow the service to receive traffic through the node's public (external) IP as well.

The alternative to NodePort is using a LoadBalancer, which is not yet supported on OpenStack.

Labels and Selectors

You can choose which pods a service affects by applying labels to the Pod(s) in question.

You then simply need to provide a matching set of labels to the Service.

See http://kubernetes.io/docs/user-guide/labels/ for more information.Namespaces

Initially, there is only one namespace name default that runs your Kubernetes master.

Namespaces are synonymous with "users" in NDS Labs, and allow you to encapsulate services from one another even further - Services cannot communicate between namespaces.

 

  • No labels