From f7d3ddef5febbb3c9b0dd63d8683e40ce5c340b8 Mon Sep 17 00:00:00 2001 From: Lucas Fontes Date: Mon, 22 Jul 2024 15:43:50 -0300 Subject: [PATCH] chore: Update Example Setup (#70) --------- Signed-off-by: Lucas Fontes Signed-off-by: Lucas Fontes Co-authored-by: Joonas Bergius --- README.md | 10 +- examples/full-config/wasmcloud-annotated.yaml | 92 +++++++++++++++++++ examples/quickstart/README.md | 87 ++++++++++++++++++ .../quickstart/hello-world-application.yaml | 45 +++++++++ examples/quickstart/nats-values.yaml | 16 ++++ examples/quickstart/wadm-values.yaml | 6 ++ examples/quickstart/wasmcloud-host.yaml | 7 ++ sample.yaml | 53 ----------- 8 files changed, 258 insertions(+), 58 deletions(-) create mode 100644 examples/full-config/wasmcloud-annotated.yaml create mode 100644 examples/quickstart/README.md create mode 100644 examples/quickstart/hello-world-application.yaml create mode 100644 examples/quickstart/nats-values.yaml create mode 100644 examples/quickstart/wadm-values.yaml create mode 100644 examples/quickstart/wasmcloud-host.yaml delete mode 100644 sample.yaml diff --git a/README.md b/README.md index a6a9fc2..547bf2f 100644 --- a/README.md +++ b/README.md @@ -18,14 +18,14 @@ spec: # The number of wasmCloud host pods to run hostReplicas: 2 # The lattice to connect the hosts to - lattice: 83a5b52e-17cf-4080-bac8-f844099f142e + lattice: default # Additional labels to apply to the host other than the defaults set in the operator hostLabels: some-label: value # The address to connect to nats - natsAddress: nats://nats-cluster.default.svc.cluster.local + natsAddress: nats://nats.default.svc.cluster.local # Which wasmCloud version to use - version: 1.0.2 + version: 1.0.4 # Enable the following to run the wasmCloud hosts as a DaemonSet #daemonset: true # The name of the image pull secret to use with wasmCloud hosts so that they @@ -121,7 +121,7 @@ config: ```sh helm repo add nats https://nats-io.github.io/k8s/helm/charts/ -helm upgrade --install -f values.yaml nats-cluster nats/nats +helm upgrade --install -f values.yaml nats nats/nats ``` ### Running Wadm @@ -133,7 +133,7 @@ NATS server deployed above, all you need in your `values.yaml` file is: wadm: config: nats: - server: "nats-cluster.default.svc.cluster.local:4222" + server: "nats.default.svc.cluster.local:4222" ``` You can deploy Wadm using your values file and Helm: diff --git a/examples/full-config/wasmcloud-annotated.yaml b/examples/full-config/wasmcloud-annotated.yaml new file mode 100644 index 0000000..667e99a --- /dev/null +++ b/examples/full-config/wasmcloud-annotated.yaml @@ -0,0 +1,92 @@ +apiVersion: k8s.wasmcloud.dev/v1alpha1 +kind: WasmCloudHostConfig +metadata: + name: my-wasmcloud-cluster + namespace: default +spec: + # Optional: Number of hosts (pods). Defaults to 1. + hostReplicas: 1 + # Required: The lattice to connect the hosts to. + lattice: default + # Optional: Additional labels to apply to the host other than the defaults set in the controller. + hostLabels: + test: value + cluster: kind + # Required: Which wasmCloud version to use. + version: "1.0.4" + # Optional: The image to use for the wasmCloud host. + # If provided, the 'version' field will be ignored. + image: "registry/wasmcloud:tag" + # Optional: The image to use for the NATS leaf that is deployed alongside the wasmCloud host. + # If not provided, the default upstream image will be used. + natsLeafImage: "registry/nats:tag" + # Optional. The name of a secret containing a set of NATS credentials under 'nats.creds' key. + secretName: "wasmcloud-host-nats-secret" + # Optional: Enable structured logging for host logs. Defaults to "false". + enableStructuredLogging: true + # Optional: The name of a secret containing the registry credentials. + # See https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-secret-by-providing-credentials-on-the-command-line + registryCredentialsSecret: "wasmcloud-pull-secret" + # Optional: The control topic prefix to use for the host. Defaults to "wasmbus.ctl" + controlTopicPrefix: "wasmbus.custom-ctl" + # Optional: The leaf node domain to use for the NATS sidecar. Defaults to "leaf". + leafNodeDomain: "custom-leaf" + # Optional: Enable the config service for this host. Defaults to "false". + # Makes wasmCloud host issue requests to a config service on startup. + configServiceEnabled: true + # Optional: The log level to use for the host. Defaults to "INFO". + logLevel: INFO + # Optional: The address of the NATS server to connect to. Defaults to "nats://nats.default.svc.cluster.local". + natsAddress: nats://nats.default.svc.cluster.local + # Optional: Allow the host to deploy using the latest tag on OCI components or providers. Defaults to "false". + allowLatest: true + # Optional: Allow the host to pull artifacts from OCI registries insecurely. + allowedInsecure: + - "localhost:5001" + - "kind-registry:5000" + # Optional: Policy service configuration. + policyService: + # If provided, enables policy checks on start actions and component invocations. + topic: "wasmcloud.policy" + # If provided, allows the host to subscribe to updates on past policy decisions. Requires 'topic' above to be set. + changesTopic: "wasmcloud.policy.changes" + # If provided, allows setting a custom timeout for requesting policy decisions. Defaults to 1000. Requires 'topic' to be set. + timeoutMs: 10000 + # Optional: Observability options for configuring the OpenTelemetry integration. + observability: + # NOTE: Enables all signals (logs/metrics/traces) at once. Set it to 'false' and enable each signal individually in case you don't need all of them. + enable: true + endpoint: "otel-collector.svc" + # Either 'grpc' or 'http' + protocol: "http" + logs: + enable: false + endpoint: "logs-specific-otel-collector.svc" + metrics: + enable: false + endpoint: "metrics-specific-otel-collector.svc" + traces: + enable: false + endpoint: "traces-specific-otel-collector.svc" + # Optional: Additional options to control how the underlying wasmCloud hosts are scheduled in Kubernetes. + # This includes setting resource requirements for the nats and wasmCloud host + # containers along with any additional pot template settings. + schedulingOptions: + # Optional: Enable the following to run the wasmCloud hosts as a DaemonSet. Defaults to "false". + daemonset: true + # Optional: Set the resource requirements for the nats and wasmCloud host containers. + # See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ for valid values + resources: + nats: + requests: + cpu: "1" + wasmCloudHost: + requests: + cpu: "1" + # Optional: Any additional pod template settings to apply to the wasmCloud host pods. + # See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#podspec-v1-core for all valid options. + # Note that you *cannot* set the `containers` field here as it is managed by the controller. + podTemplateAdditions: + spec: + nodeSelector: + kubernetes.io/os: linux diff --git a/examples/quickstart/README.md b/examples/quickstart/README.md new file mode 100644 index 0000000..2abfdfd --- /dev/null +++ b/examples/quickstart/README.md @@ -0,0 +1,87 @@ +# Example setup + +This example shows the bare minimum requirements to deploy applications on wasmCloud. + +It relies on the Kubernetes `default` namespace for simplicity. + +## Install [NATS](https://github.com/nats-io/nats-server) + +```bash +helm repo add nats https://nats-io.github.io/k8s/helm/charts/ +helm upgrade --install -f nats-values.yaml nats nats/nats +``` + +Validate installation with: + +```bash +# make sure pods are ready +kubectl rollout status deploy,sts -l app.kubernetes.io/instance=nats +``` + +## Install wasmCloud Application Deployment Manager - [wadm](https://github.com/wasmCloud/wadm) + +```sh +helm install wadm -f wadm-values.yaml oci://ghcr.io/wasmcloud/charts/wadm +``` + +Validate installation with: + +```bash +# make sure pods are ready +kubectl rollout status deploy -l app.kubernetes.io/instance=wadm +``` + +## Install the operator + +```sh +kubectl apply -k ../../deploy/base +``` + +Validate installation with: + +```bash +# make sure pods are ready +kubectl rollout status deploy -l app=wasmcloud-operator -n wasmcloud-operator +# apiservice should be available +kubectl get apiservices.apiregistration.k8s.io v1beta1.core.oam.dev +``` + +## Create wasmcloud cluster + +```bash +kubectl apply -f wasmcloud-host.yaml +``` + +Check wasmCloud host status with: + +```bash +kubectl describe wasmcloudhostconfig wasmcloud-host +``` + +## Managing applications using kubectl + +Install the rust hello world application: + +```bash +kubectl apply -f hello-world-application.yaml +``` + +Check application status with: + +```bash +kubectl get applications +``` + +## Managing applications with wash + +Port forward into the NATS cluster. 4222 = NATS Service, 4223 = NATS Websockets + +```bash +kubectl port-forward svc/nats 4222:4222 4223:4223 +``` + +In another shell: + +```bash +wash app list +``` diff --git a/examples/quickstart/hello-world-application.yaml b/examples/quickstart/hello-world-application.yaml new file mode 100644 index 0000000..967c8e3 --- /dev/null +++ b/examples/quickstart/hello-world-application.yaml @@ -0,0 +1,45 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: hello-world + annotations: + version: v0.0.1 + description: "HTTP hello world demo in Rust, using the WebAssembly Component Model and WebAssembly Interfaces Types (WIT)" + wasmcloud.dev/authors: wasmCloud team + wasmcloud.dev/source-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/rusg/components/http-hello-world/wadm.yaml + wasmcloud.dev/readme-md-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/rusg/components/http-hello-world/README.md + wasmcloud.dev/homepage: https://github.com/wasmCloud/wasmCloud/tree/main/examples/rusg/components/http-hello-world + wasmcloud.dev/categories: | + http,http-server,rust,hello-world,example +spec: + components: + - name: http-component + type: component + properties: + image: ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0 + traits: + # Govern the spread/scheduling of the component + - type: spreadscaler + properties: + replicas: 1 + + # Add a capability provider that enables HTTP access + - name: httpserver + type: capability + properties: + image: ghcr.io/wasmcloud/http-server:0.21.0 + traits: + # Establish a unidirectional link from this http server provider (the "source") + # to the `http-component` component (the "target") so the component can handle incoming HTTP requests, + # + # The source (this provider) is configured such that the HTTP server listens on 127.0.0.1:8080 + - type: link + properties: + target: http-component + namespace: wasi + package: http + interfaces: [incoming-handler] + source_config: + - name: default-http + properties: + address: 127.0.0.1:8080 diff --git a/examples/quickstart/nats-values.yaml b/examples/quickstart/nats-values.yaml new file mode 100644 index 0000000..457bdd9 --- /dev/null +++ b/examples/quickstart/nats-values.yaml @@ -0,0 +1,16 @@ +config: + cluster: + enabled: true + replicas: 3 + leafnodes: + enabled: true + websocket: + enabled: true + port: 4223 + jetstream: + enabled: true + fileStore: + pvc: + size: 10Gi + merge: + domain: default diff --git a/examples/quickstart/wadm-values.yaml b/examples/quickstart/wadm-values.yaml new file mode 100644 index 0000000..b7c209b --- /dev/null +++ b/examples/quickstart/wadm-values.yaml @@ -0,0 +1,6 @@ +wadm: + image: + tag: v0.12.2 + config: + nats: + server: "nats.default.svc.cluster.local:4222" diff --git a/examples/quickstart/wasmcloud-host.yaml b/examples/quickstart/wasmcloud-host.yaml new file mode 100644 index 0000000..b9a87d4 --- /dev/null +++ b/examples/quickstart/wasmcloud-host.yaml @@ -0,0 +1,7 @@ +apiVersion: k8s.wasmcloud.dev/v1alpha1 +kind: WasmCloudHostConfig +metadata: + name: wasmcloud-host +spec: + lattice: default + version: "1.0.4" diff --git a/sample.yaml b/sample.yaml deleted file mode 100644 index de77ab7..0000000 --- a/sample.yaml +++ /dev/null @@ -1,53 +0,0 @@ -apiVersion: k8s.wasmcloud.dev/v1alpha1 -kind: WasmCloudHostConfig -metadata: - name: my-wasmcloud-cluster - namespace: default -spec: - hostReplicas: 1 - # The lattice to connect the hosts to - lattice: default - # Additional labels to apply to the host other than the defaults set in the controller - hostLabels: - test: value - cluster: kind - # Which wasmCloud version to use - version: "1.0.2" - logLevel: INFO - natsAddress: nats://nats-cluster.default.svc.cluster.local - ################################################ - # Additional options that can be set for hosts: - ################################################ - # allowLatest: true - # allowedInsecure: - # - "localhost:5001" - # - "kind-registry:5000" - # Policy service configuration - # policyService: - # topic: "wasmcloud.policy" - # changesTopic: "bar" - # timeoutMs: 10000 - # Additional options to control how the underlying wasmCloud hosts are scheduled in Kubernetes. - # This includes setting resource requirements for the nats and wasmCloud host - # containers along with any additional pot template settings. - # schedulingOptions: - # Enable the following to run the wasmCloud hosts as a DaemonSet - # daemonset: true - # Set the resource requirements for the nats and wasmCloud host containers. - # resources: - # nats: - # requests: - # cpu: 100m - # wasmCloudHost: - # requests: - # cpu: 100m - # Any additional pod template settings to apply to the wasmCloud host pods. - # See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#podspec-v1-core for all valid options. - # Note that you *cannot* set the `containers` field here as it is managed by the controller. - # podTemplateAdditions: - # spec: - # env: - # - name: HOST_IP - # value: spec.hostIP - # nodeSelector: - # kubernetes.io/os: linux