How to Deploy RStudio Connect into Local Kubernetes Cluster
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
![RStudio Connect Kubernetes Article Thumbnail](https://i0.wp.com/wordpress.appsilon.com/wp-content/uploads/2022/04/Thumbnail-3.jpg?w=450&ssl=1)
RStudio Connect is a publishing platform that lets you and your team share R Shiny applications, R Markdown reports, APIs, dashboards, Jupyter Notebook, and interactive Python content in one convenient place. Today we’ll show you how to deploy RStudio Connect to the local Kubernetes cluster with ease. Following along shouldn’t take you more than 10 minutes, provided you have a valid RStudio Connect license.
We’ll walk you through the process step by step. We’ll start by covering the prerequisites on macOS, creating a Kubernetes cluster with k3d
, installing dependencies with Helm, configuring the Postgres database, and much more. All the shell commands you’ll see are up-to-date and copy-paste friendly.
Looking for alternative ways to share R Shiny apps? Try GitHub, ShinyApps.io, and ShinyServer – All explained in our detailed guide.
Table of contents:
- Prerequisites to Deploying RStudio Connect to Local Kubernetes Cluster
- How to Create Local Kubernetes Cluster with k3d
- Install Dependencies with Helm
- Install the Postgres Database
- How to Install RStudio Connect to Local Kubernetes Cluster
- Removing the Deployment
- Summary of Deploying RStudio Connect to Local Kubernetes Cluster
Prerequisites to Deploying RStudio Connect to Local Kubernetes Cluster
We assume you’re using a macOS environment, but most of the commands will work on Linux as well. Before attempting to deploy RStudio Connect into Kubernetes, you’ll need a couple of software prerequisites. These are:
- Homebrew package manager
- Kubernetes cluster
- Valid RStudio Connect license
Once you install Homebrew, you should also install the rest of the command-line dependencies by running:
brew update | |
brew install docker kubernetes-cli helm |
Before you can deploy resources, you’ll need to have a working Kubernetes cluster. We suggest using k3d
project for development purposes, as it allows you to create single and multi-node Kubernetes cluster in Docker. If you’re wondering, k3d
is a highly available, certified Kubernetes distribution.
Up next, we’ll use k3d
to prepare a local Kubernetes cluster.
How to Create Local Kubernetes Cluster with k3d
To start, install the current latest release of k3d
binary by running the following shell command:
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash |
You can verify the binary was installed successfully by running the following command:
k3d version |
If you did everything correctly, you’ll see something similar as the output:
![Image 1 - k3d version output](https://i2.wp.com/wordpress.appsilon.com/wp-content/uploads/2022/04/Screenshot-99.png?w=450&ssl=1)
Image 1 – k3d version output
The next step is to create a cluster named rstudio
with a single server node:
k3d cluster create rstudio |
From here, use this shell command to verify the cluster has been created:
kubectl get nodes |
![](https://i0.wp.com/wordpress.appsilon.com/wp-content/uploads/2022/04/Screenshot-100.png?w=450&ssl=1)
Image 2 – Printing local clusters
And that’s it – a local Kubernetes cluster is now created. Up next, we’ll install the dependencies needed to integrate RStudio Connect to our local Kubernetes cluster.
Install Dependencies with Helm
In the Kubernetes world, there’s a standardized way of deploying things. You don’t have to worry about how to pass configuration options like database credentials and figure out how to tie multiple RStudio Connects together.
Kubernetes uses YAML configuration files to describe resources you attempt to deploy. A layer above these files that will allow you to treat your deployment as a package is called a Helm chart.
The best feature of RStudio Helm charts is that you don’t have to write them from scratch. RStudio team has already done that for you, and these charts are already available for public usage.
Before deploying Helm charts, we need to ensure respective repositories are configured:
# subscribe to official rstudio repository | |
helm repo add rstudio https://helm.rstudio.com | |
# subscribe to official bitnami repository, required to deploy postgresql db | |
helm repo add bitnami https://charts.bitnami.com/bitnami | |
helm repo list | |
helm repo update |
You should see the following messages while running the above commands:
![](https://i0.wp.com/wordpress.appsilon.com/wp-content/uploads/2022/04/Screenshot-101.png?w=450&ssl=1)
Image 3 – Installing dependencies with Helm
Deploying things with Helm charts will make your life easier. You can always roll back to a previous version of your deployment or even have multiple deployments within the same Kubernetes cluster.
Install the Postgres Database
At the very minimum, the PostgreSQL Helm chart requires a database password. You can set one from the terminal easily:
# Replace this value with your postgres password | |
export RSC_POSTGRES_PASS="sup3rsecretpassw0rd" |
Next, deploy the database into Kubernetes by running the following commands:
helm install rsc-db bitnami/postgresql \ | |
--version 10.6.1 \ | |
--set postgresqlDatabase="rsc_k8s" \ | |
--set postgresqlUsername="connect" \ | |
--set postgresqlPassword="$RSC_POSTGRES_PASS" \ | |
--set servicePort=5432 |
![](https://i2.wp.com/wordpress.appsilon.com/wp-content/uploads/2022/04/Screenshot-102.png?w=450&ssl=1)
Image 4 – Installing Postgres database
Postgres database installed! You can check its status with the following command:
kubectl get pod -l app.kubernetes.io/name=postgresql |
![](https://i1.wp.com/wordpress.appsilon.com/wp-content/uploads/2022/04/Screenshot-103.png?w=450&ssl=1)
Image 5 – Status of the PostgreSQL database
We now have everything needed to finally install RStudio Connect.
How to Install RStudio Connect to Local Kubernetes Cluster
You will need a working license key before attempting to deploy RStudio Connect into Kubernetes. If you do not have one, contact us at sales@appsilon.com.
First, export your license key as a variable named RSC_LICENSE
:
# Replace this value with your license key | |
export RSC_LICENSE='<your license key>' |
And now deploy RStudio Connect into Kubernetes by running the following commands:
helm install rstudio-connect-prod rstudio/rstudio-connect \ | |
--set config.Postgres.Password="$RSC_POSTGRES_PASS" \ | |
--set license.key="$RSC_LICENSE" |
![](https://i0.wp.com/wordpress.appsilon.com/wp-content/uploads/2022/04/Screenshot-104.png?w=450&ssl=1)
Image 6 – Installing RStudio Connect
Once done, you can use this command to check the status of RStudio Connect:
kubectl get pod -l app.kubernetes.io/name=rstudio-connect |
![](https://i0.wp.com/wordpress.appsilon.com/wp-content/uploads/2022/04/Screenshot-105.png?w=450&ssl=1)
Image 7 – Status of the RStudio Connect pod
You won’t be able to access RStudio Connect in this as of now – you’ll have to configure port forwarding. kubectl port-forward
command allows using resource names, such as a ReplicaSet, to select a matching ReplicaSet to port forward to.
First, grab the ReplicaSet name:
kubectl get rs -l app.kubernetes.io/instance=rstudio-connect-prod |
![](https://i0.wp.com/wordpress.appsilon.com/wp-content/uploads/2022/04/Screenshot-106.png?w=450&ssl=1)
Image 8 – Status of the RStudio Connect ReplicaSet
Next, port-forward port 3939 on localhost
to port 3939 of the running ReplicaSet:
kubectl port-forward rstudio-connect-prod-6bbbdb797b-x7lnr 3939:3939 |
You should see similar output in the console:
![](https://i2.wp.com/wordpress.appsilon.com/wp-content/uploads/2022/04/Screenshot-107.png?w=450&ssl=1)
Image 9 – Status of port forwarding the RStudio Connect ReplicaSet to localhost
Connections made to local port 3939 are forwarded to port 3939 of the ReplicaSet that is running the RStudio Connect server. With this connection in place, you can use your local workstation to access the application using your web browser, i.e. by navigating to http://localhost:3939
.
Removing the Deployment
To stop and remove the existing deployment, run the followings commands:
helm uninstall rstudio-connect-prod | |
helm uninstall rsc-db |
RStudio Connect chart will automatically deregister your license key.
Summary of RStudio Connect in a Local Kubernetes Cluster
And there you have it – you’ve successfully deployed RStudio Connect to the local Kubernetes cluster. There were a lot of steps in the process, we know, but all the shell commands can easily be copied, so we guarantee you won’t run into any issues.
With RStudio Connect on a local Kubernetes cluster, you can now experiment with the product and get familiar with the commonly used features. You’ll want to make sure the applications can be deployed to RStudio Connect locally before you put them into production. Running Connect on a local machine is also a great way to troubleshoot issues related to your deployments and environment in general. In the next post, we’ll describe how RStudio Connect can be deployed into a more production-grade Kubernetes cluster!
Want to deploy Python Streamlit apps to RStudio Connect? This guide will teach you everything you need to know.
The post How to Deploy RStudio Connect into Local Kubernetes Cluster appeared first on Appsilon | Enterprise R Shiny Dashboards.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.