|
| 1 | +--- |
| 2 | +title: Installing on Microk8s |
| 3 | +description: This guide walks you through the process of installing SpinKube using [Microk8s](https://microk8s.io/). |
| 4 | +date: 2024-06-19 |
| 5 | +tags: [Installation] |
| 6 | +--- |
| 7 | + |
| 8 | +This guide walks through the process of installing and configuring Microk8s and SpinKube. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +This guide assumes you are running Ubuntu 24.04, and that you have Snap enabled (which is the default). |
| 13 | + |
| 14 | +> The testing platform for this installation was an Akamai Edge Linode running 4G of memory and 2 cores. |
| 15 | +
|
| 16 | +## Installing Spin |
| 17 | +You will need to [install Spin](https://developer.fermyon.com/spin/quickstart). The easiest way is to just use the following one-liner to get the latest version of Spin: |
| 18 | + |
| 19 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 20 | +$ curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash |
| 21 | +``` |
| 22 | + |
| 23 | +Typically you will then want to move `spin` to `/usr/local/bin` or somewhere else on your `$PATH`: |
| 24 | + |
| 25 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 26 | +$ sudo mv spin /usr/local/bin/spin |
| 27 | +``` |
| 28 | + |
| 29 | +You can test that it's on your `$PATH` with `which spin`. If this returns blank, you will need to adjust your `$PATH` variable or put Spin somewhere that is already on `$PATH`. |
| 30 | + |
| 31 | +## A Script To Do This |
| 32 | + |
| 33 | +If you would rather work with a shell script, you may find [this Gist](https://gist.github.com/kate-goldenring/47950ccb30be2fa0180e276e82ac3593#file-spinkube-on-microk8s-sh) a great place to start. It installs Microk8s and SpinKube, and configures both. |
| 34 | + |
| 35 | +## Installing Microk8s on Ubuntu |
| 36 | + |
| 37 | +Use `snap` to install microk8s: |
| 38 | + |
| 39 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 40 | +$ sudo snap install microk8s --classic |
| 41 | +``` |
| 42 | + |
| 43 | +This will install Microk8s and start it. You may want to read the [official installation instructions](https://microk8s.io/docs/getting-started) before proceeding. Wait for a moment or two, and then ensure Microk8s is running with the `microk8s status` command. |
| 44 | + |
| 45 | +Next, enable the TLS certificate manager: |
| 46 | + |
| 47 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 48 | +$ microk8s enable cert-manager |
| 49 | +``` |
| 50 | + |
| 51 | +Now we’re ready to install the SpinKube environment for running Spin applications. |
| 52 | + |
| 53 | +### Installing SpinKube |
| 54 | + |
| 55 | +SpinKube provides the entire toolkit for running Spin serverless apps. You may want to familiarize yourself with the [SpinKube quickstart](https://www.spinkube.dev/docs/install/quickstart/) guide before proceeding. |
| 56 | + |
| 57 | +First, we need to apply a runtime class and a CRD for SpinKube: |
| 58 | + |
| 59 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 60 | +$ microk8s kubectl apply -f https://github.com/spinkube/spin-operator/releases/download/v0.2.0/spin-operator.runtime-class.yaml |
| 61 | +$ microk8s kubectl apply -f https://github.com/spinkube/spin-operator/releases/download/v0.2.0/spin-operator.crds.yaml |
| 62 | +``` |
| 63 | + |
| 64 | +Both of these should apply immediately. |
| 65 | + |
| 66 | +We then need to install KWasm because it is not yet included with Microk8s: |
| 67 | + |
| 68 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 69 | +$ microk8s helm repo add kwasm http://kwasm.sh/kwasm-operator/ |
| 70 | +$ microk8s helm install kwasm-operator kwasm/kwasm-operator --namespace kwasm --create-namespace --set kwasmOperator.installerImage=ghcr.io/spinkube/containerd-shim-spin/node-installer:v0.15.1 |
| 71 | +$ microk8s kubectl annotate node --all kwasm.sh/kwasm-node=true |
| 72 | + |
| 73 | +``` |
| 74 | + |
| 75 | +> The last line above tells Microk8s that all nodes on the cluster (which is just one node in this case) can run Spin applications. |
| 76 | +
|
| 77 | +Next, we need to install SpinKube’s operator using Helm (which is included with Microk8s). |
| 78 | + |
| 79 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 80 | +$ microk8s helm install spin-operator --namespace spin-operator --create-namespace --version 0.2.0 --wait oci://ghcr.io/spinkube/charts/spin-operator |
| 81 | + |
| 82 | +``` |
| 83 | + |
| 84 | +Now we have the main operator installed. There is just one more step. We need to install the shim executor, which is a special CRD that allows us to use multiple executors for WebAssembly. |
| 85 | + |
| 86 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 87 | +$ microk8s kubectl apply -f https://github.com/spinkube/spin-operator/releases/download/v0.2.0/spin-operator.shim-executor.yaml |
| 88 | + |
| 89 | +``` |
| 90 | + |
| 91 | +Now SpinKube is installed! |
| 92 | + |
| 93 | +### Running an App in SpinKube |
| 94 | + |
| 95 | +Next, we can run a simple Spin application inside of Microk8s. |
| 96 | + |
| 97 | +While we could write regular deployments or pod specifications, the easiest way to deploy a Spin app is by creating a simple `SpinApp` resource. Let's use the simple example from SpinKube: |
| 98 | + |
| 99 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 100 | +$ microk8s kubectl apply -f https://raw.githubusercontent.com/spinkube/spin-operator/main/config/samples/simple.yaml |
| 101 | +``` |
| 102 | +The above installs a simple `SpinApp` YAML that looks like this: |
| 103 | + |
| 104 | +```yaml |
| 105 | +apiVersion: core.spinoperator.dev/v1alpha1 |
| 106 | +kind: SpinApp |
| 107 | +metadata: |
| 108 | + name: simple-spinapp |
| 109 | +spec: |
| 110 | + image: "ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.0" |
| 111 | + replicas: 1 |
| 112 | + executor: containerd-shim-spin |
| 113 | +``` |
| 114 | +
|
| 115 | +You can read up on the definition [in the documentation](https://www.spinkube.dev/docs/reference/spin-app/). |
| 116 | +
|
| 117 | +It may take a moment or two to get started, but you should be able to see the app with `microk8s kubectl get pods`. |
| 118 | + |
| 119 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 120 | +$ microk8s kubectl get po |
| 121 | +NAME READY STATUS RESTARTS AGE |
| 122 | +simple-spinapp-5c7b66f576-9v9fd 1/1 Running 0 45m |
| 123 | +``` |
| 124 | + |
| 125 | +### Troubleshooting |
| 126 | + |
| 127 | +If `STATUS` gets stuck in `ContainerCreating`, it is possible that KWasm did not install correctly. Try doing a `microk8s stop`, waiting a few minutes, and then running `microk8s start`. You can also try the command: |
| 128 | + |
| 129 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 130 | +$ microk8s kubectl logs -n kwasm -l app.kubernetes.io/name=kwasm-operator |
| 131 | +``` |
| 132 | + |
| 133 | +### Testing the Spin App |
| 134 | + |
| 135 | +The easiest way to test our Spin app is to port forward from the Spin app to the outside host: |
| 136 | + |
| 137 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 138 | +$ microk8s kubectl port-forward services/simple-spinapp 8080:80 |
| 139 | +``` |
| 140 | + |
| 141 | +You can then run `curl localhost:8080` |
| 142 | + |
| 143 | +```console { data-plausible="copy-quick-deploy-sample" } |
| 144 | +$ curl localhost:8080 |
| 145 | +Hello World! |
| 146 | +``` |
| 147 | + |
| 148 | +### Where to go from here |
| 149 | + |
| 150 | +So far, we installed Microk8s, SpinKube, and a single Spin app. To have a more production-ready version, you might want to: |
| 151 | + |
| 152 | +- Generate TLS certificates and attach them to your Spin app to add HTTPS support. If you are using an ingress controller (see below), [here is the documentation for TLS config](https://kubernetes.github.io/ingress-nginx/user-guide/tls/). |
| 153 | +- Configure a [cluster ingress](https://microk8s.io/docs/addon-ingress) |
| 154 | +- Set up another Linode Edge instsance and create a [two-node Microk8s cluster](https://microk8s.io/docs/clustering). |
| 155 | + |
| 156 | +### Bonus: Configuring Microk8s ingress |
| 157 | + |
| 158 | +Microk8s includes an NGINX-based ingress controller that works great with Spin applications. |
| 159 | + |
| 160 | +Enable the ingress controller: `microk8s enable ingress` |
| 161 | + |
| 162 | +Now we can create an ingress that routes our traffic to the `simple-spinapp` app. Create the file `ingress.yaml` with the following content. Note that the [`service.name`](http://service.name) is the name of our Spin app. |
| 163 | + |
| 164 | +```yaml |
| 165 | +apiVersion: networking.k8s.io/v1 |
| 166 | +kind: Ingress |
| 167 | +metadata: |
| 168 | + name: http-ingress |
| 169 | +spec: |
| 170 | + rules: |
| 171 | + - http: |
| 172 | + paths: |
| 173 | + - path: / |
| 174 | + pathType: Prefix |
| 175 | + backend: |
| 176 | + service: |
| 177 | + name: simple-spinapp |
| 178 | + port: |
| 179 | + number: 80 |
| 180 | +``` |
| 181 | + |
| 182 | +Install the above with `microk8s kubectl -f ingress.yaml`. After a moment or two, you should be able to run `curl [localhost](http://localhost)` and see `Hello World!`. |
| 183 | + |
| 184 | +## Conclusion |
| 185 | + |
| 186 | +In this guide we've installed Spin, Microk8s, and SpinKube and then run a Spin application. |
| 187 | + |
| 188 | +To learn more about the many things you can do with Spin apps, go to [the Spin developer docs](https://developer.fermyon.com/spin). You can also look at a variety of examples at [Spin Up Hub](https://developer.fermyon.com/hub). |
| 189 | + |
| 190 | +Or to try out different Kubernetes configurations, check out [other installation guides](https://www.spinkube.dev/docs/install/). |
0 commit comments