From 46db51d57e8923eaae4c1249d6232470184bf816 Mon Sep 17 00:00:00 2001 From: macolso Date: Thu, 7 Nov 2024 19:55:42 -0800 Subject: [PATCH 1/3] first draft of selectivey deployment tutorial Signed-off-by: macolso --- content/en/docs/topics/packaging.md | 1 + .../en/docs/topics/selective-deployments.md | 123 ++++++++++++++++++ package-lock.json | 27 ++-- 3 files changed, 140 insertions(+), 11 deletions(-) create mode 100644 content/en/docs/topics/selective-deployments.md diff --git a/content/en/docs/topics/packaging.md b/content/en/docs/topics/packaging.md index b4d38ec..5e3cc6d 100644 --- a/content/en/docs/topics/packaging.md +++ b/content/en/docs/topics/packaging.md @@ -100,6 +100,7 @@ spin kube deploy --from ttl.sh/hello-spin:24h spinapp.core.spinkube.dev/hello-spin created ``` +> You can deploy a subset of components in your Spin Application using [Selective Deployments](./selective-deployments.md). ## Scaffolding Spin Apps diff --git a/content/en/docs/topics/selective-deployments.md b/content/en/docs/topics/selective-deployments.md new file mode 100644 index 0000000..f226757 --- /dev/null +++ b/content/en/docs/topics/selective-deployments.md @@ -0,0 +1,123 @@ +--- +title: Selective Deployments in Spin +description: Learn how to deploy a subset of components from your SpinApp using Selective Deployments. +date: 2024-11-12 +categories: [Spin Operator] +tags: [Tutorials] +weight: 10 +aliases: +- /docs/spin-operator/tutorials/selective-deployments +--- + +This article explains how to selectively deploy a subset of components from your Spin App using Selective Deployments. You will learn how to: + +- Scaffold a Specific Component from a Spin Application into a Custom Resource +- Run a Selective Deployment + +Selective Deployments allow you to control which components within a Spin app are active for a specific instance of the app. With Component Selectors, Spin and SpinKube can declare at runtime which components should be activated, letting you deploy a single, versioned artifact while choosing which parts to enable at startup. This approach separates developer goals (building a well-architected app) from operational needs (optimizing for specific infrastructure). + +## Prerequisites + +For this tutorial, you’ll need: + +- [kubectl](https://kubernetes.io/docs/tasks/tools/) - the Kubernetes CLI +- Kubernetes cluster with the Spin Operator v0.4 and Containerd Spin Shim v0.16 - follow the [Quickstart](../install/quickstart.md) if needed +- `spin kube` plugin - follow [Installing the `spin kube` plugin](../install/spin-kube-plugin.md) if needed + +## Scaffold a Specific Component from a Spin Application into a Custom Resource + +We’ll use a sample application called "Salutations," which demonstrates greetings via two components, each responding to a unique HTTP route. If we take a look at the [application manifest](https://github.com/spinkube/spin-operator/blob/main/apps/salutations/spin.toml), we’ll see that this Spin application is comprised of two components: + +- `Hello` component triggered by the `/hi` route +- `Goodbye` component triggered by the `/bye` route + +```yaml +spin_manifest_version = 2 + +[application] +name = "salutations" +version = "0.1.0" +authors = ["Kate Goldenring "] +description = "An app that gives salutations" + +[[trigger.http]] +route = "/hi" +component = "hello" + +[component.hello] +source = "../hello-world/main.wasm" +allowed_outbound_hosts = [] +[component.hello.build] +command = "cd ../hello-world && tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" +watch = ["**/*.go", "go.mod"] + +[[trigger.http]] +route = "/bye" +component = "goodbye" + +[component.goodbye] +source = "main.wasm" +allowed_outbound_hosts = [] +[component.goodbye.build] +command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" +watch = ["**/*.go", "go.mod"] +``` + +With Selective Deployments, you can choose to deploy only specific components without modifying the source code. For this example, we’ll deploy just the `hello` component. + +> Note that if you had an Spin application with more than two components, you could choose to deploy multiple components selectively. + +To Selectively Deploy, we first need to turn our application into a SpinApp Custom Resource with the `spin kube scaffold` command, using the optional `--component` field to specify which component we’d like to deploy: + +```bash +spin kube scaffold --from ghcr.io/spinkube/spin-operator/salutations:20241105-223428-g4da3171 --component hello --replicas 1 --out spinapp.yaml +``` + +Now if we take a look at our `spinapp.yaml`, we should see that only the hello component will be deployed via Selective Deployments: + +```yaml +apiVersion: core.spinkube.dev/v1alpha1 +kind: SpinApp +metadata: + name: salutations +spec: + ## TODO update image + image: "ghcr.io/spinkube/spin-operator/salutations:20241105-223428-g4da3171" + executor: containerd-shim-spin + replicas: 1 + components: + - hello +``` + +## Run a Selective Deployment + +Now you can deploy your app using kubectl apply -f as you normally would: + +```bash +# Deploy the spinapp.yaml using kubectl +kubectl apply -f spinapp.yaml +# TODO make sure that's the right domain +spinapp.core.spinkube.dev/salutations created +``` + +Optionally, let’s test that only our hello component is running. We’ll use port-forwarding to access our service locally: + +```bash +kubectl port-forward svc/salutations 8083:80 +``` + +Now let’s call the `/hi` route. If the hello component is running correctly, we should see a response of "hello": + +```bash +curl localhost:8083/hi +# TODO include output +``` + +Next, let’s try the `/bye` route. This should fail, confirming that only the hello component was deployed: + +```bash +curl localhost:8083/bye +# TODO include output +``` + +And there you have it! A subset of your Spin application deployed on SpinKube with no modifications to your source code. This approach lets you quickly deploy only the components you need, which can improve efficiency in environments where only specific services are required. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 461233f..441e3e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -290,12 +290,13 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, + "license": "MIT", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -853,10 +854,11 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, + "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -1231,6 +1233,7 @@ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.12.0" } @@ -1423,12 +1426,13 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, + "license": "MIT", "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -2256,6 +2260,7 @@ "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "dev": true, + "license": "MIT", "dependencies": { "is-number": "^7.0.0" }, From 7485a79185ddc7b3aef04e6dfc2e854f40a88683 Mon Sep 17 00:00:00 2001 From: MacKenzie Olson Date: Fri, 8 Nov 2024 14:02:26 -0800 Subject: [PATCH 2/3] Applying language updates, including version numbers, and other suggestions from Kate Co-authored-by: Kate Goldenring Signed-off-by: MacKenzie Olson --- content/en/docs/topics/selective-deployments.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/content/en/docs/topics/selective-deployments.md b/content/en/docs/topics/selective-deployments.md index f226757..5b2786f 100644 --- a/content/en/docs/topics/selective-deployments.md +++ b/content/en/docs/topics/selective-deployments.md @@ -21,12 +21,12 @@ Selective Deployments allow you to control which components within a Spin app ar For this tutorial, you’ll need: - [kubectl](https://kubernetes.io/docs/tasks/tools/) - the Kubernetes CLI -- Kubernetes cluster with the Spin Operator v0.4 and Containerd Spin Shim v0.16 - follow the [Quickstart](../install/quickstart.md) if needed -- `spin kube` plugin - follow [Installing the `spin kube` plugin](../install/spin-kube-plugin.md) if needed +- Kubernetes cluster with the Spin Operator v0.4 and Containerd Spin Shim v0.17 - follow the [Quickstart](../install/quickstart.md) if needed +- `spin kube` plugin v0.3 - follow [Installing the `spin kube` plugin](../install/spin-kube-plugin.md) if needed ## Scaffold a Specific Component from a Spin Application into a Custom Resource -We’ll use a sample application called "Salutations," which demonstrates greetings via two components, each responding to a unique HTTP route. If we take a look at the [application manifest](https://github.com/spinkube/spin-operator/blob/main/apps/salutations/spin.toml), we’ll see that this Spin application is comprised of two components: +We’ll use a sample application called "Salutations", which demonstrates greetings via two components, each responding to a unique HTTP route. If we take a look at the [application manifest](https://github.com/spinkube/spin-operator/blob/main/apps/salutations/spin.toml), we’ll see that this Spin application is comprised of two components: - `Hello` component triggered by the `/hi` route - `Goodbye` component triggered by the `/bye` route @@ -91,7 +91,7 @@ spec: ## Run a Selective Deployment -Now you can deploy your app using kubectl apply -f as you normally would: +Now you can deploy your app using `kubectl` as you normally would: ```bash # Deploy the spinapp.yaml using kubectl @@ -100,7 +100,7 @@ kubectl apply -f spinapp.yaml spinapp.core.spinkube.dev/salutations created ``` -Optionally, let’s test that only our hello component is running. We’ll use port-forwarding to access our service locally: +We can test that only our `hello` component is running by port-forwarding its service. ```bash kubectl port-forward svc/salutations 8083:80 @@ -120,4 +120,4 @@ curl localhost:8083/bye # TODO include output ``` -And there you have it! A subset of your Spin application deployed on SpinKube with no modifications to your source code. This approach lets you quickly deploy only the components you need, which can improve efficiency in environments where only specific services are required. \ No newline at end of file +And there you have it! You selectively deployed a subset of your Spin application to SpinKube with no modifications to your source code. This approach lets you easily deploy only the components you need, which can improve efficiency in environments where only specific services are required. \ No newline at end of file From 94cc94ca1bb1e803d0a264fd35aa03fb8195f05d Mon Sep 17 00:00:00 2001 From: macolso Date: Sun, 10 Nov 2024 12:57:46 -0800 Subject: [PATCH 3/3] added curl output Signed-off-by: macolso --- content/en/docs/topics/selective-deployments.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/content/en/docs/topics/selective-deployments.md b/content/en/docs/topics/selective-deployments.md index 5b2786f..972dfcd 100644 --- a/content/en/docs/topics/selective-deployments.md +++ b/content/en/docs/topics/selective-deployments.md @@ -81,7 +81,6 @@ kind: SpinApp metadata: name: salutations spec: - ## TODO update image image: "ghcr.io/spinkube/spin-operator/salutations:20241105-223428-g4da3171" executor: containerd-shim-spin replicas: 1 @@ -96,7 +95,6 @@ Now you can deploy your app using `kubectl` as you normally would: ```bash # Deploy the spinapp.yaml using kubectl kubectl apply -f spinapp.yaml -# TODO make sure that's the right domain spinapp.core.spinkube.dev/salutations created ``` @@ -106,18 +104,22 @@ We can test that only our `hello` component is running by port-forwarding its se kubectl port-forward svc/salutations 8083:80 ``` -Now let’s call the `/hi` route. If the hello component is running correctly, we should see a response of "hello": +Now let’s call the `/hi` route in a seperate terminal: ```bash curl localhost:8083/hi -# TODO include output ``` -Next, let’s try the `/bye` route. This should fail, confirming that only the hello component was deployed: +If the hello component is running correctly, we should see a response of "Hello Fermyon!": + +```bash +Hello Fermyon! +``` + +Next, let’s try the `/bye` route. This should return nothing, confirming that only the `hello` component was deployed: ```bash curl localhost:8083/bye -# TODO include output ``` -And there you have it! You selectively deployed a subset of your Spin application to SpinKube with no modifications to your source code. This approach lets you easily deploy only the components you need, which can improve efficiency in environments where only specific services are required. \ No newline at end of file +There you have it! You selectively deployed a subset of your Spin application to SpinKube with no modifications to your source code. This approach lets you easily deploy only the components you need, which can improve efficiency in environments where only specific services are required. \ No newline at end of file