Packaging and Deploying Spin Apps using App Platform

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

Intro placeholder

Workflow Diagram

diagram_placeholder

Concepts

  • Wasm

  • Spin

  • SpinKube

Infrastructure

  • App Platform

Apps

  • Argo CD

  • Harbor

  • Ingress-NGINX-Platform

Workloads

  • Kwasm-Operator

  • Spin-Operator

  • Spin-Shim-Executor. This adds the SpinAppExecutor CRD (custom resource definition) to the cluster, which is used by the Spin Operator to determine which executor (e.g. the Wasm compatibility layer on the nodes) should be used in running a SpinApp.

Services

Before You Begin

  1. Create a Cloud Manager account, if you do not already have one.

  2. Self-enroll in the Akamai App Platform Beta. To register for the beta, visit the Betas page in the Cloud Manager and click the Sign Up button next to the Akamai App Platform Beta.

  3. Install the Docker Engine on your workstation.

  4. Install Tinygo on your workstation. The demo used in this tutorial requires version 0.34.0. Run the following command to check your installed version:

    Your workstation
    tinygo version
  5. Install the Spin CLI on your workstation.

  6. Install the latest Go release on your workstation.

Deploy and Prepare App Platform

  1. Follow these sections in the Getting Started with the Akamai App Platform guide to provision a App Platform-enabled Kubernetes cluster and to log into the App Platform console:

    1. Create an LKE cluster

    2. Access and download your kubeconfig

    3. Obtain the initial access credentials and sign in

  2. Familiarize yourself with the App Platform console UI. In particular, the top navigation features two dropdown menus:

    1. The View toggle allows you to switch between the platform view and the team view, which affects which functions of App Platform are displayed in the left-side navigation. Some functions are displayed in both of these views, while others are available only in the platform view or only in the team view. Review the overview documentation of these views for more information.

    2. The Team toggle allows you to switch between teams. Teams are isolated tenants in App Platform, and a namespace for each team (named team-TEAM_NAME) is created on the cluster. Prior to creating a workload or other resources on the cluster, select the team (in the top navigation dropdown menu) that the resources should be created for. That team’s namespace is then set for those resources. See the Teams documentation for more information.

  3. Enable the Harbor app for App Platform. Harbor is a registry that is used to store containers for your cluster.

    1. Select the platform option from the View menu in the top navigation.

    2. Click the Apps item in the left-side navigation.

    3. The Harbor app appears as disabled box in the grid of different apps. Hover over this box and click on the power-on icon to enable the app. You are asked if you want to provision object storage for your cluster. This is not required for Harbor to function in a demo environment.

  4. Create a new Team named demo:

    1. Select the platform option from the View menu in the top navigation.

    2. Click the Teams item in the left-side navigation.

    3. Click the CREATE TEAM button.

    4. Enter demo into the Name field. Use the default values for all other options in the form.

    5. Click the SUBMIT button at the end of the form.

  5. Install the kwasm-operator Helm chart:

    1. Select the team option from the View menu in the top navigation. Select the admin option from the Team menu.

    2. Click the Workloads item in the left-side navigation.

    3. Click the CREATE WORKLOAD button.

    4. Select the kwasm-operator Helm chart from the catalog.

    5. Click the Values tab.

    6. Enter kwasm-operator in the Name field.

    7. Enter kwasm in the namespace field.

    8. Enable the Create a new namespace toggle.

    9. Click the SUBMIT button at the end of the form.

  6. Use kwasm-operator to enable Wasm support on the cluster nodes:

    1. Select the team option from the View menu in the top navigation. Select the admin option from the Team menu.

    2. Click the Shell item in the left-side navigation. A shell session UI appears at the bottom of the console.

    3. In the console shell, run:

    App Platform console shell (admin team selected)
    kubectl annotate node --all kwasm.sh/kwasm-node=true

    Output resembling the following should appear:

    node/lke377780-583222-38daa4ab0000 annotated
    node/lke377780-583222-587143350000 annotated
    node/lke377780-583222-5ac1f8160000 annotated

    The kwasm-operator installs the required Wasm compatibility layer dependencies on the annotated nodes.

  7. Install the spin-operator Helm chart:

    1. Select the team option from the View menu in the top navigation. Select the admin option from the Team menu.

    2. Click the Workloads item in the left-side navigation.

    3. Click the CREATE WORKLOAD button.

    4. Select the spin-operator Helm chart from the catalog.

    5. Click the Values tab.

    6. Enter spin-operator in the Name field.

    7. Enter spin-operator in the namespace field.

    8. Enable the Create a new namespace toggle.

    9. Click the SUBMIT button at the end of the form.

  8. Install the spin-shim-executor Helm chart. This chart should be installed for every team that deploys Spin Apps.

    1. Select the team option from the View menu in the top navigation. Select the demo option from the Team menu.

    2. Click the Workloads item in the left-side navigation.

    3. Click the CREATE WORKLOAD button.

    4. Select the spin-shim-executor Helm chart from the catalog.

    5. Click the Values tab.

    6. Enter spin-shim-executor-demo in the Name field.

    7. Click the SUBMIT button at the end of the form.

