Unsere Mission
Future of compute - green, open, efficient

Blog.

Krake optimizes your workloads for efficiency, cost, and energy consumption.

Geschrieben von Jan Frömberg
Krake optimizes your workloads for efficiency, cost, and energy consumption

What is Krake and what is it used for?

Krake [ˈkʀaːkə] is an orchestrator engine for containerized and virtualized workloads across distributed and heterogeneous cloud platforms. It creates a thin layer of aggregation on top of the different platforms (such as OpenStack, Kubernetes or OpenShift) and presents them through a single interface to the cloud user. The user’s workloads are scheduled depending on both user requirements (hardware, latencies, cost) and platforms characteristics (energy efficiency, load). The scheduling algorithm can be optimized for example on latencies, cost, or energy. Krake can be leveraged for a wide range of application scenarios such as central management of distributed compute capacities as well as application management in Edge Cloud infrastructures.

Krake Overview

Krake Components
Figure 1: Overview of Krake Components

 

Krake is hosted on Gitlab: https://gitlab.com/rak-n-rok/krake

Which way to go

There are three different options to get started with Krake. And let it orchestrate your virtualised workloads.

 

  1. Use Ansible (IT automation tool for deployment and more advanced tasks)
  2. KinD (local Kubernetes using Docker container)
  3. or Minikube (local Kubernetes cluster)

First Steps

 

  1. Clone the Krake repository from Gitlab to a folder of your choice.
    git clone https://gitlab.com/rak-n-rok/krake.git
  2. Afterwards install a python virtual environment and all pip dependencies.
    cd krake
    python3 -m venv .env
    Windows: source .env/Scripts/activate
    source .env/bin/activate
    
    # Install "krake" and "rok" dependencies
    $ pip install rok/
    $ pip install krake/
  3. Generate necessary config files. The –allow-anonymous and –static-authentication-enabled options set the API with minimal authentication and authorization protections. It should not be used within a production deployment environment.
    # first, start the generate script 
    krake_generate_config config/*.template rok.yaml.template
    
    krake_generate_config --allow-anonymous --static-authentication-enabled config/api.yaml.template
    
    # afterwards create that folder which is expected:
    sudo mkdir /etc/krake
    
    # last, copy generated files to that directory with 
    sudo cp *.yaml /etc/krake
  4. Choose a technology of your choice to get started with Krake. In this example we recommend using Minikube.

Ansible

 

Krake provides a bunch of playbooks to automatically provision and host Krake on a local or a remote kubernetes cluster. All these files are located in a subfolder called `/ansible`.

 

Prerequisites: Ansible 2.9.x

 

The infrastructure is split into multiple separate OpenStack Heat stacks. Every Heat stack is provisioned by its own Ansible playbook. The complete infrastructure can be created by the top-level site.yml playbook.

 

Krake YAML inventory file hosts.yml needs to be created. Use the example file and adjust it. The only parameter that needs to be modified is the keypair variable. It should name an existing OpenStack keypair. If the corresponding key file is not ~/.ssh/id_rsa specify it in the key_file parameter.

 

For detailed Ansible deployment information please refer to the official documentation of Krake hosted on readthedocs.io.

KinD

 

Create KinD instance and save the kubeconfig file in „cluster_certs“ sub-directory.

 

mkdir cluster_certs
# the name of your k8s cluster
CLUSTER_NAME="myfancycluster"
# start a single node k8s cluster
kind create cluster --name $CLUSTER_NAME --kubeconfig cluster_certs/config/$CLUSTER_NAME.yaml

Minikube

 

Create Minikube instance and download/copy the kubeconfig file, as well as the certificate and key file necessary to connect to your Minikube instance.

 

mkdir cluster_certs
minikube start

Create a Cluster Configuration

 

Krake will later use this configuration file to register that specific cluster-backend. There are several options to get your cluster configuration depending on the cluster-technology (kinD, k8s, minikube) you are using. For KinD you already got your config file with the above command:

kind create .. --kubeconfig cluster_certs/config/$CLUSTER_NAME.yaml

 

If your are planning to use Minikube you could use the ‚kubectl‘ command:

kubectl config view >> krake/cluster_certs/minikube_conf.yaml

 

Attention: If you have installed both KinD and Minikube this command would list both configurations. You then should remove the KinD configuration.

 

Here you can see an example configuration of Minikube for Krake.

apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/USER/.minikube/ca.crt
    extensions:
    - extension:
        last-update: Wed, 30 Mar 2022 12:36:02 CEST
        provider: minikube.sigs.k8s.io
        version: v1.23.2
      name: cluster_info
    server: https://192.168.49.2:8443
  name: minikube2
contexts:
- context:
    cluster: minikube2
    extensions:
    - extension:
        last-update: Wed, 30 Mar 2022 12:36:02 CEST
        provider: minikube.sigs.k8s.io
        version: v1.23.2
      name: context_info
    namespace: default
    user: minikube2
  name: minikube2
current-context: minikube2
kind: Config
preferences: {}
users:
- name: minikube2
  user:
    client-certificate: /home/USER/.minikube/profiles/minikube/client.crt
    client-key: /home/USER/.minikube/profiles/minikube/client.key

Let’s Go and Start all Together

 

For better overview start each process in a single terminal.

# Run etcd server. This will store the data in "tmp/etcd".
support/etcd

# Run the API
python -m krake.api

# Run the Garbage Collector
python -m krake.controller.gc

# Run the Krake Scheduler
python -m krake.controller.scheduler

# Run the Kubernetes Application Controller
python -m krake.controller.kubernetes

 

There is also a script provided in the git repository to start all parts of Krake using „tmux“.

Finally

 

Now we register the Minikube (or KinD) instance as a Krake backend and use Krake to deploy an echo-server test application.

 

# list current clusters; there should be none
$ rok kube cluster list
+------+-----------+--------+---------+----------+---------+-------+
| name | namespace | labels | created | modified | deleted | state |
+======+===========+========+=========+==========+=========+=======+
+------+-----------+--------+---------+----------+---------+-------+

# register your Minikube or KinD instance by giving a cluster configuration yaml-file, see chapter "Create a Cluster Configuration"
$ rok kube cluster create cluster_certs/config/config.yaml
+------------------+---------------------+
| name             | minikube2           |
| namespace        | system:admin        |
| labels           | None                |
| created          | 2022-03-30 16:00:21 |
| modified         | 2022-03-30 16:00:21 |
| deleted          | None                |
| state            | ONLINE              |
| custom_resources | []                  |
| metrics          | []                  |
| failing_metrics  | None                |
+------------------+---------------------+

# now there is a cluster named minikube2
$ rok kube cluster list
+-----------+--------------+--------+---------------------+---------------------+---------+--------+
| name      | namespace    | labels | created             | modified            | deleted | state  |
+===========+==============+========+=====================+=====================+=========+========+
| minikube2 | system:admin | None   | 2022-03-30 16:00:21 | 2022-03-30 16:00:21 | None    | ONLINE |
+-----------+--------------+--------+---------------------+---------------------+---------+--------+

# run an application on Krake
$ rok kube app create -f rak/functionals/echo-demo.yaml echo-demo
+-----------------------+---------------------+
| name                  | echo-demo           |
| namespace             | system:admin        |
| labels                | None                |
| created               | 2022-03-30 16:01:03 |
| modified              | 2022-03-30 16:01:03 |
| deleted               | None                |
| state                 | PENDING             |
| reason                | None                |
| services              | None                |
| allow migration       | True                |
| label constraints     | []                  |
| resources constraints | []                  |
| hooks                 | []                  |
| scheduled_to          | None                |
| scheduled             | None                |
| running_on            | None                |
+-----------------------+---------------------+

# check the status of the application
$ rok kube app get echo-demo
+-----------------------+-------------------------------------------------------------------------------------------+
| name                  | echo-demo                                                                                 |
| namespace             | system:admin                                                                              |
| labels                | None                                                                                      |
| created               | 2022-03-30 16:01:03                                                                       |
| modified              | 2022-03-30 16:01:05                                                                       |
| deleted               | None                                                                                      |
| state                 | RUNNING                                                                                   |
| reason                | None                                                                                      |
| services              | echo-demo: 192.168.49.2:30285                                                             |
| allow migration       | True                                                                                      |
| label constraints     | []                                                                                        |
| resources constraints | []                                                                                        |
| hooks                 | []                                                                                        |
| scheduled_to          | {'kind': 'Cluster', 'api': 'kubernetes', 'name': 'minikube2', 'namespace': 'system:admin'}|
| scheduled             | 2022-03-30 16:01:04                                                                       |
| running_on            | {'kind': 'Cluster', 'api': 'kubernetes', 'name': 'minikube2', 'namespace': 'system:admin'}|
+-----------------------+-------------------------------------------------------------------------------------------+

# access the application
$ curl 192.168.49.2:30285

Hostname: echo-demo-6ff4d6b744-mcxhb

Pod Information:
-no pod information available-

Server values:
server_version=nginx: 1.13.3 - lua: 10008

Request Information:
client_address=172.17.0.1
method=GET
real path=/
query=
request_version=1.1
request_scheme=http
request_uri=http://192.168.49.2:8080/

Request Headers:
accept=*/*
host=192.168.49.2:30285
user-agent=curl/7.74.0

