-
Notifications
You must be signed in to change notification settings - Fork 23
Selective Deployments Tutorial #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
46db51d
first draft of selectivey deployment tutorial
macolso 7485a79
Applying language updates, including version numbers, and other sugge…
macolso b75a9a3
Merge branch 'spinkube:main' into selective-deployments
macolso 4aa90d3
Merge branch 'spinkube:main' into selective-deployments
macolso 94cc94c
added curl output
macolso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
macolso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## 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: | ||
macolso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - `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 <[email protected]>"] | ||
| 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" | ||
macolso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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: | ||
macolso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| # Deploy the spinapp.yaml using kubectl | ||
| kubectl apply -f spinapp.yaml | ||
| # TODO make sure that's the right domain | ||
macolso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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: | ||
macolso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```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. | ||
macolso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.