Your App Platform cluster now has the dependencies required to run Spin apps.

Create a New Spin App

This section shows how to create a demo Spin app using the Spin CLI. This demo app responds to HTTP requests with a “hello, world”-style response.

Spin apps are packaged and distributed as OCI artifacts. By leveraging OCI artifacts, Spin apps can be distributed using any registry that implements the Open Container Initiative Distribution Specification (a.k.a. “OCI Distribution Spec”). In particular, the Spin app created in this section is pushed up to the Harbor registry in the App Platform cluster.

The commands in this section should be run on your workstation, not in the App Platform console shell.

  1. Spin provides templates that can be used to create new Spin apps. Run the spin templates upgrade command to ensure that the templates available to you are compatible with your version of Spin:

    Your workstation
    spin templates upgrade --branch main --repo https://github.com/spinframework/spin
  2. Create a new Spin App using the http-go template. Then, navigate into the hello-spin directory:

    Your workstation
    spin new --accept-defaults -t http-go hello-spin
    cd hello-spin
  3. The Spin CLI created all necessary files inside the hello-spin directory. The implementation of the app is in main.go:

    File: hello-spin/main.go
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    
    package main
    
    import (
        "fmt"
        "net/http"
    
        spinhttp "github.com/fermyon/spin/sdk/go/v2/http"
    )
    
    func init() {
        spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) {
            w.Header().Set("Content-Type", "text/plain")
            fmt.Fprintln(w, "Hello Fermyon!")
        })
    }
    
    func main() {}

    This implementation responds to any incoming HTTP request. It returns an HTTP response with a status code of 200 (Ok) and Hello Fermyon! as the response body.

  4. The Spin CLI simplifies packaging and distribution of Spin Apps. It provides the spin registry push command to build the app and push it to a container registry. Before you can package and push the app, you first need to login into the private registry. Follow these steps to log into your Harbor registry from your workstation:

    1. Select the team option from the View menu in the top navigation. Select the demo option from the Team menu.

    2. Click Download DOCKERCFG in the left-side navigation. A file named docker-team-demo.json is downloaded to your local downloads directory.

    3. If you have an existing .docker/ folder on your workstation (from previously authenticating with a container registry), back it up before proceeding:

      Your workstation
      cp -r $HOME/.docker $HOME/.docker-backup
    4. Move and rename the docker-team-demo.json file to config.json, and place it inside a .docker/ folder under your home directory:

      Your workstation
      mkdir -p $HOME/.docker/
      mv $HOME/Downloads/docker-team-demo.json $HOME/.docker/config.json
  5. Log in using the Docker CLI. Replace the hostname with the hostname of your Harbor registry. The hostname resembles harbor.lkeID_NUMBER.akamai-apl.net.

    Your workstation
    docker login HARBOR_REGISTRY_HOSTNAME

    There are a few ways to identify your Harbor registry hostname:

    • When viewing the App Platform console in your browser, the hostname for the console is displayed, which resembles console.lkeID_NUMBER.akamai-apl.net. Replace console with harbor to obtain the Harbor hostname.

    • When viewing the Harbor UI in your browser (by selecting it from the Apps item in the left-navigation, while in the platform View), the hostname is in the URL.

    After running the login command, output resembling the following appears:

    Authenticating with existing credentials... [Username: otomi-team-demo-push]
    
    i Info → To login with a different account, run 'docker logout' followed by 'docker login'
    
    
    Login Succeeded
  6. You can now package and distribute the hello-spin app. Run the following command:

    spin registry push --build HARBOR_REGISTRY_HOSTNAME/team-demo/hello-spin:v0.0.1
    

    The output should resemble:

    Building component hello-spin with `tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go`
    go: downloading github.com/fermyon/spin/sdk/go/v2 v2.2.0
    go: downloading github.com/julienschmidt/httprouter v1.3.0
    Finished building all Spin components
    Pushing app to the Registry...
    Pushed with digest sha256:b9594bedae63fc1f701372e4f95a8ac8ee9093405b29e0f16125dc23ad8d6b82
    
  7. To see the artifact you just pushed to Harbor:

    1. Select the platform option from the View menu in the top navigation. Select the admin option from the Team menu.

    2. Click Apps from the left-side navigation.

    3. Click the Harbor app. The Harbor UI is opened in a new tab.

    4. Click the team-demo project in the Projects table.

    5. Click the hello-spin repository.

