Planet PowerShell logo

Contents

Using a Raspberry Pi Kubernetes Cluster to Help Fight Covid19 With Rosettaathome

I recently learned about a cool project called [email protected], which utilizes people’s personal computers to design new proteins and to predict their 3-dimensional shapes. This process can help scientists in learning about diseases such as COVID-19.

I thought this cause of using the CPU power I have available in my Raspberry Pi Kubernetes cluster to help scientists learn about COVID was pretty cool. So I decided to figure out how I could create an application that could be replicated on the cluster, to easily scale the CPU load up and down. This way I can help fight COVID when I don’t really use the cluster for anything, and when I need to learn and use the cluster I can scale the COVID CPU resources a bit down, to have more resources available for my own use.

The video below explains really well how contributions are used by scientists to fight COVID-19.

How to build the Raspberry Pi Kubernetes Cluster? And why use Raspberry Pi’s

I have made a post on how I have built a Raspberry Pi Kubernetes Cluster. If you are interested I suggest you go check out this guide. It will walk you through everything you need and how you set it all up.

Why Raspberry Pi’s ?

I chose to use Raspberry Pi’s to have a low energy efficient Kubernetes Cluster. In my cluster, I have 6 Raspberry Pi’s running which consumes about 70 watts of power, depending on the load. With 70 watts of power load, I have 24 cores and 24 gigs of memory available. This amount of power would never be available on an x86 platform.

Why use [email protected] instead of [email protected]?

If you have heard about [email protected] and wondering why I have chosen Rosetta instead, it is mainly because of the compatibility with the ARM CPU architecture running on the Raspberry Pi’s.

Creating an account on [email protected]

Once you have your Rasberry Pi Kubernetes cluster ready, all you need is to set up an account with [email protected] to join your cluster. This account is used to choose which project you want to contribute CPU power to. It is also used to store your credits. Credit is a measurement of how much you have contributed to the project. What I have learned you cannot use the credits to anything except see that you are actually contributing and the cluster is actually solving tasks for scientists.

To create an account you need to go to the site https://boinc.bakerlab.org/rosetta/ and click on the button “sign up” in the top right corner.

Here you will need to provide a name, email, password, and the country you live in.

Then once you have your account created you are ready to deploy the application to the Kubernetes Cluster

Deploying the BOINC application to your kubernetes cluster

The application you are actually deploying to your cluster i called BOINC. The BOINC client can be run either with a GUI or headless like we are going to do on the cluster. The client app is going to handle all the communication between to rosetta servers and your machine. It is also going to manage all the tasks which are sent to your cluster to be computed.

In the cluster, i am creating a deployment that will use the Docker image boinc/client. This image has a tag for arm64 bit which i am using on the Kubernetes cluster.

/images/using-a-raspberry-pi-kubernetes-cluster-to-help-fight-covid19-with-rosettaathome/image1.png

Going through the deployment yaml file

I have on my kubernetes master created a folder named boinc and inside this folder, i have created a file named deployment.yaml

This file consists of two configurations.

The first configuration will create a namespace to group all the resources used for [email protected] together. The namespace will be called boinc

1
2
3
4
5
6
apiVersion: v1
kind: Namespace
metadata:
name: boinc
labels:
    name: boinc

The second configuration is the actual pod itself. The pod is the container running the BOINC client, and actually providing the CPU resources to complete the tasks provided to it.

This configuration is basically deploying a docker container on the Kubernetes cluster, with a specific amount of CPU and Memory resources. It will also define how many containers it should deploy. This way you can easily scale the number of containers up and down.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
apiVersion: v1
apiVersion: apps/v1
kind: Deployment
metadata:
name: boinc-deployment
namespace: boinc
labels:
    app: boinc
spec:
replicas: 1
selector:
    matchLabels:
    app: boinc
template:
    metadata:
    labels:
        app: boinc
    spec:
    containers:
    - name: boinc
        image: boinc/client:arm64v8
        env:
        - name: BOINC_CMD_LINE_OPTIONS
        value: "--attach_project https://boinc.bakerlab.org/rosetta/ "
        resources:
        requests:
            memory: "512Mi"
            cpu: "1000m"
        limits:
            memory: "1024Mi"
            cpu: "1250m"

Setting the number of containers:

For the container configurations, I have set it to create a single container under the specs by defining how many replicas should be used.

1
2
spec:
replicas: 1

Specifying the CPU and Memory resources of the container:

I have defined that the container should use what measures as 1 single CPU core and 512 Mb of Memory. I have a cluster with 24 cores of CPU, so I could in “theory” be running 24 containers on my cluster. Now this would not work since some resources are used for the OS and running Kubernetes.

1
2
3
4
5
6
7
resources:
requests:
    memory: "512Mi"
    cpu: "1000m"
limits:
    memory: "1024Mi"
    cpu: "1250m"

Connecting the application to your account:

You can provide an environment variable to the container on the initialization of the container. In this environment variable, you can specify your account key. You can find the account key by clicking on “Account Keys” when logged into [email protected]

/images/using-a-raspberry-pi-kubernetes-cluster-to-help-fight-covid19-with-rosettaathome/image2.png