Request Body:
-no body in request-

# delete the application
$ rok kube app delete echo-demo
+-----------------------+-----------------------------------------------+
| name                  | echo-demo                                     |
| namespace             | system:admin                                  |
| labels                | None                                          |
| created               | 2022-03-30 16:09:34                           |
| modified              | 2022-03-30 16:09:34                           |
| deleted               | 2022-03-30 16:11:30                           |
| state                 | FAILED                                        |
| reason                | code: NO_SUITABLE_RESOURCE                    |
|                       | message: No matching Kubernetes cluster found |
| services              | None                                          |
| allow migration       | True                                          |
| label constraints     | []                                            |
| resources constraints | []                                            |
| hooks                 | []                                            |
| scheduled_to          | None                                          |
| scheduled             | None                                          |
| running_on            | None                                          |
+-----------------------+-----------------------------------------------+

# delete the cluster
$ rok kube cluster delete minikube2
+------------------+---------------------+
| name             | minikube2           |
| namespace        | system:admin        |
| labels           | None                |
| created          | 2022-03-30 16:00:21 |
| modified         | 2022-03-30 16:00:21 |
| deleted          | 2022-03-30 16:08:18 |
| state            | ONLINE              |
| custom_resources | []                  |
| metrics          | []                  |
| failing_metrics  | None                |
+------------------+---------------------+

# check that cluster is deleted
$ rok kube cluster list
+------+-----------+--------+---------+----------+---------+-------+
| name | namespace | labels | created | modified | deleted | state |
+======+===========+========+=========+==========+=========+=======+
+------+-----------+--------+---------+----------+---------+-------+

Command Overview

 

The following figure shows all Krake commands to control parts of either Kubernetes, Openstack or some core elements of Krake.

 

Krake Commands
Figure 2: Overview Krake Commands

 

A complete documentation of Krake can be found at: https://rak-n-rok.readthedocs.io/projects/krake/en/latest/index.html

 

Weitere Blogbeiträge