Abstract

The BiocKubeInstall package is a cloud computing resource meant to be used with Kubernetes. The package is used to create binaries for R and Bioconductor packages on specific docker images created by Bioconductor. It works in concert with k8sredis - the Kubernetes application and RedisParam package that parallelizes over a Kubernetes cluster. The package requires knowledge of the google cloud, kubernetes, and binary package creation. It is an internal package to Bioconductor used to make creation and maintainence of package binaries easier and faster.

Prerequesites

The following steps assume you have a Google cloud account, kubernetes controller (kubectl) installed, and your Google account configured, and have the following APIs enabled on the project at a minimum.

- Kubernetes Engine Admin
- Storage Admin
- Service account Admin

These services cost money, and are to be used at your expense.

Kubernetes setup

The ‘BiocKubeInstall’ package uses the k8sredis kubernetes configuration files to apply the kuberenetes configurations on to the GKE cluster.

Once you have k8sredis downloaded from https://github.com/Bioconductor/k8sredis, you can do the following.

Steps:

Default settings used in the following commands are based on local preferences. Please change them according to your needs.

cluster name: biock8scluster

zone: us-east1-b

service account name: bioc-binaries

project ID: fancy-house-303821

  1. Start a kubernetes cluster,

     gcloud container clusters create \
         --zone us-east1-b \
         --num-nodes=6 \
         --machine-type=e2-standard-4 biock8scluster
  2. Get the cluster credentials on your local machine,

     gcloud container clusters get-credentials --zone us-east1-b biock8scluster
  3. Create a service account key. The service account key has ‘Storage Admin’ permissions, so it can upload the binaries to a google bucket.

     ## Create service account
     gcloud iam service-accounts create bioc-binaries \
         --display-name "Storage Admin SA" \
         --description "Bioc Binaries storage admin"
    
     ## List service account
     gcloud iam service-accounts list \
         --filter bioc-binaries@fancy-house-303821.iam.gserviceaccount.com
    
     ## Download service account key locally
     gcloud iam service-accounts keys create \
         bioc-binaries.json \
         --iam-account bioc-binaries@fancy-house-303821.iam.gserviceaccount.com
    
     ## Add 'Storage Admin' role to service account.
     gcloud projects add-iam-policy-binding fancy-house-303821 \
         --member \
         "serviceAccount:bioc-binaries@fancy-house-303821.iam.gserviceaccount.com" \
         --role "roles/storage.admin"
  4. Start NFS volume which is going to be attached to your k8s compute nodes. The NFS mount is where the binary packages will be stored. The location of the NFS volume is under the directory /host on your compute nodes.

     kubectl apply -f k8s/nfs-volume/
  5. Create a kubernetes secret from the service account key which was downloaded in the previous steps bioc-binaries.json.

    The service account key is going to be transmitted to the kubernetes cluster in an encrypted manner. This command below assumes that bioc-binaries.json is located in the same path where you are running the kubectl commands.

     kubectl create secret generic \
         bioc-binaries-service-account-auth \
         --from-file=service_account_key=bioc-binaries.json
  6. Once the key is created, you can now launch the bioc-redis configuration on your kubernetes cluster.

     kubectl apply -f k8s/bioc-redis

Manage kubernetes cluster (if needed)

A few commands which help with the management of the kubernetes cluster are:

  • Check if all the pods, services, and nodes are working as expected:

      kubectl get all
  • Describe specific pods or nodes, to check for failures

      kubectl describe pod/manager
  • Log into a specific pod,

      kubectl exec pod/manager --stdin --tty /bin/bash

To delete and destroy your kubernetes cluster safely,

## Stop redis, rstudio services
kubectl delete -f k8s/bioc-redis/

## Delete NFS volume (this is not recommended)
kubectl delete -f k8s/nfs-volume/

## Delete the kubernetes cluster completely losing all data.
gcloud container clusters delete biock8scluster

BiocKubeInstall

Introduction

Cluster architecture and design

The k8s application launches multiple pods on the nodes within the cluster. The pods are classified into two types, a single “manager” pod and multiple “worker” pods. The manager pod delegates reponsibility i.e the jobs are sent to the workers that actually perform the task. The worker pods are always listening to the manager and waiting for a job. Each worker performs a single job till it is done.

The manager and the worker pass messages between each other using “redis”, and the redis work is available inside the package “RedisParam”.

Storage is also built into the k8s application. The manager and the worker also share a volume mount on the k8s cluster in the form of an NFS volume. The volume is mounted on the path /host/.

The “jobs” here refer to the building of binary R/Bioconductor packages. Each pod gets a single job, where the job is to build a single package binary.

Run

To run an actual job, there is one relevant function, i.e BiocKubeInstall::kube_run().

The function needs to be used within the k8sredis/k8s/bioc-redis/manager-pod.yaml file in your k8sredis k8s application. Within the specification of the manager-pod.yaml,

