Installing on Rancher Desktop

This tutorial shows how to integrate SpinKube and Rancher Desktop.

Rancher Desktop is an open-source application that provides all the essentials to work with containers and Kubernetes on your desktop.

Prerequisites

  • An operating system compatible with Rancher Desktop (Windows, macOS, or Linux).
  • Administrative or superuser access on your computer.

Step 1: Installing Rancher Desktop

  1. Download Rancher Desktop:
  2. Install Rancher Desktop:
    • Run the downloaded installer and follow the on-screen instructions to complete the installation.

Step 2: Configure Rancher Desktop

  • Open Rancher Desktop.
  • Navigate to the Preferences -> Kubernetes menu.
  • Ensure that the Enable Kubernetes is selected and that the Enable Traefik and Install Spin Operator Options are checked. Make sure to Apply your changes.

Rancher Desktop

  • Make sure to select rancher-desktop from the Kubernetes Contexts configuration in your toolbar.

Kubernetes contexts

  • Make sure that the Enable Wasm option is checked in the PreferencesContainer Engine section. Remember to always apply your changes.

Rancher preferences

  • Once your changes have been applied, go to the Cluster DashboardMore ResourcesCert Manager section and click on Certificates. You will see the spin-operator-serving-cert is ready.

Certificates tab

Step 3: Creating a Spin Application

  1. Open a terminal (Command Prompt, Terminal, or equivalent based on your OS).
  2. Create a new Spin application: This command creates a new Spin application using the http-js template, named hello-k3s.
  $ spin new -t http-js hello-k3s --accept-defaults
  $ cd hello-k3s
  1. We can edit the /src/index.js file and make the workload return a string “Hello from Rancher Desktop”:
export async function handleRequest(request) {
    return {
        status: 200,
        headers: {"content-type": "text/plain"},
        body: "Hello from Rancher Desktop" // <-- This changed
    }
}

Step 4: Deploying Your Application

  1. Push the application to a registry:
$ npm install
$ spin build
$ spin registry push ttl.sh/hello-k3s:0.1.0

Replace ttl.sh/hello-k3s:0.1.0 with your registry URL and tag.

  1. Scaffold Kubernetes resources:
$ spin kube scaffold --from ttl.sh/hello-k3s:0.1.0

apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
  name: hello-k3s
spec:
  image: "ttl.sh/hello-k3s:0.1.0"
  executor: containerd-shim-spin
  replicas: 2

This command prepares the necessary Kubernetes deployment configurations.

  1. Deploy the application to Kubernetes:
$ spin kube deploy --from ttl.sh/hello-k3s:0.1.0

If we click on the Rancher Desktop’s “Cluster Dashboard”, we can see hello-k3s:0.1.0 running inside the “Workloads” dropdown section:

Rancher Desktop Preferences Wasm

To access our app outside of the cluster, we can forward the port so that we access the application from our host machine:

$ kubectl port-forward svc/hello-k3s 8083:80

To test locally, we can make a request as follows:

$ curl localhost:8083
Hello from Rancher Desktop

The above curl command or a quick visit to your browser at localhost:8083 will return the “Hello from Rancher Desktop” message:

Hello from Rancher Desktop