A Spin plugin for interacting with Kubernetes.
Install the stable release:
spin plugins update
spin plugins install kubeAs an alternative to the plugin manager, you can download and manually install the plugin. Manual installation is commonly used to test in-flight changes. For a user, it's better to install the plugin using Spin's plugin manager.
Ensure the pluginify plugin is installed:
spin plugins update
spin plugins install pluginify --yesFetch the plugin:
git clone [email protected]:spinkube/spin-plugin-kube.git
cd spin-plugin-kubeCompile and install the plugin:
make
make installEnsure SpinKube is installed in your Kubernetes cluster. See the SpinKube Quickstart Guide.
Install the wasm32-wasi target for Rust:
rustup target add wasm32-wasiCreate a Spin application:
spin new --accept-defaults -t http-rust hello-rust
cd hello-rustCompile the application:
spin buildPublish your application:
docker login
spin registry push bacongobbler/hello-rust:latestDeploy to Kubernetes:
spin kube scaffold --from bacongobbler/hello-rust:latest | kubectl create -f -View your application:
kubectl get spinappsspin kube scaffold deploys two replicas by default. You can change this with the --replicas flag:
spin kube scaffold --from bacongobbler/hello-rust:latest --replicas 3 | kubectl apply -f -Delete the app:
kubectl delete spinapp hello-rustAutoscaler support can be enabled by setting --autoscaler and by setting a CPU limit and a memory limit.
spin kube scaffold --from bacongobbler/hello-rust:latest --autoscaler hpa --cpu-limit 100m --memory-limit 128MiSetting min/max replicas:
spin kube scaffold --from bacongobbler/hello-rust:latest --autoscaler hpa --cpu-limit 100m --memory-limit 128Mi --replicas 1 --max-replicas 10CPU/memory limits and CPU/memory requests can be set together:
spin kube scaffold --from bacongobbler/hello-rust:latest --autoscaler hpa --cpu-limit 100m --memory-limit 128Mi --cpu-request 50m --memory-request 64MiIMPORTANT!
    CPU/memory requests are optional and will default to the CPU/memory limit if not set.
    CPU/memory requests must be lower than their respective CPU/memory limit.
Setting the target CPU utilization:
spin kube scaffold --from bacongobbler/hello-rust:latest --autoscaler hpa --cpu-limit 100m --memory-limit 128Mi --autoscaler-target-cpu-utilization 50Setting the target memory utilization:
spin kube scaffold --from bacongobbler/hello-rust:latest --autoscaler hpa --cpu-limit 100m --memory-limit 128Mi --autoscaler-target-memory-utilization 50KEDA support:
spin kube scaffold --from bacongobbler/hello-rust:latest --autoscaler keda --cpu-limit 100m --memory-limit 128MiSupport for pulling images from private registries can be enabled by using --image-pull-secret <secret-name> flag, where <secret-name> is a secret of type docker-registry in same namespace as your SpinApp.
To enable multiple private registries, you can provide the flag --image-pull-secret multiple times with secret for each registry that you wish to use.
Create a secret with credentials for private registry
$) kubectl create secret docker-registry registry-credentials \
  --docker-server=ghcr.io \
  --docker-username=bacongobbler \
  --docker-password=github-token
secret/registry-credentials createdVerify that the secret is created
$) kubectl get secret registry-credentials -o yaml
apiVersion: v1
data:
  .dockerconfigjson: eyJhdXRocyI6eyJnaGNyLmlvIjp7InVzZXJuYW1lIjoiYmFjb25nb2JibGVyIiwicGFzc3dvcmQiOiJnaXRodWItdG9rZW4iLCJhdXRoIjoiWW1GamIyNW5iMkppYkdWeU9tZHBkR2gxWWkxMGIydGxiZz09In19fQ==
kind: Secret
metadata:
  creationTimestamp: "2024-02-27T02:18:53Z"
  name: registry-credentials
  namespace: default
  resourceVersion: "162287"
  uid: 2e12ddd1-919d-44b5-b6cc-c3cd5c09fcec
type: kubernetes.io/dockerconfigjsonUse the secret when scaffolding the SpinApp
$) spin kube scaffold --from bacongobbler/hello-rust:latest --image-pull-secret registry-credentials
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
  name: hello-rust
spec:
  image: "bacongobbler/hello-rust:latest"
  executor: containerd-shim-spin
  replicas: 2
  imagePullSecrets:
    - name: registry-credentials