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:
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:
You can verify the binary was installed successfully by running the following command:
If you did everything correctly, you’ll see something similar as the output:
The next step is to create a cluster named
rstudio with a single server node:
From here, use this shell command to verify the cluster has been created:
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:
You should see the following messages while running the above commands:
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:
Next, deploy the database into Kubernetes by running the following commands:
Postgres database installed! You can check its status with the following command:
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 [email protected].
First, export your license key as a variable named
And now deploy RStudio Connect into Kubernetes by running the following commands:
Once done, you can use this command to check the status of RStudio Connect:
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:
Next, port-forward port 3939 on
localhost to port 3939 of the running ReplicaSet:
You should see similar output in the console:
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
Removing the Deployment
To stop and remove the existing deployment, run the followings commands:
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.