Deploy the Spin App

There are a few different ways to deploy Spin Apps:

  • Use the Spin CLI and run spin kube deploy to directly deploy the app to your cluster

  • Use spin kube scaffold to generate a .yaml file and use kubectl apply -f to create the SpinApp resource

  • On App Platform, use the Spin App Helm chart.

This section shows how to use the Spin App Helm chart for App Platform. By using this method, you can take advantage of the continuous delivery and monitoring features of App Platform:

  1. Select the team option from the View menu in the top navigation. Select the admin option from the Team menu.

  2. Click the Workloads item in the left-side navigation.

  3. Click the CREATE WORKLOAD button.

  4. Select the Spin-App Helm chart from the catalog.

  5. Click the Values tab.

  6. Enter hello-spin in the Name field.

  7. Set the Auto image updater option to Semver

  8. In the Semver form:

    1. Enter team-demo/hello-spin in the imageRepository field

    2. Enter v0.x in the versionConstraint field.

  9. In the chart values file, location the image and replicaCount parameters. Update the values for these parameters as follows:

    File: Chart values file
    1
    2
    3
    4
    
    image:
      repository: HARBOR_REGISTRY_HOSTNAME/team-demo/hello-spin
      tag: v0.0.1
    replicaCount: 1
  10. Click the SUBMIT button at the end of the form.

  11. After a few minutes, the status of the Workload should be healthy. Click on the Application link for the workload to see it in Argo CD.

Connect to the Spin App

The Spin app is now deployed on the cluster, but it is not exposed to the internet. To expose the app, create an NGINX ingress service:

  1. Select the team option from the View menu in the top navigation. Select the admin option from the Team menu.

  2. Click the Services item in the left-side navigation.

  3. Click the CREATE SERVICE button.

  4. Enter ‘hello-spin in the Name field.

  5. In the Exposure form, select the External option.

  6. Click the SUBMIT button at the end of the form.

  7. In the list of services, click on the URL of the hello-spin app. The app’s response is displayed in your browser:

Update the Spin App

When you installed the Spin-App Helm chart, you set the Auto image updater to Semver. This automatically updates the deployed image to the most recent pushed version of a given tag. So, to update and re-deploy the Spin app, you just need to build a new version of it and push it to Harbor:

  1. On your workstation, update the contents of the main.go file:

    File: hello-spin/main.go
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    
    package main
    
    import (
        "fmt"
        "net/http"
    
        spinhttp "github.com/fermyon/spin/sdk/go/v2/http"
    )
    
    func init() {
        spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) {
            w.Header().Set("Content-Type", "text/plain")
            fmt.Fprintln(w, "Hello Fermyon. Welcome to Akamai App Platform!")
        })
    }
    
    func main() {}

    This updated code features a new response message (Hello Fermyon. Welcome to Akamai App Platform!).

  2. Build and push the app to Harbor:

    Your workstation
    spin registry push --build harbor.<domain-of-your-cluster>/team-demo/hello-spin:v0.0.2
  3. To check the update, refresh the app in your browser. You should now see the new response message.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.