How to Deploy RStudio (Posit) Connect into Local Kubernetes Cluster

Reading time:
time
min

RStudio (Posit) 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 <code>k3d</code>, 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. <blockquote>Looking for alternative ways to share R Shiny apps? <a href="https://appsilon.com/how-to-share-r-shiny-apps/" target="_blank" rel="noopener">Try GitHub, ShinyApps.io, and ShinyServer - All explained in our detailed guide</a>.</blockquote> Table of contents: <ul><li><a href="#prerequisites">Prerequisites to Deploying RStudio Connect to Local Kubernetes Cluster</a></li><li><a href="#local-kubernetes-cluster">How to Create Local Kubernetes Cluster with k3d</a></li><li><a href="#dependencies">Install Dependencies with Helm</a></li><li><a href="#postgres">Install the Postgres Database</a></li><li><a href="#rstudio-connect">How to Install RStudio Connect to Local Kubernetes Cluster</a></li><li><a href="#removing-deployment">Removing the Deployment</a></li><li><a href="#summary">Summary of Deploying RStudio Connect to Local Kubernetes Cluster</a></li></ul> <hr /> <h2 id="prerequisites">Prerequisites to Deploying RStudio (Posit) Connect to Local Kubernetes Cluster</h2> 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: <ul><li><a href="https://brew.sh/" target="_blank" rel="noopener">Homebrew</a> package manager</li><li>Kubernetes cluster</li><li>Valid RStudio Connect license</li></ul> Once you install Homebrew, you should also install the rest of the command-line dependencies by running: <script src="https://gist.github.com/darioappsilon/9b24a87262958b68df767382fd9f4dab.js"></script> Before you can deploy resources, you'll need to have a working Kubernetes cluster. We suggest using <code>k3d</code> project for development purposes, as it allows you to create single and multi-node Kubernetes cluster in Docker. If you're wondering, <code>k3d</code> is a highly available, certified Kubernetes distribution. Up next, we'll use <code>k3d</code> to prepare a local Kubernetes cluster. <h2 id="local-kubernetes-cluster">How to Create Local Kubernetes Cluster with k3d</h2> To start, install the current latest release of <code>k3d</code> binary by running the following shell command: <script src="https://gist.github.com/darioappsilon/00d38b20a0304f603e4315dff082d4b1.js"></script> You can verify the binary was installed successfully by running the following command: <script src="https://gist.github.com/darioappsilon/a2842b57ee3e6974cb0e1051d6f7e9fa.js"></script> If you did everything correctly, you'll see something similar as the output: <img class="wp-image-12810 size-full" title="Image 1 - k3d version output" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01e491acc439bc2594dc7_Screenshot-99.webp" alt="" width="1532" height="966" /> Image 1 - k3d version output The next step is to create a cluster named <code>rstudio</code> with a single server node: <script src="https://gist.github.com/darioappsilon/599aee76cbdd7af41d39b0b3cf5947f5.js"></script> From here, use this shell command to verify the cluster has been created: <script src="https://gist.github.com/darioappsilon/3267b03e84750162599835880b4a9e1c.js"></script> <img class="size-full wp-image-12812" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01e4b099015d6184df471_Screenshot-100.webp" alt="" width="1532" height="966" /> 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. <h2 id="dependencies">Install Dependencies with Helm</h2> 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 <b>Helm chart.</b> 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 <a href="https://github.com/rstudio/helm" target="_blank" rel="noopener">available</a> for public usage. Before deploying Helm charts, we need to ensure respective repositories are configured: <script src="https://gist.github.com/darioappsilon/f81d3dd1c929be8fb3717e3b4aa1cdb4.js"></script> You should see the following messages while running the above commands: <img class="size-full wp-image-12814" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01e4bee976c4ea990fa15_Screenshot-101.webp" alt="" width="1532" height="966" /> 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. <h2 id="postgres">Install the Postgres Database</h2> At the very minimum, the PostgreSQL Helm chart requires a database password. You can set one from the terminal easily: <script src="https://gist.github.com/darioappsilon/2fcdc6946bc71782d091cb298c5b1dae.js"></script> Next, deploy the database into Kubernetes by running the following commands: <script src="https://gist.github.com/darioappsilon/c7958eab00cf295e50d4cd441ced678f.js"></script> <img class="size-full wp-image-12816" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01e4ca63ce91a2406cfcd_Screenshot-102.webp" alt="" width="1532" height="966" /> Image 4 - Installing Postgres database Postgres database installed! You can check its status with the following command: <script src="https://gist.github.com/darioappsilon/5248227ba778ee17afa0ccda623fc9c0.js"></script> <img class="size-full wp-image-12818" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01e4d6c7e8f927609e332_Screenshot-103.webp" alt="" width="1532" height="966" /> Image 5 - Status of the PostgreSQL database We now have everything needed to finally install RStudio Connect. <h2 id="rstudio-connect">How to Install RStudio (Posit) Connect to Local Kubernetes Cluster</h2> You will need a working license key before attempting to deploy RStudio Connect into Kubernetes. If you do not have one, contact us at <a href="mailto:sales@appsilon.com">sales@appsilon.com</a>. First, export your license key as a variable named <code>RSC_LICENSE</code>: <script src="https://gist.github.com/darioappsilon/4f038433254cd57905c6f894febd617a.js"></script> And now deploy RStudio Connect into Kubernetes by running the following commands: <script src="https://gist.github.com/darioappsilon/d0dc4ba0c0bbc42bc6325f37e3186d6b.js"></script> <img class="size-full wp-image-12820" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01e4e965eadfe41483d6f_Screenshot-104.webp" alt="" width="1532" height="966" /> Image 6 - Installing RStudio Connect Once done, you can use this command to check the status of RStudio Connect: <script src="https://gist.github.com/darioappsilon/5f07eb70959924c6a7bba702cd56db7f.js"></script> <img class="size-full wp-image-12822" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01e50e7ac33b972b605c4_Screenshot-105.webp" alt="" width="1532" height="966" /> 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. <code>kubectl port-forward</code> command allows using resource names, such as a ReplicaSet, to select a matching ReplicaSet to port forward to. First, grab the ReplicaSet name: <script src="https://gist.github.com/darioappsilon/9c21a91e98e1c212c4c598abd3a413b7.js"></script> <img class="size-full wp-image-12824" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01e52b28625c3f1667ab3_Screenshot-106.webp" alt="" width="1532" height="966" /> Image 8 - Status of the RStudio Connect ReplicaSet Next, port-forward port 3939 on <code>localhost</code> to port 3939 of the running ReplicaSet: <script src="https://gist.github.com/darioappsilon/583fc650dd4ebbb8117409ffba60c59a.js"></script> You should see similar output in the console: <img class="size-full wp-image-12826" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01e5318567286fa42859a_Screenshot-107.webp" alt="" width="1532" height="966" /> 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 <code>http://localhost:3939</code>. <h2 id="removing-deployment">Removing the Deployment</h2> To stop and remove the existing deployment, run the followings commands: <script src="https://gist.github.com/darioappsilon/047efc9ab537649a4a130263c1785deb.js"></script> RStudio Connect chart will automatically deregister your license key. <hr /> <h2 id="summary">Summary of RStudio Connect in a Local Kubernetes Cluster</h2> 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! <blockquote>Want to deploy Python Streamlit apps to RStudio Connect? <a href="https://appsilon.com/streamlit-tutorial-rstudio-connect/" target="_blank" rel="noopener">This guide will teach you everything you need to know</a>.</blockquote>

Have questions or insights?

Engage with experts, share ideas and take your data journey to the next level!
Explore Possibilities

Share Your Data Goals with Us

From advanced analytics to platform development and pharma consulting, we craft solutions tailored to your needs.

Talk to our Experts
r
rstudio connect