Under the Account Keys page, you will find the “Weak account Key”. This is the key you should use in the environment variable

/images/using-a-raspberry-pi-kubernetes-cluster-to-help-fight-covid19-with-rosettaathome/image3.png

An important thing to note, is that you will need a space between the URL and your account key.

1
2
3
4
5
6
containers:
- name: boinc
    image: boinc/client:arm64v8
    env:
    - name: BOINC_CMD_LINE_OPTIONS
    value: "--attach_project https://boinc.bakerlab.org/rosetta/ "

The complete deployment file

The complete deployment file which you can copy/paste to your own cluster is shown below. Now, remember to enter your account key to connect the containers to your account.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
---
apiVersion: v1
kind: Namespace
metadata:
name: boinc
labels:
    name: boinc
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: boinc-deployment
namespace: boinc
labels:
    app: boinc
spec:
replicas: 3
selector:
    matchLabels:
    app: boinc
template:
    metadata:
    labels:
        app: boinc
    spec:
    containers:
    - name: boinc
        image: boinc/client:arm64v8
        env:
        - name: BOINC_CMD_LINE_OPTIONS
        value: "--attach_project https://boinc.bakerlab.org/rosetta/ "
        resources:
        requests:
            memory: "512Mi"
            cpu: "1000m"
        limits:
            memory: "1024Mi"
            cpu: "1250m"
---

Deploying [email protected] to your cluster

Once you have the yaml file ready on your cluster, you are ready to start the deployment. Once you deploy the application, it will create a new namespace called boinc and it will deploy the number of pods which has been specified in the “replicas”, in the yaml file.

To deploy you can run the following command:

1
kubectl apply -f deployment.yaml

if everything went fine you should see a similar output to below

1
2
namespace/boinc created
deployment.apps/boinc-deployment created

To check that the deployment went fine you can run the command below. You will need to specify “-n boinc” since the pods are stored in the namespace “boinc”.

1
kubectl get pods -n boinc

And the output should look similar to below

1
2
NAME                                READY   STATUS    RESTARTS   AGE
boinc-deployment-75b7c65d6d-nd2jc   1/1     Running   0          24s

Checking that the [email protected] is actually working

You can check the individual containers to see if it is working as expected. To do this you can pull the logs of the container with the following command

1
kubectl -n boinc logs -f

The pod name you will find by running the command

1
kubectl get pods -n boinc

If you see the following in the logs, it means that your application was initialized successfully

1
2
3
15-Jan-2022 12:38:47 [https://boinc.bakerlab.org/rosetta/] Master file download succeeded
15-Jan-2022 12:38:52 [https://boinc.bakerlab.org/rosetta/] Sending scheduler request: Project initialization.
15-Jan-2022 12:38:52 [https://boinc.bakerlab.org/rosetta/] Requesting new tasks for CPU

If you see the following message in your logs, it means that your container has requested tasks, but there were no tasks available for the container. This just means there are no tasks at the moment for your container. This could take a couple of days before your cluster will start receiving tasks to compute.

1
2
3
4
15-Jan-2022 12:39:30 [[email protected]] Sending scheduler request: To fetch work.
15-Jan-2022 12:39:30 [[email protected]] Requesting new tasks for CPU
15-Jan-2022 12:39:32 [[email protected]] Scheduler request completed: got 0 new tasks
15-Jan-2022 12:39:32 [[email protected]] No tasks sent

The best thing you can do now, is to leave the cluster for a couple of days, then check your profile on [email protected], to see if you start receiving credits

/images/using-a-raspberry-pi-kubernetes-cluster-to-help-fight-covid19-with-rosettaathome/image4.png

How to scale the BOINC application

There are two ways to scale the application, so let’s say you want to go from 1 container to 5 containers, meaning going from 1 CPU core to 5 CPU cores. You can do this by running a command or editing the deployment.yaml file.

If you want to edit the yaml file, you just find the replicas and change the number to 5. Then you will need to run a command to update the deployment.

1
kubectl apply -f deployment.yaml

If you want to scale the application by running the single command you can run the command below:

1
kubectl -n boinc scale deployment/boinc-deployment --replicas=5

You should then see an output similar to below

1
deployment.apps/boinc-deployment scaled

And if you run the command below you now see 5 containers running

1
kubectl -n boinc get pods

output:

NAME                                READY   STATUS    RESTARTS   AGE
boinc-deployment-75b7c65d6d-2rmxs   1/1     Running   0          90s
boinc-deployment-75b7c65d6d-72h4n   1/1     Running   0          90s
boinc-deployment-75b7c65d6d-bh5rh   1/1     Running   0          90s
boinc-deployment-75b7c65d6d-nd2jc   1/1     Running   0          19m
boinc-deployment-75b7c65d6d-pkb29   1/1     Running   0          90s

You can use the exact same command to downscale the application

Conclusion

Creating this type of deployment is very useful for learning different subjects on deploying applications to a Kubernetes cluster. It is particularly useful for learning the simple commands on checking which pods are running on the system, checking the pod logs, and so on.

If you have some Raspberry Pi’s laying around and you don’t know what you should do with them, I think this is a great project for start learning Kubernetes, and help out a great cause at the same time.