The function takes in the following arguments, the version of Bioconductor, the docker image_name for which the binaries are being built and the number of workers which need to run in parallel as worker_pool_size.

args: ["-e", "BiocKubeInstall::kube_run(version = '3.13',
                    image_name = 'bioconductor_docker',
                    worker_pool_size = 17)"]

The docker image of the manager node is always going to be bioconductor/bioc-redis:devel

Usage of Binaries on bioconductor_docker images

BiocManager::install('Bioconductor/AnVIL')

AnVIL::install('BiocParallel')

Usage of Binaries on the AnVIL

library(AnVIL)
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
BiocManager::install('Bioconductor/AnVIL')
## 'getOption("repos")' replaces Bioconductor standard repositories, see
## '?repositories' for details
## 
## replacement repositories:
##     CRAN: https://cran.rstudio.com/
## Bioconductor version 3.13 (BiocManager 1.30.15), R 4.1.0 Patched (2021-05-18
##   r80324)
## Installing github package(s) 'Bioconductor/AnVIL'
## Downloading GitHub repo Bioconductor/AnVIL@HEAD
## 
##   
   checking for file ‘/private/var/folders/1w/xf7rrsr1483d4rg7vwbkdy780000gp/T/Rtmpd1AELO/remotes53ff648338c7/Bioconductor-AnVIL-5689b87/DESCRIPTION’ ...
  
✓  checking for file ‘/private/var/folders/1w/xf7rrsr1483d4rg7vwbkdy780000gp/T/Rtmpd1AELO/remotes53ff648338c7/Bioconductor-AnVIL-5689b87/DESCRIPTION’
## 
  
─  preparing ‘AnVIL’:
## 
  
   checking DESCRIPTION meta-information ...
  
✓  checking DESCRIPTION meta-information
## 
  
─  checking for LF line-endings in source and make files and shell scripts
## 
  
─  checking for empty or unneeded directories
## 
  
─  looking to see if a ‘data/datalist’ file should be added
## 
  
─  building ‘AnVIL_1.5.0.tar.gz’
## 
  
   
## 
AnVIL::install('<package_name>')
## 'getOption("repos")' replaces Bioconductor standard repositories, see
## '?repositories' for details
## 
## replacement repositories:
##     CRAN: https://cran.rstudio.com/
## Warning: package '<package_name>' is not available for this version of R
## 
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
## Warning: unable to access index for repository https://storage.googleapis.com/bioconductor_docker/packages/3.13/bioc/bin/macosx/contrib/4.1:
##   cannot open URL 'https://storage.googleapis.com/bioconductor_docker/packages/3.13/bioc/bin/macosx/contrib/4.1/PACKAGES'
## R version 4.1.0 Patched (2021-05-18 r80324)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Big Sur 10.16
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] AnVIL_1.4.0      dplyr_1.0.6      BiocStyle_2.20.0
## 
## loaded via a namespace (and not attached):
##  [1] tidyselect_1.1.1     xfun_0.23            bslib_0.2.5.1       
##  [4] remotes_2.4.0        purrr_0.3.4          vctrs_0.3.8         
##  [7] generics_0.1.0       htmltools_0.5.1.1    yaml_2.2.1          
## [10] pkgbuild_1.2.0       utf8_1.2.1           rlang_0.4.11        
## [13] pkgdown_1.6.1        jquerylib_0.1.4      pillar_1.6.1        
## [16] withr_2.4.2          rapiclient_0.1.3     glue_1.4.2          
## [19] DBI_1.1.1            lambda.r_1.2.4       lifecycle_1.0.0     
## [22] stringr_1.4.0        futile.logger_1.4.3  ragg_1.1.3          
## [25] memoise_2.0.0        evaluate_0.14        knitr_1.33          
## [28] callr_3.7.0          fastmap_1.1.0        ps_1.6.0            
## [31] curl_4.3.1           fansi_0.5.0          BiocManager_1.30.15 
## [34] formatR_1.11         cachem_1.0.5         desc_1.3.0          
## [37] jsonlite_1.7.2       systemfonts_1.0.2    fs_1.5.0            
## [40] textshaping_0.3.5    digest_0.6.27        stringi_1.6.2       
## [43] bookdown_0.22        processx_3.5.2       rprojroot_2.0.2     
## [46] cli_2.5.0            tools_4.1.0          magrittr_2.0.1      
## [49] sass_0.4.0           tibble_3.1.2         futile.options_1.0.1
## [52] crayon_1.4.1         tidyr_1.1.3          pkgconfig_2.0.3     
## [55] ellipsis_0.3.2       prettyunits_1.1.1    rstudioapi_0.13     
## [58] assertthat_0.2.1     rmarkdown_2.8        httr_1.4.2          
## [61] R6_2.5.0             compiler_4.1.0