关于 SpinKube,你需要了解的一切。
本站为社区维护的非官方中文翻译,与 SpinKube 官方项目无关,内容以 英文官方文档 为准。
第一步
要开始使用 SpinKube,请阅读我们的快速开始指南。
文档的组织方式
SpinKube 的文档内容十分丰富。了解其整体组织结构,可以帮助你知道去哪里查找所需的内容。
SpinKube 是一个开源项目,它通过 Spin Operator 配合 runwasi 和 runtime class manager,简化了在 Kubernetes 上部署和运维 Wasm 工作负载的体验。
借助 SpinKube,你可以充分利用 WebAssembly(Wasm)为工作负载带来的优势:
得益于 SpinKube,我们在实现上述优势的同时,还能与 Kubernetes 原生机制集成,包括 DNS、探针、自动伸缩、指标,以及众多其他云原生和 CNCF 项目。

SpinKube 会监视 Spin App 自定义资源,并在 Kubernetes 集群中实现期望的状态。本项目的基础是使用 kubebuilder 框架构建的,包含一个 Spin App 自定义资源定义(CRD)和控制器。
SpinKube 是 云原生计算基金会(CNCF)的沙箱项目。
要开始使用,请查阅我们的快速开始指南。
本快速开始指南演示如何搭建一个用于开发的 Kubernetes 集群、安装 SpinKube,并部署你的第一个 Spin 应用。本示例会创建一个 kind 集群,并在所有节点上预装 Spin containerd shim。在生产环境中,你应该使用 runtime class manager 来安装并管理 containerd shim 的生命周期。如需更多生产集群的安装说明,请跳转到 Helm 安装指南。
开始本快速开始指南之前,你需要:
spin runtime class 调度的工作负载使用 Spin containerd shim:cat <<EOF | kind create cluster --name wasm-cluster --image ghcr.io/spinframework/containerd-shim-spin/kind:v0.27.2 --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.cri.v1.runtime".containerd.runtimes.spin]
runtime_type = "io.containerd.spin.v2"
[plugins."io.containerd.cri.v1.runtime".containerd.runtimes.spin.options]
SystemdCgroup = true
EOF
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.20.0/cert-manager.yaml
kubectl wait --for=condition=available --timeout=300s deployment/cert-manager-webhook -n cert-manager
注意:在生产集群中,你通常需要通过
nodeSelector自定义 Runtime Class,使其匹配已安装 shim 的节点。不过在本 kind 示例中,shim 已在每个节点上预先配置好。
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.runtime-class.yaml
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.crds.yaml
执行以下命令,使用 Helm 在集群上安装 Spin Operator。这会在 Kubernetes 命名空间
spin-operator 下创建 Spin Operator 所需的全部 Kubernetes 资源。依赖安装和 Pod 启动需要一些时间,请稍候片刻。
# Install Spin Operator with Helm
helm upgrade --install spin-operator \
--namespace spin-operator \
--create-namespace \
--version 0.6.1 \
--wait \
oci://ghcr.io/spinframework/charts/spin-operator
最后,创建 shim executor:
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.shim-executor.yaml
现在你可以将 Spin 应用部署到集群上了!
spin-operator 命名空间中创建你的第一个应用:kubectl apply -f https://raw.githubusercontent.com/spinframework/spin-operator/main/config/samples/simple.yaml
kubectl port-forward svc/simple-spinapp 8083:80
curl localhost:8083/hello
你应该会看到:
Hello world from Spin!
恭喜你部署了第一个 SpinApp!推荐的后续步骤:
kube 插件。spin(即 Spin CLI)的 kube 插件为在 Kubernetes 环境中使用 Spin 应用提供了一流的体验。
请确保你的机器上已安装 Spin CLI(2.3.1 或更新版本)。
在安装插件之前,你应该先从 spin-plugins 仓库获取最新的 Spin 插件列表:
# Update the list of latest Spin plugins
spin plugins update
Plugin information updated successfully
接下来,使用 spin plugin install 安装 kube:
# Install the latest kube plugin
spin plugins install kube
此时,查询已安装的 Spin 插件列表时,你应该能看到 kube 插件:
# List all installed Spin plugins
spin plugins list --installed
cloud 0.7.0 [installed]
cloud-gpu 0.1.0 [installed]
kube 0.1.1 [installed]
pluginify 0.6.1 [installed]
除了使用插件管理器之外,你还可以下载并手动安装该插件。手动安装通常用于测试尚未发布的改动。对普通用户而言,使用 Spin 的插件管理器安装插件是更好的选择。
请参阅 spin-plugin-kube GitHub 仓库,了解如何从源码编译该插件。
对于本指南,你特别需要:
以下说明介绍如何使用 Helm chart(通过 helm install)安装 Spin Operator。
安装 chart 之前,你需要确保以下组件已安装:
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.20.0/cert-manager.yaml
# Install Runtime Class Manager
helm upgrade --install runtime-class-manager \
--namespace runtime-class-manager \
--create-namespace \
--version 0.2.0 \
oci://ghcr.io/spinframework/charts/runtime-class-manager
# Create Shim resource for installing the containerd-shim-spin binary
kubectl apply -f https://github.com/spinframework/containerd-shim-spin/releases/download/v0.27.2/runtime-class-manager-shim-v1alpha1-v0.27.2.yaml
# Label all Nodes where the shim should be installed (and thus where Spin Apps may run)
# Note: this specific key and value matches the nodeSelector configuration used in the Shim resource above
kubectl label node --all spin=true
此时你应该能看到一个 wasmtime-spin-v2 RuntimeClass,并且所有打过标签的节点都已准备好运行 Spin 应用。
依赖安装完成后,我们就可以开始安装 operator 了。这个过程包含几个步骤,允许日后在集群中进一步自定义 Spin 应用,不过这里我们安装默认配置。
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.crds.yaml
containerd-spin-shim SpinAppExecutor。它告诉 Spin Operator 使用我们刚创建的 RuntimeClass
来运行 Spin 应用:kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.shim-executor.yaml
以下命令以 release 名称 spin-operator 安装该 chart:
# Install Spin Operator with Helm
helm upgrade --install spin-operator \
--namespace spin-operator \
--create-namespace \
--version 0.6.1 \
--wait \
oci://ghcr.io/spinframework/charts/spin-operator
前往快速开始部署你的第一个 Spin 应用。或者,继续阅读如何升级或卸载 Spin Operator。
注意,在升级 Helm release 的同时,你可能还需要一并升级 spin-operator 的 CRD:
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.crds.yaml
要升级 spin-operator release,请运行以下命令:
# Upgrade Spin Operator using Helm
helm upgrade spin-operator \
--namespace spin-operator \
--version 0.6.1 \
--wait \
oci://ghcr.io/spinframework/charts/spin-operator
要删除 spin-operator release,请运行:
# Uninstall Spin Operator using Helm
helm delete spin-operator --namespace spin-operator
这会移除与该 chart 关联的所有 Kubernetes 资源,并删除 Helm release。
要彻底卸载所有与 spin-operator 相关的资源,你还可以删除相应的 CRD 资源:
kubectl delete -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.shim-executor.yaml
kubectl delete -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.crds.yaml
在本教程中,你将在 Azure Kubernetes Service(AKS)集群上安装 Spin Operator,并部署一个简单的 Spin 应用。你将学到:
在继续之前,请确保已安装以下工具:
在将 Spin Operator 部署到 Azure Kubernetes Service(AKS)之前,必须先准备好底层的云基础设施。本文将创建一个简单的 AKS 集群。(你也可以按照微软官方指南来搭建 AKS 集群。)
# Login with Azure CLI
az login
# Select the desired Azure Subscription
az account set --subscription <YOUR_SUBSCRIPTION>
# Create an Azure Resource Group
az group create --name rg-spin-operator \
--location germanywestcentral
# Create an AKS cluster
az aks create --name aks-spin-operator \
--resource-group rg-spin-operator \
--location germanywestcentral \
--node-count 1 \
--tier free \
--generate-ssh-keys
AKS 集群创建完成后,使用 aks get-credentials 命令为 kubectl 下载凭证:
# Download credentials for kubectl
az aks get-credentials --name aks-spin-operator \
--resource-group rg-spin-operator
为了验证,你可以使用 kubectl 浏览 AKS 集群中的常见资源:
# Browse namespaces in the AKS cluster
kubectl get namespaces
NAME STATUS AGE
default Active 3m
kube-node-lease Active 3m
kube-public Active 3m
kube-system Active 3m
首先,必须安装 自定义资源定义(CRD)
以及 wasmtime-spin-v2 的 Runtime Class。
# Install the CRDs
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.crds.yaml
下面安装 cert-manager,它是自动供应和管理 TLS 证书所必需的(Spin Operator 的准入 webhook 系统会用到这些证书):
# Install cert-manager CRDs
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.20.0/cert-manager.crds.yaml
# Add and update Jetstack repository
helm repo add jetstack https://charts.jetstack.io
helm repo update
# Install the cert-manager Helm chart
helm upgrade --install cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace \
--version v1.20.0
Spin Operator chart 还依赖 Runtime Class Manager,它用于在 Kubernetes 节点上安装 containerd Spin shim:
# Install Runtime Class Manager
helm upgrade --install runtime-class-manager \
--namespace runtime-class-manager \
--create-namespace \
--version 0.2.0 \
oci://ghcr.io/spinframework/charts/runtime-class-manager
# Create Shim resource for installing the containerd-shim-spin binary
kubectl apply -f https://github.com/spinframework/containerd-shim-spin/releases/download/v0.27.2/runtime-class-manager-shim-v1alpha1-v0.27.2.yaml
# Label all Nodes where the shim should be installed (and thus where Spin Apps may run)
# Note: this specific key and value matches the nodeSelector configuration used in the Shim resource above
kubectl label node --all spin=true
要验证 containerd-shim-spin 是否安装成功,可以查看由 Runtime Class Manager 更新的 Shim 资源状态:
# Inspect the Shim resource
kubectl get shim spin-v2 --no-headers -o custom-columns=":status.nodesReady"
上述命令返回的数值应与你集群中节点的数量一致(即上一步中打了标签的节点数)。
下面的命令会以 spin-operator 为 release 名称,把 chart 安装到 spin-operator 命名空间:
helm upgrade --install spin-operator \
--namespace spin-operator \
--create-namespace \
--version 0.6.1 \
--wait \
oci://ghcr.io/spinframework/charts/spin-operator
最后,创建 shim executor::
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.shim-executor.yaml
为了验证 Spin Operator 的部署,你将向 AKS 集群部署一个简单的 Spin App。以下命令会使用
上一节中创建的 SpinApp CRD 安装一个简单的 Spin App:
# Deploy a sample Spin app
kubectl apply -f https://raw.githubusercontent.com/spinframework/spin-operator/main/config/samples/simple.yaml
配置端口转发,将本地机器的 8080 端口转发到 Kubernetes 服务的 80 端口,该服务指向上一节安装的
Spin App:
kubectl port-forward services/simple-spinapp 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
使用 curl 向 http://127.0.0.1:8080/hello 发送
HTTP 请求:
# Send an HTTP GET request to the Spin App
curl -iX GET http://localhost:8080/hello
HTTP/1.1 200 OK
transfer-encoding: chunked
date: Mon, 12 Feb 2024 12:23:52 GMT
Hello world from Spin!%
要删除本文创建的 Azure 基础设施,请使用以下命令:
# Remove all Azure resources
az group delete --name rg-spin-operator \
--no-wait \
--yes
本指南将逐步介绍如何在 Linode Kubernetes Engine(LKE)上安装和配置 SpinKube。
本指南假设你已拥有一个 Akamai Linode 账户,该账户已完成配置, 并具有创建新 LKE 集群的足够权限。
你还需要在系统上安装较新版本的 kubectl 和 helm。
LKE 的控制平面是托管的,因此你只需要创建工作节点池。在本教程中,我们将使用最小可用的 工作节点创建一个 2 节点的 LKE 集群。对于安装 SpinKube 并运行大约 100 个以内的 Spin 应用来说, 这已经足够了。
如果你计划将容器与 Spin 应用混合部署,可能更倾向于使用更大的集群,因为容器消耗的资源 远多于 Spin 应用。
在 Linode 的 Web 控制台中,点击右侧导航栏中的 Kubernetes,然后点击 Create Cluster。

在这个界面上你只需做少量选择。以下是我们所做的配置:
spinkube-lke-1。你可以按照自己喜欢的命名规范来命名。Chicago, IL (us-ord) 区域,但你可以选择任意你喜欢的区域。1.30,所以我们选择了该版本。HA Control Plane 上选择了 No,
因为我们不需要高可用。Add Node Pools 中,我们添加了两个 Dedicated 4 GB 节点,仅仅是为了
展示一个运行多个节点的集群。对于 Spin 应用来说,两个节点已经足够,不过你可能更倾向于
传统的 3 节点集群。点击 Add 添加这些节点,并忽略关于最小规格的警告。设置完成后,点击 Create Cluster。
接下来会进入一个显示集群状态的页面。最初,你需要等待所有 Node Pool 启动完成。当所有
节点都上线后,下载 kubeconfig 文件,其名称类似于 spinkube-lke-1-kubeconfig.yaml。
kubeconfig文件中包含连接到新 LKE 集群的凭证。请不要共享该文件,也不要将其放在 公开的地方。
在后续所有操作中,你都需要将 spinkube-lke-1-kubeconfig.yaml 作为主 Kubernetes 配置文件。
最好的做法是设置环境变量 KUBECONFIG 指向该文件:
$ export KUBECONFIG=/path/to/spinkube-lke-1-kubeconfig.yaml
你可以使用 kubectl config view 命令来测试:
$ kubectl config view
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://REDACTED.us-ord-1.linodelke.net:443
name: lke203785
contexts:
- context:
cluster: lke203785
namespace: default
user: lke203785-admin
name: lke203785-ctx
current-context: lke203785-ctx
kind: Config
preferences: {}
users:
- name: lke203785-admin
user:
token: REDACTED
这展示了我们的集群配置。你应该可以将 lkeNNNNNN 版本的编号与 Akamai Linode 控制面板中
显示的内容进行对照。
到这里,请使用 Helm 安装 SpinKube。只要你的 KUBECONFIG
环境变量指向正确的集群,那里文档中介绍的安装方法就可以正常工作。
完成这些安装步骤后,请返回本页来安装第一个应用。
我们将使用 spin kube 插件来生成一个新应用的骨架。如果你运行以下命令时尚未安装 kube
插件,系统会先提示你安装该插件。请选择 yes 进行安装。
我们将指向一个已有的 Spin 应用——一个用 Rust 编写的 Hello World 程序, 它被编译为 Wasm 并存储在 GitHub Container Registry(GHCR)中:
$ spin kube scaffold --from ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.0 > hello-world.yaml
请注意,Spin 应用本质上是 WebAssembly,尽管它们并不是 Docker 容器,但可以存储在大多数容器镜像仓库中。
该命令会将以下内容写入 hello-world.yaml:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: spin-rust-hello
spec:
image: "ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.0"
executor: containerd-shim-spin
replicas: 2
使用 kubectl apply,我们就可以部署该应用:
$ kubectl apply -f hello-world.yaml
spinapp.core.spinkube.dev/spin-rust-hello created
在 SpinKube 中,SpinApp 会以 Pod 资源的形式部署,因此我们可以用 kubectl get pods 查看该应用:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
spin-rust-hello-f6d8fc894-7pq7k 1/1 Running 0 54s
spin-rust-hello-f6d8fc894-vmsgh 1/1 Running 0 54s
状态显示为 Running,说明我们的应用已经就绪。
默认情况下,Spin 应用会以内部服务的形式部署。但在 Linode 上,你可以通过 Service
对象来供应一个 NodeBalancer。
下面这个 hello-world-service.yaml 可以为我们供应一个 nodebalancer:
apiVersion: v1
kind: Service
metadata:
name: spin-rust-hello-nodebalancer
annotations:
service.beta.kubernetes.io/linode-loadbalancer-throttle: "4"
labels:
core.spinkube.dev/app-name: spin-rust-hello
spec:
type: LoadBalancer
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
core.spinkube.dev/app.spin-rust-hello.status: ready
sessionAffinity: None
当 LKE 收到一个 type 为 LoadBalancer 的 Service 时,它会为你供应一个 NodeBalancer。
你只需将文件中所有
spin-rust-hello替换为自己应用的名称,即可针对你的应用进行定制。
我们可以对上述文件运行 kubectl apply 来创建 NodeBalancer:
$ kubectl apply -f hello-world-nodebalancer.yaml
service/spin-rust-hello-nodebalancer created
供应新的 NodeBalancer 可能需要一些时间,但我们可以使用
kubectl get service spin-rust-hello-nodebalancer 来获取其 IP 地址:
$ get service spin-rust-hello-nodebalancer
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
spin-rust-hello-nodebalancer LoadBalancer 10.128.235.253 172.234.210.123 80:31083/TCP 40s
EXTERNAL-IP 字段告诉我们 NodeBalancer 使用的公网 IP。现在我们可以通过互联网访问它,
使用 curl,或者在浏览器中输入 URL http://172.234.210.123/hello。
$ curl 172.234.210.123/hello
Hello world from Spin!
要删除这个示例应用,我们先删除 NodeBalancer,然后再删除应用:
$ kubectl delete service spin-rust-hello-nodebalancer
service "spin-rust-hello-nodebalancer" deleted
$ kubectl delete spinapp spin-rust-hello
spinapp.core.spinkube.dev "spin-rust-hello" deleted
如果你直接在 Linode 控制台中删除 NodeBalancer,Kubernetes 中的
Service记录并不会被 自动删除,从而造成不一致。因此,最好使用kubectl delete service来删除你的 NodeBalancer。
如果你也不再需要 LKE 集群,最简单的删除方式是登录 Akamai Linode 控制面板,进入
Kubernetes,然后按下 Delete 按钮。这将销毁所有工作节点并注销控制平面。
Rancher Desktop 是一个开源应用,为在桌面环境中使用容器和 Kubernetes 提供了所有必备功能。
1.19.1 和 Spin v3.2.0 进行了测试,但更新的版本应该也能正常工作。containerd 配置为你的容器运行时引擎(位于 Preferences -> Container Engine 下)。

请确保在 Kubernetes 上下文中选择了 rancher-desktop:kubectl config use-context rancher-desktop
更改应用完成后,进入 Cluster Dashboard -> Workloads。你应该能看到
spin-operator-controller-manager 已部署到 spin-operator 命名空间。
http-js 模板创建一个名为 hello-k3s 的
新 Spin 应用。 $ spin new -t http-js hello-k3s --accept-defaults
$ cd hello-k3s
/src/index.js 文件,让工作负载返回字符串 “Hello from Rancher Desktop”:import { AutoRouter } from 'itty-router';
let router = AutoRouter();
router
.get("/", () => new Response("Hello from Rancher Desktop")) // <-- this changed
.get('/hello/:name', ({ name }) => `Hello, ${name}!`)
addEventListener('fetch', (event) => {
event.respondWith(router.fetch(event.request));
});
$ npm install
$ spin build
$ spin registry push ttl.sh/hello-k3s:0.1.0
将 ttl.sh/hello-k3s:0.1.0 替换为你的镜像仓库 URL 和标签。
使用 spin-kube 插件将你的应用部署到集群:
spin kube scaffold --from ttl.sh/hello-k3s:0.1.0 | kubectl apply -f -
如果点击 Rancher Desktop 的 “Cluster Dashboard”,我们可以在 “Workloads” 下拉区域中看到
hello-k3s 正在运行:

要在集群外部访问我们的应用,可以进行端口转发,以便从主机访问该应用:
$ kubectl port-forward svc/hello-k3s 8083:80
要在本地测试,可以发送如下请求:
$ curl localhost:8083
Hello from Rancher Desktop
执行上面的 curl 命令,或在浏览器中快速访问 localhost:8083,都会返回 “Hello
from Rancher Desktop” 消息:

本指南将逐步介绍如何安装和配置 Microk8s 与 SpinKube。
本指南假设你使用的是 Ubuntu 24.04,并且已启用 Snap(这是默认配置)。
本次安装的测试平台是一台配备 4G 内存和 2 个核心的 Akamai Edge Linode。
你需要安装 Spin。最简单的方式是 使用下面的一行命令获取最新版本的 Spin:
$ curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash
通常,接下来你需要把 spin 移动到 /usr/local/bin 或 $PATH 上的其他位置:
$ sudo mv spin /usr/local/bin/spin
你可以用 which spin 来测试它是否在 $PATH 上。如果返回为空,你就需要调整
$PATH 变量,或者把 Spin 放到已在 $PATH 上的某个位置。
如果你更愿意使用 shell 脚本,可以看看这个 Gist, 它是很好的起点。它会安装 Microk8s 和 SpinKube,并对两者进行配置。
使用 snap 安装 microk8s:
$ sudo snap install microk8s --classic
这会安装并启动 Microk8s。在继续之前,你可能想先阅读官方安装说明。
等待一两分钟后,使用 microk8s status 命令确认 Microk8s 正在运行。
接下来,启用 TLS 证书管理器:
$ microk8s enable cert-manager
现在我们就可以安装用于运行 Spin 应用的 SpinKube 环境了。
SpinKube 提供了运行 Spin 无服务器应用的完整工具链。在继续之前,你可能想先熟悉一下 SpinKube 快速开始指南。
首先,我们需要应用 SpinKube 的 CRD:
$ microk8s kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.crds.yaml
这些应该会立即应用完成。
接下来,我们还需要安装 Runtime Class Manager,因为 Microk8s 尚未内置它。它负责在尚未 内置 WebAssembly shim 的 Kubernetes 节点上安装这些 shim。更多细节请参阅项目的 README.md。
microk8s helm upgrade --install runtime-class-manager \
--namespace runtime-class-manager \
--create-namespace \
--version 0.2.0 \
oci://ghcr.io/spinframework/charts/runtime-class-manager
# Create Shim resource for installing the containerd-shim-spin binary
kubectl apply -f https://github.com/spinframework/containerd-shim-spin/releases/download/v0.27.2/runtime-class-manager-shim-v1alpha1-v0.27.2.yaml
# Label all Nodes where the shim should be installed (and thus where Spin Apps may run)
# Note: this specific key and value matches the nodeSelector configuration used in the Shim resource above
microk8s kubectl label node --all spin=true
上面的最后一行告诉 Microk8s,集群中的所有节点(在本例中只有一个节点)都可以运行 Spin 应用。
接下来,我们需要使用 Helm(Microk8s 已内置)安装 SpinKube 的 operator:
$ microk8s helm upgrade --install spin-operator --namespace spin-operator --create-namespace --version 0.6.1 --wait oci://ghcr.io/spinframework/charts/spin-operator
现在主 operator 已经安装完成。还剩最后一步:我们需要安装 shim executor,它是一个特殊的 CRD,让我们可以为 WebAssembly 使用多个 executor。
$ microk8s kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.shim-executor.yaml
现在 SpinKube 已经安装完成!
接下来,我们可以在 Microk8s 中运行一个简单的 Spin 应用。
虽然我们可以编写常规的 deployment 或 pod 规约,但部署 Spin 应用最简单的方式是创建一个
简单的 SpinApp 资源。让我们使用 SpinKube 提供的简单示例:
$ microk8s kubectl apply -f https://raw.githubusercontent.com/spinframework/spin-operator/main/config/samples/simple.yaml
上面的命令会安装一个简单的 SpinApp YAML,其内容如下:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: simple-spinapp
spec:
image: "ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.0"
replicas: 1
executor: containerd-shim-spin
你可以在文档中阅读相关定义。
它启动可能需要一小会儿时间,但你应该可以通过 microk8s kubectl get pods 看到该应用:
$ microk8s kubectl get po
NAME READY STATUS RESTARTS AGE
simple-spinapp-5c7b66f576-9v9fd 1/1 Running 0 45m
如果 STATUS 一直停留在 ContainerCreating,可能是 Runtime Class Manager 未能正确安装
containerd-shim-spin 二进制文件。要查看日志,可以尝试:
$ microk8s kubectl logs -n runtime-class-manager -l app.kubernetes.io/name=runtime-class-manager
测试 Spin 应用最简单的方法是将端口从 Spin 应用转发到外部主机:
$ microk8s kubectl port-forward services/simple-spinapp 8080:80
然后你可以运行 curl localhost:8080/hello
$ curl localhost:8080/hello
Hello world from Spin!
到目前为止,我们安装了 Microk8s、SpinKube 和一个单独的 Spin 应用。要构建一个更接近 生产可用的环境,你可以考虑:
Microk8s 内置了一个基于 NGINX 的 ingress controller,它与 Spin 应用配合得很好。
启用 ingress controller:microk8s enable ingress
现在我们可以创建一个 ingress,把流量路由到 simple-spinapp 应用。创建文件
ingress.yaml,内容如下。注意 service.name 就是我们的
Spin 应用名称。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: http-ingress
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: simple-spinapp
port:
number: 80
使用 microk8s kubectl -f ingress.yaml 安装上述内容。稍等片刻后,你应该就能运行
curl [localhost](http://localhost) 并看到 Hello World!。
在本指南中,我们安装了 Spin、Microk8s 和 SpinKube,并运行了一个 Spin 应用。
要进一步了解 Spin 应用的更多功能,请访问 Spin 开发者文档。 你也可以在 Spin Up Hub 上查看各种示例。
如果想尝试不同的 Kubernetes 配置,请查看其他安装指南。
containerd-shim-spin ExecutorSpin containerd shim 项目是 Spin 的一种 containerd shim 实现。
如果 SpinApp 中配置的某个功能在所使用的 shim 版本中不受支持,应用可能无法按预期运行。下表列出了支持特定功能的 Spin
containerd shim、Spin Operator 和 spin kube
插件的版本。
| 功能 | SpinApp 字段 | Shim 版本 | Spin Operator 版本 | spin kube 插件版本 |
|---|---|---|---|---|
| OTEL Traces | otel | v0.15.0 | v0.3.0 | NA |
| Selective Deployment | components | v0.17.0 | v0.4.0 | v0.3.0 |
| Invocation Limits | invocationLimits | v0.20.0 | v0.6.0 | NA |
NA 表示该功能在对应项目中尚未提供
为了追踪 Spin 功能的可用性和 Spin SDK 的兼容性,下表列出了 Spin containerd shim 所使用的各 Spin 运行时版本。
| Shim 版本 | Spin 版本 |
|---|---|
| Spin v4.x | |
| v0.27.2 | Spin v4.2.6 |
| v0.27.1 | Spin v4.2.5 |
| v0.27.0 | Spin v4.2.5 |
| v0.26.0 | Spin v4.1.0 |
| v0.25.1 | Spin v4.0.0 |
| v0.25.0 | Spin v4.0.0 |
| Spin v3.x | |
| v0.24.0 | Spin v3.6.3 |
| v0.23.0 | Spin v3.6.2 |
| v0.22.0 | Spin v3.5.0 |
| v0.21.0 | Spin v3.4.0 |
| v0.20.0 | Spin v3.3.1 |
| v0.19.0 | Spin v3.2.0 |
| v0.18.0 | Spin v3.1.2 |
| v0.17.0 | Spin v3.0.0 |
| Spin v2.x | |
| v0.16.0 | Spin v2.6.0 |
| v0.15.1 | Spin v2.6.0 |
| v0.15.0 | Spin v2.6.0 |
| v0.14.1 | Spin v2.4.3 |
| v0.14.0 | Spin v2.4.2 |
| v0.13.0 | Spin v2.3.1 |
| v0.12.0 | Spin v2.2.0 |
本文介绍如何使用选择性部署(Selective Deployments)只部署 Spin 应用中的一部分组件。你将学到:
选择性部署让你可以控制 Spin 应用的某个实例中哪些组件处于激活状态。借助组件选择器(Component Selector),Spin 和 SpinKube 可以在运行时声明应激活哪些组件,让你在部署单一版本化工件的同时,自行决定启动时启用哪些部分。这种方式将开发者的目标(构建架构良好的应用)与运维需求(针对特定基础设施做优化)分离开来。
本教程需要:
spin kube 插件 v0.3 - 如有需要,请参照安装 spin kube 插件我们将使用一个名为 “Salutations” 的示例应用,它通过两个组件来演示问候功能,每个组件响应一个独立的 HTTP 路由。查看该应用清单可以看到,这个 Spin 应用由两个组件组成:
Hello 组件由 /hi 路由触发Goodbye 组件由 /bye 路由触发spin_manifest_version = 2
[application]
name = "salutations"
version = "0.1.0"
authors = ["Kate Goldenring <kate.goldenring@fermyon.com>"]
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"]
使用选择性部署,你可以只部署特定组件而无需修改源代码。在本例中,我们只部署 hello 组件。
注意,如果你的 Spin 应用包含两个以上的组件,你同样可以有选择地部署其中多个组件。
要进行选择性部署,首先需要使用 spin kube scaffold 命令把应用转换为 SpinApp 自定义资源,并通过可选的 --component 字段指定要部署的组件:
spin kube scaffold --from ghcr.io/spinkube/spin-operator/salutations:20241105-223428-g4da3171 --component hello --replicas 1 --out spinapp.yaml
现在查看 spinapp.yaml,可以看到通过选择性部署只会部署 hello 组件:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: salutations
spec:
image: "ghcr.io/spinkube/spin-operator/salutations:20241105-223428-g4da3171"
executor: containerd-shim-spin
replicas: 1
components:
- hello
现在你可以像平时一样使用 kubectl 部署应用:
# 使用 kubectl 部署 spinapp.yaml
kubectl apply -f spinapp.yaml
spinapp.core.spinkube.dev/salutations created
我们可以对 hello 组件的 service 做端口转发,验证是否只有这个组件在运行。
kubectl port-forward svc/salutations 8083:80
然后在另一个终端调用 /hi 路由:
curl localhost:8083/hi
如果 hello 组件正常运行,我们应该看到 “Hello Fermyon!” 的响应:
Hello Fermyon!
接下来试试 /bye 路由。它应该不会有任何返回,这证明只有 hello 组件被部署了:
curl localhost:8083/bye
就是这样!你在完全没有修改源代码的情况下,把 Spin 应用的一个子集选择性地部署到了 SpinKube。这种方式让你可以轻松地只部署所需组件,在只需要特定服务的环境中能够提升效率。
本文介绍 Spin 应用如何通过公共和私有镜像仓库进行打包与分发。你将学到:
本教程特别需要以下工具:
你可以使用 spin CLI 创建一个新的 Spin 应用。spin CLI 提供了多种模板,帮助你快速创建不同类型的 Spin 应用。出于演示目的,这里使用 http-go 模板创建一个简单的 Spin 应用。
# 使用 http-go 模板创建一个新的 Spin 应用
spin new --accept-defaults -t http-go hello-spin
# 进入 hello-spin 目录
cd hello-spin
spin CLI 在 hello-spin 中创建了所有必需的文件。除了 Spin 清单(spin.toml)之外,你可以在 main.go 中找到应用的具体实现:
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() {}
这段实现会响应所有传入的 HTTP 请求,返回状态码为 200(Ok)的 HTTP 响应,并把 Hello Fermyon 作为响应体发送回去。
你可以在本地机器上进入 hello-spin 文件夹,执行 spin up 命令来测试该应用。
Spin 应用以 OCI 工件(artifact)的形式打包和分发。借助 OCI 工件,Spin 应用可以通过任何实现了开放容器倡议分发规范(即 “OCI Distribution Spec”)的镜像仓库进行分发。
spin CLI 简化了 Spin 应用的打包与分发,并提供了一条原子命令(spin registry push)。你可以像下面这样,把上一节创建的 hello-spin 应用打包并分发出去:
# 打包并分发 hello-spin 应用
spin registry push --build ttl.sh/hello-spin:24h
建议在
spin registry push时加上--build标志。这样可以避免把过期版本的 Spin 应用意外推送到你选定的镜像仓库。
要将 Spin 应用部署到运行着 Spin Operator 的 Kubernetes 集群,你需要使用 spin 的 kube 插件。按下面的方式执行 spin kube deploy 命令,即可把 hello-spin 应用部署到你的 Kubernetes 集群:
# 将 hello-spin 应用部署到你的 Kubernetes 集群
spin kube deploy --from ttl.sh/hello-spin:24h
spinapp.core.spinkube.dev/hello-spin created
你可以使用选择性部署只部署 Spin 应用中的部分组件。
在上一节中,你使用 spin kube deploy 命令部署了 hello-spin 应用。虽然这样很方便,但有时你可能希望在应用之前先检查或修改 Kubernetes 清单。这时可以使用 spin kube scaffold 命令来生成 Kubernetes 清单:
spin kube scaffold --from ttl.sh/hello-spin:24h
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: hello-spin
spec:
image: "ttl.sh/hello-spin:24h"
replicas: 2
默认情况下,该命令会把所有 Kubernetes 清单打印到 STDOUT。你也可以指定 out 参数,将清单保存到文件中:
# 将清单生成到 spinapp.yaml
spin kube scaffold --from ttl.sh/hello-spin:24h \
--out spinapp.yaml
# 输出 spinapp.yaml 的内容
cat spinapp.yaml
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: hello-spin
spec:
image: "ttl.sh/hello-spin:24h"
replicas: 2
然后你就可以通过 kubectl CLI 应用清单来部署这个 Spin 应用:
kubectl apply -f spinapp.yaml
在实际场景中,Spin 应用经常通过需要某种身份验证的私有镜像仓库来分发。要将 Spin 应用发布到私有镜像仓库,你必须先使用 spin registry login 命令完成身份验证。
出于演示目的,下面将通过 GitHub Container Registry(GHCR)来分发 Spin 应用。你可以按照 GitHub 的这份指南创建一个新的个人访问令牌(PAT),身份验证时会用到它。
# 将 PAT 和 GitHub 用户名保存为环境变量
export GH_PAT=YOUR_TOKEN
export GH_USER=YOUR_GITHUB_USERNAME
# 使用 GHCR 对 spin CLI 进行身份验证
echo $GH_PAT | spin registry login ghcr.io -u $GH_USER --password-stdin
Successfully logged in as YOUR_GITHUB_USERNAME to registry ghcr.io
身份验证成功后,你就可以使用 spin registry push 把 Spin 应用推送到 GHCR:
# 将 hello-spin 推送到 GHCR
spin registry push --build ghcr.io/$GH_USER/hello-spin:0.0.1
Pushing app to the Registry...
Pushed with digest sha256:1611d51b296574f74b99df1391e2dc65f210e9ea695fbbce34d770ecfcfba581
在 Kubernetes 中,身份验证信息以 docker-registry 类型的 Secret 形式保存。下面的代码片段展示了如何利用你在上一节设置的环境变量,通过 kubectl 创建这样一个 Secret:
# 在 Kubernetes 中创建 Secret
kubectl create secret docker-registry ghcr \
--docker-server ghcr.io \
--docker-username $GH_USER \
--docker-password $CR_PAT
secret/ghcr created
使用 spin kube scaffold 生成所需的 SpinApp 自定义资源(CR):
# 生成 SpinApp 清单
spin kube scaffold --from ghcr.io/$GH_USER/hello-spin:0.0.1 \
--out spinapp.yaml
在使用 kubectl 部署清单之前,请更新 spinapp.yaml,通过 imagePullSecrets 属性关联你之前创建的 ghcr Secret。你的 SpinApp 清单应如下所示:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: hello-spin
spec:
image: ghcr.io/$GH_USER/hello-spin:0.0.1
imagePullSecrets:
- name: ghcr
replicas: 2
executor: containerd-shim-spin
$GH_USER应与你在本文前面章节中运行命令时实际提供的用户名一致
最后,你可以使用 kubectl apply 部署该应用:
# 使用 kubectl 部署 spinapp.yaml
kubectl apply -f spinapp.yaml
spinapp.core.spinkube.dev/hello-spin created
要启用 HTTPS 请求,必须为 executor 配置证书。SpinKube 可以配置为使用默认证书或自定义证书。
如果证书配置不当就发起请求,你会遇到如下错误信息:error trying to connect: unexpected EOF (unable to get local issuer certificate)。
将 installDefaultCACerts 设置为 true,SpinKube 就可以生成默认的 CA 证书包。这会创建一个名为 spin-ca 的 Secret,其中填充 curl 的默认证书包。你也可以通过设置 caCertSecret 来指定自定义的 Secret 名称。
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinAppExecutor
metadata:
name: containerd-shim-spin
spec:
createDeployment: true
deploymentConfig:
runtimeClassName: wasmtime-spin-v2
installDefaultCACerts: true
使用 kubectl 应用该 executor:
kubectl apply -f myexecutor.yaml
根据你的证书文件创建一个 Secret:
kubectl create secret generic my-custom-ca --from-file=ca-certificates.crt
配置 executor 使用该自定义证书 Secret:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinAppExecutor
metadata:
name: containerd-shim-spin
spec:
createDeployment: true
deploymentConfig:
runtimeClassName: wasmtime-spin-v2
caCertSecret: my-custom-ca
使用 kubectl 应用该 executor:
kubectl apply -f myexecutor.yaml
通过使用变量,你可以在不重新编译 SpinApp 的情况下改变应用的行为。在 Kubernetes 中运行时,你可以为变量提供常量值,也可以从
Kubernetes 原语(如 ConfigMaps 和 Secrets)中引用它们。本教程将引导你完成为 SpinApp 赋值的整个过程。
Note: 如果你想了解如何使用外部变量提供程序(例如 Vault 或 Azure Key Vault)来配置应用,请参阅外部变量提供程序指南。
我们将构建 SpinApp 并将其存储到一个 ttl.sh registry 中。进入 apps/variable-explorer 目录,并构建我们提供的 SpinApp:
# Build and publish the sample app
cd apps/variable-explorer
spin build
spin registry push ttl.sh/variable-explorer:1h
注意 ttl.sh/variable-explorer:1h 末尾的标签表示镜像的存留时长,例如
1h(1 小时)。最长为 24h,如果超过 24 小时,你需要重新推送。
出于演示目的,我们使用 variable
explorer 示例应用。它读取三个不同的变量(log_level、platform_name
和 db_password),并将其值打印到 STDOUT 流,如下面的代码片段所示:
let log_level = variables::get("log_level")?;
let platform_name = variables::get("platform_name")?;
let db_password = variables::get("db_password")?;
println!("# Log Level: {}", log_level);
println!("# Platform name: {}", platform_name);
println!("# DB Password: {}", db_password);
这些变量在 Spin manifest(spin.toml)中定义,并且 variable-explorer 组件被授予了对它们的访问权限:
[variables]
log_level = { default = "WARN" }
platform_name = { default = "Fermyon Cloud" }
db_password = { required = true }
[component.variable-explorer.variables]
log_level = "{{ log_level }}"
platform_name = "{{ platform_name }}"
db_password = "{{ db_password }}"
关于在 Spin manifest 中定义变量的更多内容,请参阅 Spin 应用 Manifest 参考。
在 Kubernetes 中,你使用 ConfigMaps 存储非敏感配置数据,使用 Secrets 存储敏感配置数据。部署 manifest
(config/samples/variable-explorer.yaml)中同时包含一个 ConfigMap 和一个 Secret 的定义:
kind: ConfigMap
apiVersion: v1
metadata:
name: spinapp-cfg
data:
logLevel: INFO
---
kind: Secret
apiVersion: v1
metadata:
name: spinapp-secret
data:
password: c2VjcmV0X3NhdWNlCg==
创建 SpinApp 时,你可以从以下几种指定变量的方式中选择:
SpinApp 规范中包含 variables 数组,用于指定变量(参见 kubectl explain spinapp.spec.variables)。
部署 manifest(config/samples/variable-explorer.yaml)为 platform_name 指定了静态值,log_level 的值从名为
spinapp-cfg 的 ConfigMap 中读取,而 db_password 的值从名为 spinapp-secret 的 Secret 中读取:
kind: SpinApp
apiVersion: core.spinkube.dev/v1alpha1
metadata:
name: variable-explorer
spec:
replicas: 1
image: ttl.sh/variable-explorer:1h
executor: containerd-shim-spin
variables:
- name: platform_name
value: Kubernetes
- name: log_level
valueFrom:
configMapKeyRef:
name: spinapp-cfg
key: logLevel
optional: true
- name: db_password
valueFrom:
secretKeyRef:
name: spinapp-secret
key: password
optional: false
正如部署 manifest 所示,你可以像为普通 Kubernetes Pod 指定环境变量那样使用 optional
属性,来控制当被引用的配置源不存在时,Kubernetes 是否阻止 SpinApp 启动。
你可以执行以下命令来部署所有资源:
kubectl apply -f config/samples/variable-explorer.yaml
configmap/spinapp-cfg created
secret/spinapp-secret created
spinapp.core.spinkube.dev/variable-explorer created
要验证所有变量都已正确传递给 SpinApp,你可以配置从本地机器到对应 Kubernetes Service 的端口转发:
kubectl port-forward services/variable-explorer 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
端口转发建立后,你可以在另一个终端会话中向 variable-explorer 发送 HTTP 请求:
curl http://localhost:8080
Hello from Kubernetes
最后,你可以使用 kubectl logs 查看 variable-explorer 在运行时产生的所有日志:
kubectl logs -l core.spinkube.dev/app-name=variable-explorer
# Log Level: INFO
# Platform Name: Kubernetes
# DB Password: secret_sauce
在变量赋值指南中,你已经了解了如何通过 SpinApp 的 variables 部分为其配置变量,既可以直接内联提供值,也可以通过 Kubernetes ConfigMap 或 Secret 来提供。
你还可以使用外部服务(例如 Vault 或 Azure Key Vault)来为你的应用提供变量值。本指南将结合相应的示例应用,向你展示如何使用和配置这两个服务。
要跟随本教程操作,你需要:
Spin 目前支持 Vault 和 Azure Key Vault 作为外部变量提供程序。配置通过运行时配置文件提供给应用。
在 SpinKube 中,该配置文件可以以 Kubernetes secret 的形式提供,并通过 SpinApp 的 runtimeConfig.loadFromSecret 部分与之关联。
Note:
loadFromSecret的优先级高于任何其他runtimeConfig配置。因此,所有 运行时配置都必须包含在这个 Kubernetes secret 中,包括 SQLite、Key Value 和 LLM 选项,即使它们原本可以通过各自专属的 spec 来指定。
接下来让我们看一些使用特定提供程序配置的示例。
Vault 是存储机密数据并充当安全键值存储的热门选择。
本指南假设你已具备:
我们将使用 variable explorer 应用来测试这一集成。
首先,将仓库克隆到本地并进入 variable-explorer 目录:
git clone git@github.com:spinkube/spin-operator.git
cd apps/variable-explorer
现在,构建应用并将其推送到你有访问权限的 registry。这里我们使用 ttl.sh:
spin build
spin registry push ttl.sh/variable-explorer:1h
runtime-config.toml 文件下面是一个包含 Vault 提供程序配置的 runtime-config.toml 文件示例:
[[config_provider]]
type = "vault"
url = "https://my-vault-server:8200"
token = "my_token"
mount = "admin/secret"
要使用这个示例,你需要将 url 和 token 字段更新为与你的 Vault 集群匹配的值。mount
的值取决于 Vault 命名空间以及 kv-v2 secrets 引擎的名称。在本示例中,命名空间为 admin,引擎名为 secret,例如可以运行
vault secrets enable --path=secret kv-v2 来创建。
在 Vault 中创建 variable-explorer 应用所需的 log_level、platform_name 和
db_password secrets:
vault kv put secret/log_level value=INFO
vault kv put secret/platform_name value=Kubernetes
vault kv put secret/db_password value=secret_sauce
接下来,通过 kube 插件一次性脚手架生成 SpinApp 以及包含 runtime-config.toml 数据的 Secret 资源:
spin kube scaffold -f ttl.sh/variable-explorer:1h -c runtime-config.toml -o scaffold.yaml
kubectl apply -f scaffold.yaml
现在你可以测试应用,验证所有变量都已从 Vault 提供程序正确传递给 SpinApp。
配置从本地机器到对应 Kubernetes Service 的端口转发:
kubectl port-forward services/variable-explorer 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
端口转发建立后,你可以在另一个终端会话中向 variable-explorer 发送 HTTP 请求:
curl http://localhost:8080
Hello from Kubernetes
最后,你可以使用 kubectl logs 查看 variable-explorer 在运行时产生的所有日志:
kubectl logs -l core.spinkube.dev/app-name=variable-explorer
# Log Level: INFO
# Platform Name: Kubernetes
# DB Password: secret_sauce
Azure Key Vault 是托管在 Azure 平台上的分布式应用的安全机密存储。
本指南假设你已具备:
本练习中我们将使用 Azure Key Vault Provider 示例应用。
首先,将仓库克隆到本地并进入 azure-key-vault-provider 目录:
git clone git@github.com:fermyon/enterprise-architectures-and-patterns.git
cd enterprise-architectures-and-patterns/application-variable-providers/azure-key-vault-provider
现在,构建应用并将其推送到你有访问权限的 registry。这里我们使用 ttl.sh:
spin build
spin registry push ttl.sh/azure-key-vault-provider:1h
接下来的步骤将引导你创建并配置 Azure Key Vault,并将连接凭据填入运行时配置文件。
# Variable Definition
KV_NAME=spinkube-keyvault
LOCATION=westus2
RG_NAME=rg-spinkube-keyvault
# Create Azure Resource Group and Azure Key Vault
az group create -n $RG_NAME -l $LOCATION
az keyvault create -n $KV_NAME \
-g $RG_NAME \
-l $LOCATION \
--enable-rbac-authorization true
# Grab the Azure Resource Identifier of the Azure Key Vault instance
KV_SCOPE=$(az keyvault show -n $KV_NAME -g $RG_NAME -otsv --query "id")
# Grab the ID of the currently signed in user in Azure CLI
CURRENT_USER_ID=$(az ad signed-in-user show -otsv --query "id")
# Make the currently signed in user a Key Vault Secrets Officer
# on the scope of the new Azure Key Vault instance
az role assignment create --assignee $CURRENT_USER_ID \
--role "Key Vault Secrets Officer" \
--scope $KV_SCOPE
# Create a test secret called 'secret` in the Azure Key Vault instance
az keyvault secret set -n secret --vault-name $KV_NAME --value secret_value -o none
SP_NAME=sp-spinkube-keyvault
SP=$(az ad sp create-for-rbac -n $SP_NAME -ojson)
CLIENT_ID=$(echo $SP | jq -r '.appId')
CLIENT_SECRET=$(echo $SP | jq -r '.password')
TENANT_ID=$(echo $SP | jq -r '.tenant')
az role assignment create --assignee $CLIENT_ID \
--role "Key Vault Secrets User" \
--scope $KV_SCOPE
runtime-config.toml 文件创建一个包含以下内容的 runtime-config.toml 文件,并将前面步骤中获得的 KV_NAME、CLIENT_ID、CLIENT_SECRET
和 TENANT_ID 的值代入其中。
[[config_provider]]
type = "azure_key_vault"
vault_url = "https://<$KV_NAME>.vault.azure.net/"
client_id = "<$CLIENT_ID>"
client_secret = "<$CLIENT_SECRET>"
tenant_id = "<$TENANT_ID>"
authority_host = "AzurePublicCloud"
通过 kube 插件一次性脚手架生成 SpinApp 以及包含 runtime-config.toml 数据的 Secret 资源:
spin kube scaffold -f ttl.sh/azure-key-vault-provider:1h -c runtime-config.toml -o scaffold.yaml
kubectl apply -f scaffold.yaml
现在你可以测试应用,验证 secret 的值是从 Azure Key Vault 解析得到的。
配置从本地机器到对应 Kubernetes Service 的端口转发:
kubectl port-forward services/azure-key-vault-provider 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
端口转发建立后,你可以在另一个终端会话中向 azure-key-vault-provider 应用发送 HTTP 请求:
curl http://localhost:8080
Loaded secret from Azure Key Vault: secret_value
本主题指南介绍如何配置 SpinKube,使你的 Spin 应用导出可观测性数据。这些数据将导出到一个 OpenTelemetry collector,再由其发送到 Jaeger。
在继续之前,请确保你已安装以下工具:
摘自 OpenTelemetry 文档:
OpenTelemetry Collector 提供了一种与厂商无关的实现,用于接收、处理和导出遥测数据。它免去了运行、操作和维护多个 agent/collector 的需要。它具备更好的可伸缩性,并支持将开源可观测性数据格式(如 Jaeger、Prometheus、Fluent Bit 等)发送到一个或多个开源或商业后端。
在我们的场景中,OpenTelemetry collector 作为接收和路由遥测数据的统一端点,让我们能够通过偏好的界面监控指标、链路追踪和日志。
摘自 Jaeger 文档:
Jaeger 是由 Uber Technologies 开源发布的分布式链路追踪平台。使用 Jaeger,你可以:监控和排查分布式工作流,识别性能瓶颈,追查问题根因,分析服务依赖关系。
在这里,我们让 OpenTelemetry collector 将链路追踪数据发送到 Jaeger。
首先,添加 OpenTelemetry collector 的 Helm 仓库:
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm repo update
接下来,将 OpenTelemetry collector 部署到你的集群:
helm upgrade --install otel-collector open-telemetry/opentelemetry-collector \
--set image.repository="otel/opentelemetry-collector-k8s" \
--set nameOverride=otel-collector \
--set mode=deployment \
--set config.exporters.otlp.endpoint=http://jaeger-collector.default.svc.cluster.local:4317 \
--set config.exporters.otlp.tls.insecure=true \
--set config.service.pipelines.traces.exporters\[0\]=otlp \
--set config.service.pipelines.traces.processors\[0\]=batch \
--set config.service.pipelines.traces.receivers\[0\]=otlp \
--set config.service.pipelines.traces.receivers\[1\]=jaeger
接下来,添加 Jaeger 的 Helm 仓库:
helm repo add jaegertracing https://jaegertracing.github.io/helm-charts
helm repo update
然后,将 Jaeger 部署到你的集群:
helm upgrade --install jaeger jaegertracing/jaeger \
--set provisionDataStore.cassandra=false \
--set allInOne.enabled=true \
--set agent.enabled=false \
--set collector.enabled=false \
--set query.enabled=false \
--set storage.type=memory
SpinAppExecutor 资源决定了 Spin 应用在集群中的部署方式。以下配置将确保任何使用该 executor 的 SpinApp 资源都会将遥测数据发送到 OpenTelemetry collector。要查看 SpinAppExecutor 的完整 OTel 选项列表,请参阅 API 参考。
创建一个名为 executor.yaml 的文件,内容如下:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinAppExecutor
metadata:
name: otel-shim-executor
spec:
createDeployment: true
deploymentConfig:
runtimeClassName: wasmtime-spin-v2
installDefaultCACerts: true
otel:
exporter_otlp_endpoint: http://otel-collector.default.svc.cluster.local:4318
运行以下命令部署该 executor:
kubectl apply -f executor.yaml
一切就绪后,我们现在可以部署一个使用 otel-shim-executor executor 的 SpinApp 资源。
创建一个名为 app.yaml 的文件,内容如下:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: otel-spinapp
spec:
image: ghcr.io/spinkube/spin-operator/cpu-load-gen:20240311-163328-g1121986
executor: otel-shim-executor
replicas: 1
运行以下命令部署该应用:
kubectl apply -f app.yaml
恭喜!你现在拥有了一个导出遥测数据的 Spin 应用。
接下来,我们需要生成一些遥测数据供 Spin 应用导出。使用以下命令对 Spin 应用进行端口转发:
kubectl port-forward svc/otel-spinapp 3000:80
在新的终端窗口中,执行一个 curl 请求:
curl localhost:3000
该请求需要运行片刻,完成后你应该会看到类似下面的输出:
fib(43) = 433494437
要查看 Jaeger 中的链路追踪数据,请使用以下端口转发命令:
kubectl port-forward svc/jaeger-query 16686:16686
然后,打开浏览器并访问 localhost:16686,即可与 Jaeger 的界面进行交互。
本主题指南介绍如何连接部署到 SpinKube 的应用,包括如何在本地开发时使用端口转发,以及如何在生产环境中使用 Ingress 规则。
让我们先向你的 Kubernetes 集群部署一个示例应用。整个教程中我们将使用这个应用来演示如何连接它。
如果你还没有搭建 Kubernetes 集群,请参阅快速开始指南。
kubectl apply -f https://raw.githubusercontent.com/spinkube/spin-operator/main/config/samples/simple.yaml
SpinKube 部署应用时,会创建一个 Kubernetes Service 将应用暴露给集群。你可以使用以下命令查看部署状态:
kubectl get services
你应该会看到一个名为 simple-spinapp 的 Service,类型为 ClusterIP。这意味着该 Service 只能从集群内部访问。
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
simple-spinapp ClusterIP 10.43.152.184 <none> 80/TCP 1m
我们将通过这个 Service 连接到你的应用。
这种方式非常适合调试和开发。它允许你将本地端口转发到该 Service。
将端口 8083 转发到该 Service,以便从你的计算机访问它:
kubectl port-forward svc/simple-spinapp 8083:80
你应该可以在浏览器中通过 http://localhost:8083 访问它:
curl http://localhost:8083
你应该会看到类似 “Hello world from Spin!” 的消息。
这是测试应用最简单的方式之一。但是,它并不适合生产环境使用。下一节将介绍如何使用 Ingress 控制器将你的应用暴露到互联网。
Ingress 将来自集群外部的 HTTP 和 HTTPS 路由暴露给集群内的 Service。流量路由由 Ingress 资源上定义的规则控制。
下面是一个简单的示例,其中一个 Ingress 将其所有流量转发到一个 Service:
(图片来源:Kubernetes 文档)
Ingress 可以配置为为应用提供外部可访问的 URL、负载均衡流量、终止 SSL / TLS,以及提供基于名称的虚拟主机。Ingress 控制器负责实现 Ingress 的要求,通常使用负载均衡器,不过它也可能配置你的边缘路由器或额外的前端来帮助处理流量。
要满足 Ingress 规则的要求,你必须拥有一个 Ingress 控制器。在没有控制器的情况下创建 Ingress 规则不会产生任何效果。
理想情况下,所有 Ingress 控制器都应该符合参考规范。但实际情况是,各种 Ingress 控制器的运作方式略有不同。请务必查阅你所使用的 Ingress 控制器的文档,了解其具体工作方式。
ingress-nginx 是一个流行的 Ingress 控制器,因此本教程将使用它:
helm upgrade --install ingress-nginx ingress-nginx \
--repo https://kubernetes.github.io/ingress-nginx \
--namespace ingress-nginx --create-namespace
等待 Ingress 控制器就绪:
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=120s
如果你的 Kubernetes 集群是一个支持 LoadBalancer 类型 Service 的“真实”集群,它会为 Ingress 控制器分配一个外部 IP 地址或 FQDN。
使用以下命令查看该 IP 地址或 FQDN:
kubectl get service ingress-nginx-controller --namespace=ingress-nginx
它就是 EXTERNAL-IP 字段。如果该字段显示 <pending>,说明你的 Kubernetes 集群无法创建负载均衡器。通常这是因为该集群不支持 LoadBalancer 类型的 Service。
获得外部 IP 地址(或 FQDN)后,请设置一条指向它的 DNS 记录。关于如何向你的域名添加新的 DNS 记录,请参阅你的 DNS 服务商的文档。
你需要创建一条指向该外部 IP 地址的 A 记录。假设你的外部 IP 地址是 <EXTERNAL-IP>,则可以创建如下记录:
A myapp.spinkube.local <EXTERNAL-IP>
向你的域名添加 DNS 记录并等待其生效后,接下来就可以创建 Ingress 资源了。
创建一个将流量路由到 simple-spinapp Service 的 Ingress 资源。以下示例假设你已经为 myapp.spinkube.local 设置了 DNS 记录:
kubectl create ingress simple-spinapp --class=nginx --rule="myapp.spinkube.local/*=simple-spinapp:80"
关于上面的命令,有几点说明:
simple-spinapp 是 Ingress 资源的名称。myapp.spinkube.local 是 Ingress 将为其路由流量的主机名。这就是你之前设置的 DNS 记录。simple-spinapp:80 是 SpinKube 为我们创建的 Service。应用在端口 80 上监听请求。假设 DNS 已正确生效,当你连接到 http://myapp.spinkube.local/ 时,应该会看到类似 “Hello world from Spin!” 的消息。
恭喜,你正在对外提供一个托管在 Kubernetes 集群上的公开网站!🎉
这是一种快速测试 Ingress 配置的方式,无需设置 DNS 记录,也适用于不支持 LoadBalancer 类型 Service 的集群。
打开一个新终端,将 localhost 的 8080 端口转发到 Ingress 控制器:
kubectl port-forward --namespace=ingress-nginx service/ingress-nginx-controller 8080:80
然后,在另一个终端中测试 Ingress 配置:
curl --resolve myapp.spinkube.local:8080:127.0.0.1 http://myapp.spinkube.local:8080/hello
你应该会看到类似 “Hello world from Spin!” 的消息。
如果你想在浏览器中查看应用的运行情况,可以修改你的 /etc/hosts 文件,将来自 myapp.spinkube.local 的请求解析到 Ingress 控制器:
127.0.0.1 myapp.spinkube.local
Spin 应用可以使用在键值存储中持久化数据的标准 API。Spin 中的默认键值存储是一个 SQLite 数据库,非常适合在无需搭建任何基础设施的情况下快速使用本地非关系型存储。然而,对于运行在 SpinKube 环境中的应用来说,这种方案可能并不理想,因为应用的副本数通常会扩展到不止一个。
好在 Spin 支持为应用配置外部键值提供方。外部提供方包括 Redis 或 Valkey,以及 Azure Cosmos DB。
要跟随本教程操作,你需要:
本教程将使用一个用 Go SDK 编写的 Spin 键值应用。该应用提供用于管理键值对的 CRUD(创建、读取、更新、删除)API。
首先,将仓库克隆到本地,并进入 examples/key-value 目录:
git clone git@github.com:fermyon/spin-go-sdk.git
cd examples/key-value
现在,构建应用并将其推送到你有权限访问的镜像仓库。这里我们使用 ttl.sh:
export IMAGE_NAME=ttl.sh/$(uuidgen):1h
spin build
spin registry push ${IMAGE_NAME}
由于我们已经有一个运行 SpinKube 的 Kubernetes 集群,我们将选择 Valkey 作为键值提供方,并通过 Bitnami 的 Valkey Helm chart 进行安装。在 Spin 中,Valkey 可以与 Redis 互换使用,但请注意 URL 需要使用 redis:// 协议而不是 valkey://。
helm install valkey --namespace valkey --create-namespace oci://registry-1.docker.io/bitnamicharts/valkey
正如安装成功后提示信息所述,请务必获取 valkey 密码以备后用:
export VALKEY_PASSWORD=$(kubectl get secret --namespace valkey valkey -o jsonpath="{.data.valkey-password}" | base64 -d)
运行时配置需要 Valkey URL 才能连接到该提供方。由于该 URL 包含敏感的密码字符串,我们将把它创建为 Kubernetes 中的 Secret 资源:
kubectl create secret generic kv-secret --from-literal=valkey-url="redis://:${VALKEY_PASSWORD}@valkey-master.valkey.svc.cluster.local:6379"
现在你可以着手为该应用编写 SpinApp 自定义资源清单了。
spec.runtimeConfig.keyValueStores 设置。更多细节请参阅 keyValueStores 参考指南。default 存储配置为 redis 提供方类型,并在 options 下提供 Valkey URL(通过其 Kubernetes Secret 引用)将 $IMAGE_NAME 和 $DB_URL 的值填入下面的清单,并保存为 spinapp.yaml:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: kv-app
spec:
image: "$IMAGE_NAME"
replicas: 1
executor: containerd-shim-spin
runtimeConfig:
keyValueStores:
- name: "default"
type: "redis"
options:
- name: "url"
valueFrom:
secretKeyRef:
name: "kv-secret"
key: "valkey-url"
将资源清单应用到你的 Kubernetes 集群:
kubectl apply -f spinapp.yaml
Spin Operator 会替你创建底层的 Kubernetes 资源。
现在你可以测试应用,验证其与所配置提供方的连接和键值存储是否正常。
配置从本地机器到对应 Kubernetes Service 的端口转发:
kubectl port-forward services/kv-app 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
端口转发建立后,你可以在另一个终端会话中向该应用发送 HTTP 请求。下面是一些入门示例。
创建一个值为 ok! 的 test 键:
$ curl -i -X POST -d "ok!" localhost:8080/test
HTTP/1.1 200 OK
content-length: 0
date: Mon, 29 Jul 2024 19:58:14 GMT
获取 test 键的值:
$ curl -i -X GET localhost:8080/test
HTTP/1.1 200 OK
content-length: 3
date: Mon, 29 Jul 2024 19:58:39 GMT
ok!
删除 test 键的值:
$ curl -i -X DELETE localhost:8080/test
HTTP/1.1 200 OK
content-length: 0
date: Mon, 29 Jul 2024 19:59:18 GMT
尝试再次获取 test 键的值:
$ curl -i -X GET localhost:8080/test
HTTP/1.1 500 Internal Server Error
content-type: text/plain; charset=utf-8
x-content-type-options: nosniff
content-length: 12
date: Mon, 29 Jul 2024 19:59:44 GMT
no such key
Spin 应用可以使用在 SQLite 数据库中持久化数据的标准 API。默认数据库由 Spin 运行时在本地文件系统上创建,这对于让应用快速跑起来非常方便。然而,对于运行在 SpinKube 环境中的应用来说,这种基于磁盘的方案可能并不理想,因为应用的副本数通常会扩展到不止一个。
好在 Spin 支持通过运行时配置为应用接入外部 SQLite 数据库提供方。外部提供方包括任何可以通过 HTTPS 访问的 libSQL 数据库。
要跟随本教程操作,你需要:
本教程将使用 HTTP CRUD Go SQLite 示例应用。这是一个基于 Go 的应用,通过 SQLite API 实现 CRUD(创建、读取、更新、删除)操作。
首先,将仓库克隆到本地,并进入 http-crud-go-sqlite 目录:
git clone git@github.com:fermyon/enterprise-architectures-and-patterns.git
cd enterprise-architectures-and-patterns/http-crud-go-sqlite
现在,构建应用并将其推送到你有权限访问的镜像仓库。这里我们使用 ttl.sh:
export IMAGE_NAME=ttl.sh/$(uuidgen):1h
spin build
spin registry push ${IMAGE_NAME}
如果你还没有可以通过 HTTPS 访问的 LibSQL 数据库,可以跟随我们通过 Turso 创建一个。
继续之前,请先安装 turso CLI 并注册账号(如果尚未完成)。
创建一个新数据库并保存其 HTTP URL:
turso db create spinkube
export DB_URL=$(turso db show spinkube --http-url)
接下来,为该数据库创建一个认证令牌(auth token):
export DB_TOKEN=$(turso db tokens create spinkube)
数据库令牌属于敏感信息,因此在 Kubernetes 中应将其创建为 Secret 资源:
kubectl create secret generic turso-auth --from-literal=db-token="${DB_TOKEN}"
现在你可以着手编写 SpinApp 自定义资源清单了。
image 的值使用的是上面推送的镜像引用。spec.runtimeConfig.sqliteDatabases 设置。更多细节请参阅 sqliteDatabases 参考指南。default 数据库配置为 libsql 提供方类型,并在 options 下提供数据库 URL 和认证令牌(通过其 Kubernetes Secret 引用)将 $IMAGE_NAME 和 $DB_URL 的值填入下面的清单,并保存为 spinapp.yaml:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: http-crud-go-sqlite
spec:
image: "$IMAGE_NAME"
replicas: 1
executor: containerd-shim-spin
runtimeConfig:
sqliteDatabases:
- name: "default"
type: "libsql"
options:
- name: "url"
value: "$DB_URL"
- name: "token"
valueFrom:
secretKeyRef:
name: "turso-auth"
key: "db-token"
将资源清单应用到你的 Kubernetes 集群:
kubectl apply -f spinapp.yaml
Spin Operator 会替你创建底层的 Kubernetes 资源。
现在你可以测试应用,验证其与所配置 SQLite 数据库的连接和数据存储是否正常。
配置从本地机器到对应 Kubernetes Service 的端口转发:
kubectl port-forward services/http-crud-go-sqlite 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
端口转发建立后,你可以在另一个终端会话中向 http-crud-go-sqlite 应用发送 HTTP 请求。下面是一些入门示例。
获取当前的所有条目:
$ curl -X GET http://localhost:8080/items
[
{
"id": "8b933c84-ee60-45a1-848d-428ad3259e2b",
"name": "Full Self Driving (FSD)",
"active": true
},
{
"id": "d660b9b2-0406-46d6-9efe-b40b4cca59fc",
"name": "Sentry Mode",
"active": true
}
]
创建一个新条目:
$ curl -X POST -d '{"name":"Engage Thrusters","active":true}' localhost:8080/items
{
"id": "a5efaa73-a4ac-4ffc-9c5c-61c5740e2d9f",
"name": "Engage Thrusters",
"active": true
}
再次获取条目,可以看到新增的条目:
$ curl -X GET http://localhost:8080/items
[
{
"id": "8b933c84-ee60-45a1-848d-428ad3259e2b",
"name": "Full Self Driving (FSD)",
"active": true
},
{
"id": "d660b9b2-0406-46d6-9efe-b40b4cca59fc",
"name": "Sentry Mode",
"active": true
},
{
"id": "a5efaa73-a4ac-4ffc-9c5c-61c5740e2d9f",
"name": "Engage Thrusters",
"active": true
}
]
spin kube 命令启用自动伸缩器支持的教程。在 Kubernetes 中,水平自动伸缩器会自动更新工作负载资源(例如 Deployment 或 StatefulSet),目标是让工作负载自动随需求变化而伸缩。
水平伸缩的意思是,应对负载增长的方式是部署更多资源。这与垂直伸缩不同;对 Kubernetes 而言,垂直伸缩意味着为工作负载中已在运行的资源分配更多内存或 CPU。
如果负载下降,且资源数量高于配置的最小值,水平自动伸缩器会指示工作负载资源(Deployment、StatefulSet 或其他类似资源)把规模缩减回去。
Spin 的 Kubernetes 插件包含自动伸缩器支持,让你可以告诉 Kubernetes 何时根据需求扩大或缩小 Spin 应用的规模。本教程将展示如何通过 spin kube scaffold 命令启用自动伸缩器支持。
无论使用哪种类型的自动伸缩,你都必须先回答下面几个问题,确定应用应如何伸缩:
Spin 的 Kubernetes 插件支持两种类型的自动伸缩器:Horizontal Pod Autoscaler(HPA)和 Kubernetes Event-driven Autoscaling(KEDA)。选择哪种自动伸缩器取决于你的应用需求。
Horizontal Pod Autoscaler(HPA)基于 CPU 或内存利用率对 Kubernetes Pod 进行伸缩。通过 Spin 的 Kubernetes 插件设置 --autoscaler hpa 选项即可启用这种 HPA 伸缩。本页只讨论通过 Spin 的 Kubernetes 插件进行自动伸缩。
spin kube scaffold --from user-name/app-name:latest --autoscaler hpa --cpu-limit 100m --memory-limit 128Mi
Horizontal Pod Autoscaling 是 Kubernetes 的内置功能,无需安装任何第三方运行时。关于使用 HPA 进行伸缩的更多通用信息,请参阅 Spin Operator 的 Scaling with HPA 章节
Kubernetes Event-driven Autoscaling(KEDA)是 Horizontal Pod Autoscaler(HPA)的扩展。除了支持基于 CPU 或内存利用率伸缩之外,KEDA 还支持基于来自各种来源的事件进行伸缩,例如队列中的消息数或数据库中的行数。
通过设置 --autoscaler keda 选项即可启用 KEDA:
spin kube scaffold --from user-name/app-name:latest --autoscaler keda --cpu-limit 100m --memory-limit 128Mi -replicas 1 --max-replicas 10
使用 KEDA 为 Spin 应用做自动伸缩需要先在你的 Kubernetes 集群中安装 KEDA 运行时。关于使用 KEDA 进行伸缩的更多通用信息,请参阅 Spin Operator 的 Scaling with KEDA 章节
可以使用 --replicas 和 --max-replicas 选项来设置应用的最小和最大副本数。--replicas 选项的默认值为 2,--max-replicas 选项的默认值为 3。
spin kube scaffold --from user-name/app-name:latest --autoscaler hpa --cpu-limit 100m --memory-limit 128Mi -replicas 1 --max-replicas 10
如果应用所在节点上的某项资源足够充裕,那么该应用可以(也允许)使用超过其对应资源请求(request)所规定的数量。但是,应用不得使用超过其资源限制(limit)的数量。
举例来说,如果你为应用设置了 256 MiB 的内存请求,而该应用被调度到一个拥有 8GiB 内存且没有其他应用的节点上,那么应用可以尝试使用更多内存。
如果你为该应用设置了 4GiB 的内存限制,WebAssembly 运行时会强制执行这一限制。运行时会阻止应用使用超过所配置资源限制的资源。例如,当应用中的某个进程试图消耗超过允许数量的内存时,WebAssembly 运行时会以内存不足(OOM)错误终止尝试分配内存的那个进程。
可以使用 --cpu-limit、--memory-limit、--cpu-request 和 --memory-request 选项来设置应用的 CPU 与内存限制及请求。--cpu-limit 和 --memory-limit 选项是必需的,而 --cpu-request 和 --memory-request 选项是可选的。
需要注意以下几点:
spin kube scaffold --from user-name/app-name:latest --autoscaler hpa --cpu-limit 100m --memory-limit 128Mi --cpu-request 50m --memory-request 64Mi
目标利用率是指你希望资源被使用到什么百分比时自动伸缩器开始介入。自动伸缩器会将应用当前的资源利用率与目标利用率进行比较,并根据结果扩大或缩小应用的规模。
目标利用率基于应用所有实例的平均资源利用率。例如,如果你的应用有 3 个实例,目标 CPU 利用率为 50%,而每个应用实例的平均 CPU 利用率为 80%,那么自动伸缩器会持续增加实例数量,直到所有实例的平均 CPU 利用率达到 50%。
要基于 CPU 利用率进行伸缩,请使用 --autoscaler-target-cpu-utilization 选项:
spin kube scaffold --from user-name/app-name:latest --autoscaler hpa --cpu-limit 100m --memory-limit 128Mi --autoscaler-target-cpu-utilization 50
要基于内存利用率进行伸缩,请使用 --autoscaler-target-memory-utilization 选项:
spin kube scaffold --from user-name/app-name:latest --autoscaler hpa --cpu-limit 100m --memory-limit 128Mi --autoscaler-target-memory-utilization 50
KEDA 扩展了 Kubernetes,为其提供事件驱动的伸缩能力,使集群能够借助 KEDA
scaler 对来自 Kubernetes 内部或外部源的事件作出反应。KEDA 提供了丰富多样的 scaler,可基于 CPU、内存、Azure Event Hubs、Kafka、RabbitMQ 等各种来源定义伸缩行为。我们将使用 ScaledObject 根据实际需求动态伸缩 SpinApp 的实例数量。
请确保你的本地机器上已安装以下工具:
本教程使用 kind 在本地运行一个 Kubernetes 集群,但你也可以在你自己的 Kubernetes 环境中按照以下步骤配置 KEDA 自动伸缩。
运行以下命令创建一个已安装 containerd-shim-spin 前置依赖的 Kubernetes 集群:如果你已经有一个 Kubernetes 集群,或者希望从一个更接近生产环境的 SpinKube 安装开始,请改用 Helm 安装指南,其中包含配置 Runtime Class Manager 以管理 Spin containerd shim 生命周期的说明。下面的 kind 集群创建命令会建立一个三节点集群,并通过 containerd 配置指示 containerd 对使用 spin runtime class 调度的工作负载使用 Spin containerd shim。我们还暴露了主机端口 8081,以便在后续步骤中更方便地进行负载测试。
cat <<EOF | kind create cluster --name wasm-cluster-scale --image ghcr.io/spinframework/containerd-shim-spin/kind:v0.27.2 --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.cri.v1.runtime".containerd.runtimes.spin]
runtime_type = "io.containerd.spin.v2"
[plugins."io.containerd.cri.v1.runtime".containerd.runtimes.spin.options]
SystemdCgroup = true
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 8081
protocol: TCP
- role: worker
- role: worker
EOF
首先,你需要安装 cert-manager,用于自动供给和管理 TLS 证书(供 Spin Operator 的准入 webhook 系统使用)。详细的安装说明请参阅 cert-manager 文档。
# 安装 cert-manager CRD
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.20.0/cert-manager.crds.yaml
# 添加并更新 Jetstack 仓库
helm repo add jetstack https://charts.jetstack.io
helm repo update
# 安装 cert-manager Helm chart
helm install \
cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace \
--version v1.20.0
接下来,运行以下命令安装 Spin Runtime Class 和 Spin Operator 的自定义资源定义(CRD):
注意:在生产集群中,你通常需要为 Runtime Class 配置一个
nodeSelector,使其匹配已安装 shim 的节点。不过在本例的 kind 集群中,每个节点都安装了 shim。
# 安装 RuntimeClass
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.runtime-class.yaml
# 安装 CRD
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.crds.yaml
最后,使用 helm 和 shim 执行器,通过以下命令安装 Spin Operator:
# 安装 Spin Operator
helm install spin-operator \
--namespace spin-operator \
--create-namespace \
--version 0.6.1 \
--wait \
oci://ghcr.io/spinframework/charts/spin-operator
# 安装 shim 执行器
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.shim-executor.yaml
很好,现在 Spin Operator 已经在你的集群上运行起来了。这意味着你可以在本教程的后续步骤中创建并部署 SpinApp 了。
在你的集群中安装一个 ingress controller。本示例使用 Traefik 作为 Kind 环境中本地路由的 ingress controller。我们要求它运行在暴露 hostPort 的 control-plane 节点上。
helm repo add traefik https://helm.traefik.io/traefik
helm repo update
helm install traefik traefik/traefik \
--namespace traefik --create-namespace \
--set deployment.kind=DaemonSet \
--set service.type=ClusterIP \
--set ports.web.hostPort=80 \
--set tolerations[0].key=node-role.kubernetes.io/control-plane \
--set tolerations[0].effect=NoSchedule \
--set tolerations[0].operator=Exists \
--set nodeSelector."kubernetes\.io/hostname"=wasm-cluster-scale-control-plane
kubectl wait --namespace traefik --for=condition=ready pod --selector=app.kubernetes.io/name=traefik --timeout=180s
使用以下命令在你的 Kubernetes 集群上配置 ingress。这样一旦我们在后续步骤中创建了 Spin 应用,流量就能访问到它:
cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
spec:
ingressClassName: traefik
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: keda-spinapp
port:
number: 80
EOF
使用以下命令通过 Helm 在你的 Kubernetes 集群上安装 KEDA。其他部署方式请参阅 keda.sh 上的 Deploying KEDA:
# 添加 Helm 仓库
helm repo add kedacore https://kedacore.github.io/charts
# 更新你的 Helm 仓库
helm repo update
# 将 keda Helm chart 安装到 keda 命名空间
helm install keda kedacore/keda --namespace keda --create-namespace
接下来,我们要部署将用于伸缩演示的 Spin 应用。你可以在 Spin Operator 仓库的 apps/cpu-load-gen 目录中找到该 Spin 应用的源代码。
我们可以在下面的部署文件中查看 SpinApp 和 KEDA ScaledObject 的定义。如你所见,我们为每个 SpinApp 显式指定了资源上限:cpu 为 500m(spec.resources.limits.cpu)、memory 为 500Mi(spec.resources.limits.memory):
# https://raw.githubusercontent.com/spinframework/spin-operator/main/config/samples/keda-app.yaml
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: keda-spinapp
spec:
image: ghcr.io/spinkube/spin-operator/cpu-load-gen:20240311-163328-g1121986
executor: containerd-shim-spin
enableAutoscaling: true
resources:
limits:
cpu: 500m
memory: 500Mi
requests:
cpu: 100m
memory: 400Mi
---
当 cpu 利用率达到 50%(spec.triggers[cpu].metadata.value)时,我们就会伸缩实例数量。我们还指示 KEDA 在 1(spec.minReplicaCount)到 20(spec.maxReplicaCount)的范围内对 SpinApp 进行水平伸缩:
# https://raw.githubusercontent.com/spinframework/spin-operator/main/config/samples/keda-scaledobject.yaml
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: cpu-scaling
spec:
scaleTargetRef:
name: keda-spinapp
minReplicaCount: 1
maxReplicaCount: 20
triggers:
- type: cpu
metricType: Utilization
metadata:
value: "50"
Kubernetes 文档中有关于 limits 和 requests 的详细介绍。 如需进一步了解 ScaledObject 和 KEDA 内置的 scaler,请查阅 KEDA 文档。
让我们使用以下命令把 SpinApp 和 KEDA ScaledObject 实例部署到集群上:
# 部署 SpinApp
kubectl apply -f https://raw.githubusercontent.com/spinframework/spin-operator/main/config/samples/keda-app.yaml
spinapp.core.spinkube.dev/keda-spinapp created
# 部署 ScaledObject
kubectl apply -f https://raw.githubusercontent.com/spinframework/spin-operator/main/config/samples/keda-scaledobject.yaml
scaledobject.keda.sh/cpu-scaling created
运行以下命令可以查看你正在运行的 Spin 应用:
kubectl get spinapps
NAME READY REPLICAS EXECUTOR
keda-spinapp 1 containerd-shim-spin
你也可以使用以下命令查看你的 KEDA ScaledObject 实例:
kubectl get scaledobject
NAME SCALETARGETKIND SCALETARGETNAME MIN MAX TRIGGERS READY ACTIVE AGE
cpu-scaling apps/v1.Deployment keda-spinapp 1 20 cpu True True 7m
现在,让我们使用 Bombardier 生成流量,测试 KEDA 对 SpinApp 的伸缩效果。下面的 Bombardier 命令会在 3 分钟(或更短时间)内尝试建立 40 个连接。如果某个请求在 5 秒内没有得到响应,该请求将超时:
# 生成大量负载
bombardier -c 40 -t 5s -d 3m http://localhost:8081
为了观察负载情况,我们可以运行以下命令查看部署的状态:
kubectl describe deploy keda-spinapp
...
---
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: keda-spinapp-76db5d7f9f (1/1 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 84s deployment-controller Scaled up replica set hpa-spinapp-76db5d7f9f to 2 from 1
Normal ScalingReplicaSet 69s deployment-controller Scaled up replica set hpa-spinapp-76db5d7f9f to 4 from 2
Normal ScalingReplicaSet 54s deployment-controller Scaled up replica set hpa-spinapp-76db5d7f9f to 8 from 4
Normal ScalingReplicaSet 39s deployment-controller Scaled up replica set hpa-spinapp-76db5d7f9f to 16 from 8
Normal ScalingReplicaSet 24s deployment-controller Scaled up replica set hpa-spinapp-76db5d7f9f to 20 from 16
在 Kubernetes 的语境中,水平伸缩(horizontal scaling)指的是部署更多 Pod 来满足需求(与垂直伸缩不同,后者是为已运行的 Pod 分配更多内存和 CPU 资源)。在本教程中,我们将配置 HPA,根据实际需求动态伸缩 SpinApp 的实例数量。
请确保已安装以下工具:
本教程使用 kind 在本地运行一个 Kubernetes 集群,但你也可以在你自己的 Kubernetes 环境中按照以下步骤配置 HPA 自动伸缩。
运行以下命令创建一个已安装 containerd-shim-spin 前置依赖的 Kubernetes 集群:如果你已经有一个 Kubernetes 集群,或者希望从一个更接近生产环境的 SpinKube 安装开始,请改用 Helm 安装指南,其中包含配置 Runtime Class Manager 以管理 Spin containerd shim 生命周期的说明。下面的 kind 集群创建命令会建立一个三节点集群,并通过 containerd 配置指示 containerd 对使用 spin runtime class 调度的工作负载使用 Spin containerd shim。我们还暴露了主机端口 8081,以便在后续步骤中更方便地进行负载测试。
cat <<EOF | kind create cluster --name wasm-cluster-scale --image ghcr.io/spinframework/containerd-shim-spin/kind:v0.27.2 --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.cri.v1.runtime".containerd.runtimes.spin]
runtime_type = "io.containerd.spin.v2"
[plugins."io.containerd.cri.v1.runtime".containerd.runtimes.spin.options]
SystemdCgroup = true
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 8081
protocol: TCP
- role: worker
- role: worker
EOF
首先,你需要安装 cert-manager,用于自动供给和管理 TLS 证书(供 Spin Operator 的准入 webhook 系统使用)。详细的安装说明请参阅 cert-manager 文档。
# 安装 cert-manager CRD
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.20.0/cert-manager.crds.yaml
# 添加并更新 Jetstack 仓库
helm repo add jetstack https://charts.jetstack.io
helm repo update
# 安装 cert-manager Helm chart
helm install \
cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace \
--version v1.20.0
接下来,运行以下命令安装 Spin Runtime Class 和 Spin Operator 的自定义资源定义(CRD):
注意:在生产集群中,你通常需要为 Runtime Class 配置一个
nodeSelector,使其匹配已安装 shim 的节点。不过在本例的 kind 集群中,每个节点都安装了 shim。
# 安装 RuntimeClass
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.runtime-class.yaml
# 安装 CRD
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.crds.yaml
最后,使用 helm 和 shim 执行器,通过以下命令安装 Spin Operator:
# 安装 Spin Operator
helm install spin-operator \
--namespace spin-operator \
--create-namespace \
--version 0.6.1 \
--wait \
oci://ghcr.io/spinframework/charts/spin-operator
# 安装 shim 执行器
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.shim-executor.yaml
很好,现在 Spin Operator 已经在你的集群上运行起来了。这意味着你可以在本教程的后续步骤中创建并部署 SpinApp 了。
在你的集群中安装一个 ingress controller。本示例使用 Traefik 作为 Kind 环境中本地路由的 ingress controller。我们要求它运行在暴露 hostPort 的 control-plane 节点上。
helm repo add traefik https://helm.traefik.io/traefik
helm repo update
helm install traefik traefik/traefik \
--namespace traefik --create-namespace \
--set deployment.kind=DaemonSet \
--set service.type=ClusterIP \
--set ports.web.hostPort=80 \
--set tolerations[0].key=node-role.kubernetes.io/control-plane \
--set tolerations[0].effect=NoSchedule \
--set tolerations[0].operator=Exists \
--set nodeSelector."kubernetes\.io/hostname"=wasm-cluster-scale-control-plane
kubectl wait --namespace traefik --for=condition=ready pod --selector=app.kubernetes.io/name=traefik --timeout=180s
使用以下命令在你的 Kubernetes 集群上配置 ingress。这样一旦我们在后续步骤中创建了 Spin 应用,流量就能访问到它:
cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
spec:
ingressClassName: traefik
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hpa-spinapp
port:
number: 80
EOF
接下来,我们要部署将用于伸缩演示的 Spin 应用。你可以在 Spin Operator 仓库的 apps/cpu-load-gen 目录中找到该 Spin 应用的源代码。
我们可以在下面的部署文件中查看 SpinApp 和 HPA 的定义。如你所见,我们为每个 Spin 应用设置了 resources -> limits,即 cpu 为 500m、memory 为 500Mi,并将在 cpu 和 memory 利用率达到 50% 时伸缩实例数量。我们还定义了最大
replica 数为 10、最小副本数为 1:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: hpa-spinapp
spec:
image: ghcr.io/spinkube/spin-operator/cpu-load-gen:20240311-163328-g1121986
enableAutoscaling: true
resources:
limits:
cpu: 500m
memory: 500Mi
requests:
cpu: 100m
memory: 400Mi
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: spinapp-autoscaler
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: hpa-spinapp
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
关于 HPA 的更多信息,请访问以下链接:
下面是一个伸缩资源配置的示例:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: hpa-spinapp
spec:
image: ghcr.io/spinkube/spin-operator/cpu-load-gen:20240311-163328-g1121986
executor: containerd-shim-spin
enableAutoscaling: true
resources:
limits:
cpu: 500m
memory: 500Mi
requests:
cpu: 100m
memory: 400Mi
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: spinapp-autoscaler
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: hpa-spinapp
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
让我们把 SpinApp 和 HPA 实例部署到集群上(使用上面的 .yaml 配置)。要应用上述配置,我们使用以下 kubectl apply 命令:
# 安装 SpinApp 和 HPA
kubectl apply -f https://raw.githubusercontent.com/spinframework/spin-operator/main/config/samples/hpa.yaml
运行以下命令可以查看你正在运行的 Spin 应用:
kubectl get spinapps
NAME AGE
hpa-spinapp 92m
你也可以使用以下命令查看你的 HPA 实例:
kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
spinapp-autoscaler Deployment/hpa-spinapp 6%/50% 1 10 1 97m
请注意:Spin 的 Kubernetes 插件 是一个为 Spin 命令行工具提供 Kubernetes 集成能力的工具。Spin 的 Kubernetes 插件提供了一个伸缩教程,演示了如何使用
spin kube命令告诉 Kubernetes 根据需求伸缩(扩大或缩小)你的 Spin 应用。
现在,让我们使用 Bombardier 生成流量,测试 HPA 对 SpinApp 的伸缩效果。下面的 Bombardier 命令会在 3 分钟(或更短时间)内尝试建立 40 个连接。如果某个请求在 5 秒内没有得到响应,该请求将超时:
# 生成大量负载
bombardier -c 40 -t 5s -d 3m http://localhost:8081
为了观察负载情况,我们可以运行以下命令查看部署的状态:
kubectl describe deploy hpa-spinapp
...
---
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: hpa-spinapp-544c649cf4 (1/1 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 11m deployment-controller Scaled up replica set hpa-spinapp-544c649cf4 to 1
Normal ScalingReplicaSet 9m45s deployment-controller Scaled up replica set hpa-spinapp-544c649cf4 to 4
Normal ScalingReplicaSet 9m30s deployment-controller Scaled up replica set hpa-spinapp-544c649cf4 to 8
Normal ScalingReplicaSet 9m15s deployment-controller Scaled up replica set hpa-spinapp-544c649cf4 to 10
Spin Operator 是一个 Kubernetes operator,它让平台工程师能够以自定义资源的形式将 Spin 应用 部署到他们的 Kubernetes 集群中。Spin Operator 为那些希望在不牺牲性能的前提下提升效率、同时保持工作负载可移植性的平台工程师提供了一个优雅的解决方案。
通过将 Spin 框架的能力带入 Kubernetes 集群,Spin Operator 让应用开发者和平台工程师两全其美。对开发者而言,这意味着可以使用 Spin 开发者工具轻松构建可移植的 serverless 函数,并借助 Wasm 的强大能力与卓越性能。对平台工程师而言,则可以使用地道的 Kubernetes 原语(Secret、自动伸缩等)和工具,在生产环境中大规模地管理这些工作负载,从而提升整体运营效率。
Spin Operator 基于 kubebuilder 框架构建,是一个 Kubernetes operator。Kubernetes operator 用于在无需修改 Kubernetes API 的前提下,将 Kubernetes 的自动化能力扩展到以自定义资源形式定义的新对象上。Spin Operator 由两个主要组件构成:

SpinApps CRD 可以手动编写,也可以使用
spin kube scaffold 命令从现有的 Spin 应用自动生成。前一种方式非常适合
CI/CD 系统,而后一种方式则更适合本地开发者工作流中的本地测试。
一旦应用部署开始,Spin Operator 会负责(借助 Runtime Class Manager,其前身为
Kwasm)将工作负载调度到合适的节点上,并管理资源的生命周期。你无需手动获取
containerd-shim-spin 二进制文件,也不需要修改节点标签,这些都由 Runtime
Class Manager 统一管理,它会在你安装 Spin Operator 时作为依赖一并安装。
containerd-shim-spin 是面向
Spin 的一个 containerd
shim 实现,它通过
runwasi 使得在 Kubernetes 上运行 Spin 工作负载成为可能。也就是说,只要将这个
shim 安装到 Kubernetes 节点上,我们就可以向 Kubernetes 添加一个 runtime
class,并将 Spin
工作负载调度到这些节点上。你的 Spin 应用可以像容器工作负载一样运行!
containerd-shim-spin 专门用于执行使用 Spin(一个用于构建和运行 serverless Wasm
应用的开发者工具)构建的应用。该 shim 借助 containerd 的能力,确保 Wasm 工作负载能够在 Kubernetes
环境中得到有效的管理。
在 Kubernetes 集群中,可以为特定节点引导安装 Wasm 运行时,并为其添加相应的标签,以便于 Wasm
工作负载的调度。Kubernetes 中的 RuntimeClasses 用于将 Pod 调度到特定节点并指定特定的运行时。通过定义带有合适
NodeSelector 和 handler 的 RuntimeClass,Kubernetes 可以将 Wasm 工作负载引导到配备了所需 Wasm
运行时的节点上,并确保它们由正确的运行时 handler 执行。
Note: Runtime Class Manager 会根据 Shim 资源中提供的配置,自动创建相应的
RuntimeClass。
总而言之,Containerd Shim Spin 是将 Wasm 工作负载集成到 Kubernetes 集群方面的一项重大进展,它增强了容器编排的多样性与能力。
Runtime Class Manager,又称 Containerd Shim Lifecycle Operator,旨在自动化并管理 Kubernetes 环境中 containerd shim 的生命周期,包括 shim 的安装、更新、移除和配置等任务,从而减少人为失误,提升 WebAssembly(Wasm)工作负载及其他 containerd 扩展管理的可靠性。
Runtime Class Manager 为在 Kubernetes 环境中安装、更新和移除 shim,以及管理节点标签和 runtime class 提供了一个健壮且可用于生产环境的解决方案。
通过自动化这些流程,runtime-class-manager 提升了可靠性,减少了人为失误,并简化了 Kubernetes 集群中 containerd shim 的部署与管理。
Spin 的 Kubernetes 插件 旨在增强 Spin 的能力,使其可以在 Kubernetes 集群内直接执行 Wasm 模块。具体来说,它是一个让 Kubernetes 与 Spin 命令行工具集成的工具。该插件通过对接 containerd shim 进行工作,使 Kubernetes 能够像管理传统容器工作负载那样管理和运行 Wasm 工作负载。
Spin 的 Kubernetes 插件允许开发者使用 Spin 命令行工具部署 Spin 应用,它为在 Kubernetes 环境中构建、推送、部署和管理 Spin 应用提供了无缝的工作流。它包含用于将新组件脚手架生成为 Kubernetes manifest 的命令,以及部署运行在 Kubernetes 中的 Spin 应用并获取其信息的命令。对于希望简化在 Kubernetes 平台上部署 Spin 应用的开发者来说,这款插件是不可或缺的工具。
SpinApp 的自定义资源定义(CRD)参考资源类型:
SpinApp 是 spinapps API 的 Schema
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| apiVersion | string | core.spinkube.dev/v1alpha1 | true |
| kind | string | SpinApp | true |
| metadata | object | 参见 Kubernetes API 文档中 `metadata` 字段的说明。 | true |
| spec | object | SpinAppSpec 定义 SpinApp 的期望状态 | false |
| status | object | SpinAppStatus 定义 SpinApp 的实际状态 | false |
SpinApp.specSpinAppSpec 定义 SpinApp 的期望状态
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| executor | string | Executor 控制此应用在集群中的执行方式。 默认使用集群上可用的 executor。如果有多个可用的 executor,则按字母顺序选择第一个。如果没有可用的 executor,则不设置默认值。 | true |
| image | string | Image 是此应用的来源。 | true |
| checks | object | Checks 定义 Kubernetes 监控应用所使用的健康检查。 | false |
| components | []string | 要执行的应用组件。 如果未提供,则执行所有组件。 | false |
| deploymentAnnotations | map[string]string | DeploymentAnnotations 定义要应用到底层 deployment 的注解。 | false |
| enableAutoscaling | boolean | EnableAutoscaling 指示是否允许应用自动扩缩容。若为 true,operator 会将底层 deployment 的副本数交由外部自动扩缩器(HPA/KEDA)管理。启用此选项时不能再定义 replicas。默认情况下 EnableAutoscaling 为 false。 默认:false | false |
| imagePullSecrets | []object | ImagePullSecrets 是同一命名空间内的 secret 引用列表,用于拉取 image。 | false |
| invocationLimits | map[string]string | InvocationLimits 定义每次调用应用时应用的限制。键为限制的名称,值为限制的值。SpinKube executor 可以定义自己的限制。 | false |
| podAnnotations | map[string]string | PodAnnotations 定义要应用到底层 Pod 的注解。 | false |
| podLabels | map[string]string | PodLabels 定义要应用到底层 Pod 的标签。 | false |
| replicas | integer | 要运行的副本数。 格式:int32 | false |
| resources | object | Resources 定义此应用的资源需求。 | false |
| runtimeConfig | object | RuntimeConfig 定义此应用在运行时应用的配置。 | false |
| serviceAccountName | string | ServiceAccountName 是 Pod 所使用的 Kubernetes service account 的名称。如果未指定,将使用默认的 service account。 | false |
| serviceAnnotations | map[string]string | ServiceAnnotations 定义要应用到底层 service 的注解。 | false |
| variables | []object | Variables 提供从 Kubernetes 到 Spin 应用变量的绑定。 | false |
| volumeMounts | []object | VolumeMounts 定义 volume 在底层容器中的挂载方式。 | false |
| volumes | []object | Volumes 定义要挂载到底层 Pod 的 volume。 | false |
SpinApp.spec.checksChecks 定义 Kubernetes 监控应用所使用的健康检查。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| liveness | object | Liveness 定义应用的存活探针。 | false |
| readiness | object | Readiness 定义应用的就绪探针。 | false |
SpinApp.spec.checks.livenessLiveness 定义应用的存活探针。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| failureThreshold | integer | 探针在成功之后连续失败多少次会被判定为失败。默认为 3。最小值为 1。 格式:int32 默认:3 | false |
| httpGet | object | HTTPGet 描述使用 GET 请求执行的健康检查。 | false |
| initialDelaySeconds | integer | 应用启动后多少秒开始执行存活探针。默认为 10 秒。 格式:int32 默认:10 | false |
| periodSeconds | integer | 执行探针的频率(单位:秒)。默认为 10 秒。最小值为 1。 格式:int32 默认:10 | false |
| successThreshold | integer | 探针在失败之后连续成功多少次会被判定为成功。默认为 1。liveness 和 startup 探针必须为 1。最小值为 1。 格式:int32 默认:1 | false |
| timeoutSeconds | integer | 探针超时的时间(单位:秒)。默认为 1 秒。最小值为 1。 格式:int32 默认:1 | false |
SpinApp.spec.checks.liveness.httpGetHTTPGet 描述使用 GET 请求执行的健康检查。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| path | string | Path 是为健康检查调用应用时使用的路径,例如 /healthz。 | true |
| httpHeaders | []object | HTTPHeaders 是应包含在健康检查请求中的请求头。 | false |
SpinApp.spec.checks.liveness.httpGet.httpHeaders[index]HTTPHealthProbeHeader 是对 HTTP header 键值对的抽象。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | true | |
| value | string | true |
SpinApp.spec.checks.readinessReadiness 定义应用的就绪探针。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| failureThreshold | integer | 探针在成功之后连续失败多少次会被判定为失败。默认为 3。最小值为 1。 格式:int32 默认:3 | false |
| httpGet | object | HTTPGet 描述使用 GET 请求执行的健康检查。 | false |
| initialDelaySeconds | integer | 应用启动后多少秒开始执行存活探针。默认为 10 秒。 格式:int32 默认:10 | false |
| periodSeconds | integer | 执行探针的频率(单位:秒)。默认为 10 秒。最小值为 1。 格式:int32 默认:10 | false |
| successThreshold | integer | 探针在失败之后连续成功多少次会被判定为成功。默认为 1。liveness 和 startup 探针必须为 1。最小值为 1。 格式:int32 默认:1 | false |
| timeoutSeconds | integer | 探针超时的时间(单位:秒)。默认为 1 秒。最小值为 1。 格式:int32 默认:1 | false |
SpinApp.spec.checks.readiness.httpGetHTTPGet 描述使用 GET 请求执行的健康检查。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| path | string | Path 是为健康检查调用应用时使用的路径,例如 /healthz。 | true |
| httpHeaders | []object | HTTPHeaders 是应包含在健康检查请求中的请求头。 | false |
SpinApp.spec.checks.readiness.httpGet.httpHeaders[index]HTTPHealthProbeHeader 是对 HTTP header 键值对的抽象。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | true | |
| value | string | true |
SpinApp.spec.imagePullSecrets[index]LocalObjectReference 包含足够的信息,让你能在同一命名空间内定位被引用的对象。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
SpinApp.spec.resourcesResources 定义此应用的资源需求。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| limits | map[string]int or string | Limits 描述允许的最大计算资源量。 | false |
| requests | map[string]int or string | Requests 描述所需的最小计算资源量。如果容器未指定 Requests,则在显式指定了 Limits 时默认取 Limits 的值,否则取由实现定义的值。Requests 不能超过 Limits。 | false |
SpinApp.spec.runtimeConfigRuntimeConfig 定义此应用在运行时应用的配置。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| keyValueStores | []object | false | |
| llmCompute | object | false | |
| loadFromSecret | string | LoadFromSecret 是从中加载 runtime config 的 secret 的名称。该 secret 应包含一个名为 "runtime-config.toml" 的键,其内容为 base64 编码的 runtime config。如果提供了此字段,将忽略所有其他 runtime config。 | false |
| sqliteDatabases | []object | SqliteDatabases 为不同的 SQLite 数据库提供者提供 spin 绑定,例如 on-disk 或 turso。 | false |
SpinApp.spec.runtimeConfig.keyValueStores[index]| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | true | |
| type | string | true | |
| options | []object | false |
SpinApp.spec.runtimeConfig.keyValueStores[index].options[index]| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 配置项的名称。 | true |
| value | string | Value 是绑定到变量的静态值。 | false |
| valueFrom | object | ValueFrom 是动态绑定变量的引用。 | false |
SpinApp.spec.runtimeConfig.keyValueStores[index].options[index].valueFromValueFrom 是动态绑定变量的引用。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| configMapKeyRef | object | 选择 ConfigMap 的某个键。 | false |
| secretKeyRef | object | 选择应用命名空间内 secret 的某个键 | false |
SpinApp.spec.runtimeConfig.keyValueStores[index].options[index].valueFrom.configMapKeyRef选择 ConfigMap 的某个键。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | 要选择的键。 | true |
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
| optional | boolean | 指定是否必须定义该 ConfigMap 或其键 | false |
SpinApp.spec.runtimeConfig.keyValueStores[index].options[index].valueFrom.secretKeyRef选择应用命名空间内 secret 的某个键
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | 要从中选择的 secret 键。必须是有效的 secret 键。 | true |
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
| optional | boolean | 指定是否必须定义该 Secret 或其键 | false |
SpinApp.spec.runtimeConfig.llmCompute| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| type | string | true | |
| options | []object | false |
SpinApp.spec.runtimeConfig.llmCompute.options[index]| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 配置项的名称。 | true |
| value | string | Value 是绑定到变量的静态值。 | false |
| valueFrom | object | ValueFrom 是动态绑定变量的引用。 | false |
SpinApp.spec.runtimeConfig.llmCompute.options[index].valueFromValueFrom 是动态绑定变量的引用。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| configMapKeyRef | object | 选择 ConfigMap 的某个键。 | false |
| secretKeyRef | object | 选择应用命名空间内 secret 的某个键 | false |
SpinApp.spec.runtimeConfig.llmCompute.options[index].valueFrom.configMapKeyRef选择 ConfigMap 的某个键。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | 要选择的键。 | true |
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
| optional | boolean | 指定是否必须定义该 ConfigMap 或其键 | false |
SpinApp.spec.runtimeConfig.llmCompute.options[index].valueFrom.secretKeyRef选择应用命名空间内 secret 的某个键
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | 要从中选择的 secret 键。必须是有效的 secret 键。 | true |
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
| optional | boolean | 指定是否必须定义该 Secret 或其键 | false |
SpinApp.spec.runtimeConfig.sqliteDatabases[index]| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | true | |
| type | string | true | |
| options | []object | false |
SpinApp.spec.runtimeConfig.sqliteDatabases[index].options[index]| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 配置项的名称。 | true |
| value | string | Value 是绑定到变量的静态值。 | false |
| valueFrom | object | ValueFrom 是动态绑定变量的引用。 | false |
SpinApp.spec.runtimeConfig.sqliteDatabases[index].options[index].valueFromValueFrom 是动态绑定变量的引用。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| configMapKeyRef | object | 选择 ConfigMap 的某个键。 | false |
| secretKeyRef | object | 选择应用命名空间内 secret 的某个键 | false |
SpinApp.spec.runtimeConfig.sqliteDatabases[index].options[index].valueFrom.configMapKeyRef选择 ConfigMap 的某个键。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | 要选择的键。 | true |
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
| optional | boolean | 指定是否必须定义该 ConfigMap 或其键 | false |
SpinApp.spec.runtimeConfig.sqliteDatabases[index].options[index].valueFrom.secretKeyRef选择应用命名空间内 secret 的某个键
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | 要从中选择的 secret 键。必须是有效的 secret 键。 | true |
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
| optional | boolean | 指定是否必须定义该 Secret 或其键 | false |
SpinApp.spec.variables[index]SpinVar 定义 spin 变量与静态值或动态值之间的绑定。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 要绑定的变量名称。 | true |
| value | string | Value 是绑定到变量的静态值。 | false |
| valueFrom | object | ValueFrom 是动态绑定变量的引用。 | false |
SpinApp.spec.variables[index].valueFromValueFrom 是动态绑定变量的引用。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| configMapKeyRef | object | 选择 ConfigMap 的某个键。 | false |
| fieldRef | object | 选择 Pod 的某个字段:支持 metadata.name、metadata.namespace、`metadata.labels[' | false |
| resourceFieldRef | object | 选择容器的某个资源:目前仅支持资源的 limits 和 requests(limits.cpu、limits.memory、limits.ephemeral-storage、requests.cpu、requests.memory 和 requests.ephemeral-storage)。 | false |
| secretKeyRef | object | 选择 Pod 命名空间内 secret 的某个键 | false |
SpinApp.spec.variables[index].valueFrom.configMapKeyRef选择 ConfigMap 的某个键。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | 要选择的键。 | true |
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
| optional | boolean | 指定是否必须定义该 ConfigMap 或其键 | false |
SpinApp.spec.variables[index].valueFrom.fieldRef选择 Pod 的某个字段:支持 metadata.name、metadata.namespace、metadata.labels['<KEY>']、metadata.annotations['<KEY>']、spec.nodeName、spec.serviceAccountName、status.hostIP、status.podIP、status.podIPs。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| fieldPath | string | 在指定 API 版本中要选择的字段路径。 | true |
| apiVersion | string | FieldPath 所基于的 schema 版本,默认为 "v1"。 | false |
SpinApp.spec.variables[index].valueFrom.resourceFieldRef选择容器的某个资源:目前仅支持资源的 limits 和 requests(limits.cpu、limits.memory、limits.ephemeral-storage、requests.cpu、requests.memory 和 requests.ephemeral-storage)。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| resource | string | 必填:要选择的资源 | true |
| containerName | string | 容器名称:对 volume 为必填,对环境变量为可选 | false |
| divisor | int or string | 指定所公开资源的输出格式,默认为 "1" | false |
SpinApp.spec.variables[index].valueFrom.secretKeyRef选择 Pod 命名空间内 secret 的某个键
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | 要从中选择的 secret 键。必须是有效的 secret 键。 | true |
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
| optional | boolean | 指定是否必须定义该 Secret 或其键 | false |
SpinApp.spec.volumeMounts[index]VolumeMount 描述 volume 在容器内的挂载。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| mountPath | string | volume 应挂载到容器内的路径。不得包含 ':'。 | true |
| name | string | 此值必须与某个 Volume 的 Name 匹配。 | true |
| mountPropagation | string | mountPropagation 决定挂载如何在宿主机与容器之间传播。未设置时使用 MountPropagationNone。此字段在 1.10 中为 beta 版。当 RecursiveReadOnly 设置为 IfPossible 或 Enabled 时,MountPropagation 必须为 None 或不指定(默认为 None)。 | false |
| readOnly | boolean | 若为 true 则以只读方式挂载,否则(false 或未指定)以读写方式挂载。默认为 false。 | false |
| recursiveReadOnly | string | RecursiveReadOnly 指定是否以递归方式处理只读挂载。 若 ReadOnly 为 false,此字段无意义且不得指定。 若 ReadOnly 为 true 且此字段设置为 Disabled,则挂载不会被设为递归只读。若此字段设置为 IfPossible,则在容器运行时支持时将挂载设为递归只读。若此字段设置为 Enabled,则在容器运行时支持时将挂载设为递归只读,否则 Pod 不会启动,并会生成错误以说明原因。 若此字段设置为 IfPossible 或 Enabled,则 MountPropagation 必须设置为 None(或不指定,默认为 None)。 若未指定此字段,则视为等同于 Disabled。 | false |
| subPath | string | 从 volume 中挂载容器 volume 的子路径。默认为 “"(volume 的根目录)。 | false |
| subPathExpr | string | 从 volume 中挂载容器 volume 的展开路径。行为与 SubPath 类似,但会使用容器的环境变量展开 $(VAR_NAME) 形式的环境变量引用。默认为 “"(volume 的根目录)。SubPathExpr 与 SubPath 互斥。 | false |
SpinApp.spec.volumes[index]Volume 表示 Pod 中的一个具名 volume,可被 Pod 内的任何容器访问。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | volume 的名称。必须是 DNS_LABEL 且在 Pod 内唯一。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names | true |
| awsElasticBlockStore | object | awsElasticBlockStore 表示挂接到 kubelet 宿主机并随后暴露给 Pod 的 AWS Disk 资源。已弃用:AWSElasticBlockStore 已弃用。树内 awsElasticBlockStore 类型的所有操作都会重定向到 ebs.csi.aws.com CSI 驱动。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore | false |
| azureDisk | object | azureDisk 表示挂载在宿主机并绑定挂载到 Pod 的 Azure Data Disk。已弃用:AzureDisk 已弃用。树内 azureDisk 类型的所有操作都会重定向到 disk.csi.azure.com CSI 驱动。 | false |
| azureFile | object | azureFile 表示挂载在宿主机并绑定挂载到 Pod 的 Azure File Service。已弃用:AzureFile 已弃用。树内 azureFile 类型的所有操作都会重定向到 file.csi.azure.com CSI 驱动。 | false |
| cephfs | object | cephFS 表示与 Pod 生命周期相同的、挂载在宿主机上的 Ceph FS。已弃用:CephFS 已弃用,不再支持树内 cephfs 类型。 | false |
| cinder | object | cinder 表示挂接并挂载在 kubelet 宿主机上的 cinder volume。已弃用:Cinder 已弃用。树内 cinder 类型的所有操作都会重定向到 cinder.csi.openstack.org CSI 驱动。更多信息:https://examples.k8s.io/mysql-cinder-pd/README.md | false |
| configMap | object | configMap 表示应填充此 volume 的 configMap | false |
| csi | object | csi(Container Storage Interface)表示由某些外部 CSI 驱动处理的临时存储。 | false |
| downwardAPI | object | downwardAPI 表示应填充此 volume 的 Pod 相关 downward API 信息 | false |
| emptyDir | object | emptyDir 表示与 Pod 生命周期相同的临时目录。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#emptydir | false |
| ephemeral | object | ephemeral 表示由集群存储驱动处理的 volume。该 volume 的生命周期与定义它的 Pod 绑定——会在 Pod 启动前创建,并在 Pod 删除时删除。 在以下情况使用:a) 仅在 Pod 运行期间需要该 volume;b) 需要普通 volume 的特性(如从快照恢复或容量跟踪);c) 存储驱动通过 storage class 指定;d) 存储驱动支持通过 PersistentVolumeClaim 进行动态卷供给(关于此 volume 类型与 PersistentVolumeClaim 之间关系的更多信息,请参见 EphemeralVolumeSource)。 对于需要比单个 Pod 生命周期更持久存在的 volume,请使用 PersistentVolumeClaim 或特定厂商的 API。 如果 CSI 驱动的设计用途就是轻量本地临时卷,可将其用于此类 volume——更多信息请参见该驱动的文档。 Pod 可以同时使用这两种临时卷和持久卷。 | false |
| fc | object | fc 表示挂接到 kubelet 宿主机并随后暴露给 Pod 的 Fibre Channel 资源。 | false |
| flexVolume | object | flexVolume 表示使用基于 exec 的插件供给/挂接的通用 volume 资源。已弃用:FlexVolume 已弃用。请考虑改用 CSIDriver。 | false |
| flocker | object | flocker 表示挂接到 kubelet 宿主机的 Flocker volume。这依赖 Flocker 控制服务的运行。已弃用:Flocker 已弃用,不再支持树内 flocker 类型。 | false |
| gcePersistentDisk | object | gcePersistentDisk 表示挂接到 kubelet 宿主机并随后暴露给 Pod 的 GCE Disk 资源。已弃用:GCEPersistentDisk 已弃用。树内 gcePersistentDisk 类型的所有操作都会重定向到 pd.csi.storage.gke.io CSI 驱动。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk | false |
| gitRepo | object | gitRepo 表示特定 revision 的 git 仓库。已弃用:GitRepo 已弃用。若要为容器提供 git 仓库,请将一个 EmptyDir 挂载到使用 git 克隆该仓库的 InitContainer,再将该 EmptyDir 挂载到 Pod 的容器中。 | false |
| glusterfs | object | glusterfs 表示与 Pod 生命周期相同的、挂载在宿主机上的 Glusterfs。已弃用:Glusterfs 已弃用,不再支持树内 glusterfs 类型。更多信息:https://examples.k8s.io/volumes/glusterfs/README.md | false |
| hostPath | object | hostPath 表示宿主机上已存在的、直接暴露给容器的文件或目录。这通常供系统代理或其他允许查看宿主机的特权程序使用。大多数容器不需要此类型。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#hostpath | false |
| image | object | image 表示拉取并挂载到 kubelet 宿主机上的 OCI 对象(容器镜像或 artifact)。volume 在 Pod 启动时根据提供的 PullPolicy 值进行解析:
如果 Pod 被删除并重新创建,该 volume 会重新解析,这意味着重新创建 Pod 时新的远端内容将可用。Pod 启动期间解析或拉取镜像失败会阻止容器启动,并可能增加明显的延迟。失败将按常规 volume 回退策略重试,并记录到 Pod 的 reason 和 message 中。此 volume 可挂载的对象类型由宿主机上的容器运行时实现定义,且至少必须包含容器 image 字段所支持的所有有效类型。OCI 对象通过与容器镜像相同的方式合并 manifest 层,挂载到单个目录(spec.containers[].volumeMounts.mountPath)。该 volume 将以只读(ro)且文件不可执行(noexec)的方式挂载。1.33 之前不支持容器的子路径挂载(spec.containers[].volumeMounts.subpath)。字段 spec.securityContext.fsGroupChangePolicy 对此 volume 类型无效。 | false |
| iscsi | object | iscsi 表示挂接到 kubelet 宿主机并随后暴露给 Pod 的 ISCSI Disk 资源。更多信息:https://examples.k8s.io/volumes/iscsi/README.md | false |
| nfs | object | nfs 表示与 Pod 生命周期相同的、挂载在宿主机上的 NFS。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#nfs | false |
| persistentVolumeClaim | object | persistentVolumeClaimVolumeSource 表示对同一命名空间内 PersistentVolumeClaim 的引用。更多信息:https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims | false |
| photonPersistentDisk | object | photonPersistentDisk 表示挂接并挂载在 kubelet 宿主机上的 PhotonController 持久磁盘。已弃用:PhotonPersistentDisk 已弃用,不再支持树内 photonPersistentDisk 类型。 | false |
| portworxVolume | object | portworxVolume 表示挂接并挂载在 kubelet 宿主机上的 portworx volume。已弃用:PortworxVolume 已弃用。当 CSIMigrationPortworx feature-gate 开启时,树内 portworxVolume 类型的所有操作都会重定向到 pxd.portworx.com CSI 驱动。 | false |
| projected | object | 将 secrets、configmaps 和 downward API 等资源一次性投影出来的内容 | false |
| quobyte | object | quobyte 表示与 Pod 生命周期相同的、挂载在宿主机上的 Quobyte。已弃用:Quobyte 已弃用,不再支持树内 quobyte 类型。 | false |
| rbd | object | rbd 表示与 Pod 生命周期相同的、挂载在宿主机上的 Rados Block Device。已弃用:RBD 已弃用,不再支持树内 rbd 类型。更多信息:https://examples.k8s.io/volumes/rbd/README.md | false |
| scaleIO | object | scaleIO 表示挂接并挂载在 Kubernetes 节点上的 ScaleIO 持久卷。已弃用:ScaleIO 已弃用,不再支持树内 scaleIO 类型。 | false |
| secret | object | secret 表示应填充此 volume 的 secret。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#secret | false |
| storageos | object | storageOS 表示挂接并挂载在 Kubernetes 节点上的 StorageOS volume。已弃用:StorageOS 已弃用,不再支持树内 storageos 类型。 | false |
| vsphereVolume | object | vsphereVolume 表示挂接并挂载在 kubelet 宿主机上的 vSphere volume。已弃用:VsphereVolume 已弃用。树内 vsphereVolume 类型的所有操作都会重定向到 csi.vsphere.vmware.com CSI 驱动。 | false |
SpinApp.spec.volumes[index].awsElasticBlockStoreawsElasticBlockStore 表示挂接到 kubelet 宿主机并随后暴露给 Pod 的 AWS Disk 资源。已弃用:AWSElasticBlockStore 已弃用。树内 awsElasticBlockStore 类型的所有操作都会重定向到 ebs.csi.aws.com CSI 驱动。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| volumeID | string | volumeID 是 AWS 中持久磁盘资源(Amazon EBS volume)的唯一 ID。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore | true |
| fsType | string | fsType 是要挂载的 volume 的文件系统类型。提示:请确保宿主机操作系统支持该文件系统类型。示例:"ext4"、"xfs"、"ntfs"。未指定时隐式推断为 "ext4"。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore | false |
| partition | integer | partition 是要挂载的 volume 中的分区。如果省略,默认按 volume 名称挂载。示例:对于 volume /dev/sda1,分区指定为 "1";类似地,/dev/sda 的 volume 分区为 "0"(也可以将该属性留空)。 格式:int32 | false |
| readOnly | boolean | readOnly 值为 true 时将强制在 VolumeMounts 中设置 readOnly。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore | false |
SpinApp.spec.volumes[index].azureDiskazureDisk 表示挂载在宿主机并绑定挂载到 Pod 的 Azure Data Disk。已弃用:AzureDisk 已弃用。树内 azureDisk 类型的所有操作都会重定向到 disk.csi.azure.com CSI 驱动。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| diskName | string | diskName 是 blob 存储中数据磁盘的名称 | true |
| diskURI | string | diskURI 是 blob 存储中数据磁盘的 URI | true |
| cachingMode | string | cachingMode 是主机缓存模式:None、Read Only、Read Write。 | false |
| fsType | string | fsType 是要挂载的文件系统类型。必须是宿主机操作系统支持的文件系统类型。例如 "ext4"、"xfs"、"ntfs"。未指定时隐式推断为 "ext4"。 默认:ext4 | false |
| kind | string | kind 的可选值:Shared——每个存储账户多个 blob 磁盘;Dedicated——每个存储账户单个 blob 磁盘;Managed——azure 托管数据磁盘(仅限托管可用性集)。默认为 shared | false |
| readOnly | boolean | readOnly 默认为 false(读写)。此处设为 ReadOnly 将强制在 VolumeMounts 中设置 ReadOnly。 默认:false | false |
SpinApp.spec.volumes[index].azureFileazureFile 表示挂载在宿主机并绑定挂载到 Pod 的 Azure File Service。已弃用:AzureFile 已弃用。树内 azureFile 类型的所有操作都会重定向到 file.csi.azure.com CSI 驱动。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| secretName | string | secretName 是包含 Azure 存储账户名称和密钥的 secret 的名称 | true |
| shareName | string | shareName 是 azure 共享名称 | true |
| readOnly | boolean | readOnly 默认为 false(读写)。此处设为 ReadOnly 将强制在 VolumeMounts 中设置 ReadOnly。 | false |
SpinApp.spec.volumes[index].cephfscephFS 表示与 Pod 生命周期相同的、挂载在宿主机上的 Ceph FS。已弃用:CephFS 已弃用,不再支持树内 cephfs 类型。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| monitors | []string | monitors 为必填:Monitors 是 Ceph monitor 的集合。更多信息:https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it | true |
| path | string | path 为可选:用作挂载的根目录而非完整的 Ceph 树,默认为 / | false |
| readOnly | boolean | readOnly 为可选:默认为 false(读写)。此处设为 ReadOnly 将强制在 VolumeMounts 中设置 ReadOnly。更多信息:https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it | false |
| secretFile | string | secretFile 为可选:SecretFile 是 User 的 key ring 路径,默认为 /etc/ceph/user.secret。更多信息:https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it | false |
| secretRef | object | secretRef 为可选:SecretRef 是对 User 认证 secret 的引用,默认为空。更多信息:https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it | false |
| user | string | user 为可选:User 是 rados 用户名,默认为 admin。更多信息:https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it | false |
SpinApp.spec.volumes[index].cephfs.secretRefsecretRef 为可选:SecretRef 是对 User 认证 secret 的引用,默认为空。更多信息:https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
SpinApp.spec.volumes[index].cindercinder 表示挂接并挂载在 kubelet 宿主机上的 cinder volume。已弃用:Cinder 已弃用。树内 cinder 类型的所有操作都会重定向到 cinder.csi.openstack.org CSI 驱动。更多信息:https://examples.k8s.io/mysql-cinder-pd/README.md
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| volumeID | string | volumeID 用于在 cinder 中标识该 volume。更多信息:https://examples.k8s.io/mysql-cinder-pd/README.md | true |
| fsType | string | fsType 是要挂载的文件系统类型。必须是宿主机操作系统支持的文件系统类型。示例:"ext4"、"xfs"、"ntfs"。未指定时隐式推断为 "ext4"。更多信息:https://examples.k8s.io/mysql-cinder-pd/README.md | false |
| readOnly | boolean | readOnly 默认为 false(读写)。此处设为 ReadOnly 将强制在 VolumeMounts 中设置 ReadOnly。更多信息:https://examples.k8s.io/mysql-cinder-pd/README.md | false |
| secretRef | object | secretRef 为可选:指向包含连接 OpenStack 所用参数的 secret 对象。 | false |
SpinApp.spec.volumes[index].cinder.secretRefsecretRef 为可选:指向包含连接 OpenStack 所用参数的 secret 对象。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
SpinApp.spec.volumes[index].configMapconfigMap 表示应填充此 volume 的 configMap
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| defaultMode | integer | defaultMode 为可选:默认用于为创建的文件设置权限的 mode 位。必须是 0000 到 0777 之间的八进制值或 0 到 511 之间的十进制值。YAML 同时接受八进制和十进制值,JSON 要求 mode 位使用十进制值。默认为 0644。路径内的目录不受此设置影响。这可能与影响文件 mode 的其他选项(如 fsGroup)冲突,结果可能是设置了其他 mode 位。 格式:int32 | false |
| items | []object | items 如果未指定,被引用 ConfigMap 的 Data 字段中的每个键值对都会以文件形式投影到 volume 中,文件名为键,内容为值。如果指定,则列出的键会被投影到指定的路径,未列出的键不会出现。如果指定的键不存在于 ConfigMap 中,除非标记为可选,volume 设置将报错。路径必须是相对路径,且不得包含 '..' 路径或以 '..' 开头。 | false |
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
| optional | boolean | optional 指定是否必须定义该 ConfigMap 或其键 | false |
SpinApp.spec.volumes[index].configMap.items[index]将字符串键映射到 volume 内的某个路径。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | key 是要投影的键。 | true |
| path | string | path 是将键映射到的文件的相对路径。不得是绝对路径。不得包含路径元素 '..'。不得以字符串 '..' 开头。 | true |
| mode | integer | mode 为可选:用于为此文件设置权限的 mode 位。必须是 0000 到 0777 之间的八进制值或 0 到 511 之间的十进制值。YAML 同时接受八进制和十进制值,JSON 要求 mode 位使用十进制值。如果未指定,将使用 volume 的 defaultMode。这可能与影响文件 mode 的其他选项(如 fsGroup)冲突,结果可能是设置了其他 mode 位。 格式:int32 | false |
SpinApp.spec.volumes[index].csicsi(Container Storage Interface)表示由某些外部 CSI 驱动处理的临时存储。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| driver | string | driver 是处理此 volume 的 CSI 驱动的名称。请向管理员确认在集群中注册的正确名称。 | true |
| fsType | string | 要挂载的 fsType。例如 "ext4"、"xfs"、"ntfs"。如果未提供,空值会传递给关联的 CSI 驱动,由其决定要应用的默认文件系统。 | false |
| nodePublishSecretRef | object | nodePublishSecretRef 是对包含敏感信息的 secret 对象的引用,这些信息会传递给 CSI 驱动以完成 CSI NodePublishVolume 和 NodeUnpublishVolume 调用。此字段为可选,如果不需要 secret 可以为空。如果 secret 对象包含多个 secret,则所有 secret 引用都会被传递。 | false |
| readOnly | boolean | readOnly 指定此 volume 的只读配置。默认为 false(读写)。 | false |
| volumeAttributes | map[string]string | volumeAttributes 存储传递给 CSI 驱动的驱动特定属性。支持哪些值请参见所用驱动的文档。 | false |
SpinApp.spec.volumes[index].csi.nodePublishSecretRefnodePublishSecretRef 是对包含敏感信息的 secret 对象的引用,这些信息会传递给 CSI 驱动以完成 CSI NodePublishVolume 和 NodeUnpublishVolume 调用。此字段为可选,如果不需要 secret 可以为空。如果 secret 对象包含多个 secret,则所有 secret 引用都会被传递。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
SpinApp.spec.volumes[index].downwardAPIdownwardAPI 表示应填充此 volume 的 Pod 相关 downward API 信息
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| defaultMode | integer | 可选:默认用于为创建的文件设置权限的 mode 位。必须是 0000 到 0777 之间的八进制值或 0 到 511 之间的十进制值。YAML 同时接受八进制和十进制值,JSON 要求 mode 位使用十进制值。默认为 0644。路径内的目录不受此设置影响。这可能与影响文件 mode 的其他选项(如 fsGroup)冲突,结果可能是设置了其他 mode 位。 格式:int32 | false |
| items | []object | Items 是 downward API volume 文件的列表 | false |
SpinApp.spec.volumes[index].downwardAPI.items[index]DownwardAPIVolumeFile 表示用于创建包含 Pod 字段的文件的信息。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| path | string | 必填:Path 是要创建的文件的相对路径名。不得是绝对路径或包含 '..' 路径。必须为 utf-8 编码。相对路径的第一项不得以 '..' 开头 | true |
| fieldRef | object | 必填:选择 Pod 的某个字段:仅支持 annotations、labels、name、namespace 和 uid。 | false |
| mode | integer | 可选:用于为此文件设置权限的 mode 位,必须是 0000 到 0777 之间的八进制值或 0 到 511 之间的十进制值。YAML 同时接受八进制和十进制值,JSON 要求 mode 位使用十进制值。如果未指定,将使用 volume 的 defaultMode。这可能与影响文件 mode 的其他选项(如 fsGroup)冲突,结果可能是设置了其他 mode 位。 格式:int32 | false |
| resourceFieldRef | object | 选择容器的某个资源:目前仅支持资源的 limits 和 requests(limits.cpu、limits.memory、requests.cpu 和 requests.memory)。 | false |
SpinApp.spec.volumes[index].downwardAPI.items[index].fieldRef必填:选择 Pod 的某个字段:仅支持 annotations、labels、name、namespace 和 uid。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| fieldPath | string | 在指定 API 版本中要选择的字段路径。 | true |
| apiVersion | string | FieldPath 所基于的 schema 版本,默认为 "v1"。 | false |
SpinApp.spec.volumes[index].downwardAPI.items[index].resourceFieldRef选择容器的某个资源:目前仅支持资源的 limits 和 requests(limits.cpu、limits.memory、requests.cpu 和 requests.memory)。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| resource | string | 必填:要选择的资源 | true |
| containerName | string | 容器名称:对 volume 为必填,对环境变量为可选 | false |
| divisor | int or string | 指定所公开资源的输出格式,默认为 "1" | false |
SpinApp.spec.volumes[index].emptyDiremptyDir 表示与 Pod 生命周期相同的临时目录。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#emptydir
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| medium | string | medium 表示支持此目录的存储介质类型。默认为 "",表示使用节点的默认介质。必须是空字符串(默认)或 Memory。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#emptydir | false |
| sizeLimit | int or string | sizeLimit 是此 EmptyDir volume 所需的本地存储总量。此大小限制同样适用于 memory 介质。memory 介质 EmptyDir 的最大用量为此处指定的 SizeLimit 与 Pod 中所有容器内存 limits 之和中的较小值。默认为 nil,表示未定义限制。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#emptydir | false |
SpinApp.spec.volumes[index].ephemeralephemeral 表示由集群存储驱动处理的 volume。该 volume 的生命周期与定义它的 Pod 绑定——会在 Pod 启动前创建,并在 Pod 删除时删除。
在以下情况使用:a) 仅在 Pod 运行期间需要该 volume;b) 需要普通 volume 的特性(如从快照恢复或容量跟踪);c) 存储驱动通过 storage class 指定;d) 存储驱动支持通过 PersistentVolumeClaim 进行动态卷供给(关于此 volume 类型与 PersistentVolumeClaim 之间关系的更多信息,请参见 EphemeralVolumeSource)。
对于需要比单个 Pod 生命周期更持久存在的 volume,请使用 PersistentVolumeClaim 或特定厂商的 API。
如果 CSI 驱动的设计用途就是轻量本地临时卷,可将其用于此类 volume——更多信息请参见该驱动的文档。
Pod 可以同时使用这两种临时卷和持久卷。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| volumeClaimTemplate | object | 将用于创建独立的 PVC 来供给此 volume。嵌入了此 EphemeralVolumeSource 的 Pod 将成为该 PVC 的所有者,即 PVC 会随 Pod 一起删除。PVC 的名称为 ` 与该 Pod 无关的同名既有 PVC 不会 被该 Pod 使用,以避免误用无关的 volume。此时 Pod 的启动会被阻塞,直到该无关 PVC 被删除。如果此类预先创建的 PVC 本意就是供该 Pod 使用,则必须在 Pod 存在后为该 PVC 添加指向 Pod 的 owner reference。通常没有必要这样做,但在手动重建损坏的集群时可能有用。 此字段为只读,PVC 创建后 Kubernetes 不会对其进行任何更改。 必填,不得为 nil。 | false |
SpinApp.spec.volumes[index].ephemeral.volumeClaimTemplate将用于创建独立的 PVC 来供给此 volume。嵌入了此 EphemeralVolumeSource 的 Pod 将成为该 PVC 的所有者,即 PVC 会随 Pod 一起删除。PVC 的名称为 <pod name>-<volume name>,其中 <volume name> 是 PodSpec.Volumes 数组条目中的名称。如果拼接后的名称对 PVC 无效(例如过长),Pod 校验将拒绝该 Pod。
与该 Pod 无关的同名既有 PVC 不会 被该 Pod 使用,以避免误用无关的 volume。此时 Pod 的启动会被阻塞,直到该无关 PVC 被删除。如果此类预先创建的 PVC 本意就是供该 Pod 使用,则必须在 Pod 存在后为该 PVC 添加指向 Pod 的 owner reference。通常没有必要这样做,但在手动重建损坏的集群时可能有用。
此字段为只读,PVC 创建后 Kubernetes 不会对其进行任何更改。
必填,不得为 nil。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| spec | object | PersistentVolumeClaim 的规格。全部内容会原样复制到根据此模板创建的 PVC 中。PersistentVolumeClaim 中的相同字段在此同样有效。 | true |
| metadata | object | 可以包含在创建 PVC 时复制到其中的标签和注解。不允许其他字段,将在校验时被拒绝。 | false |
SpinApp.spec.volumes[index].ephemeral.volumeClaimTemplate.specPersistentVolumeClaim 的规格。全部内容会原样复制到根据此模板创建的 PVC 中。PersistentVolumeClaim 中的相同字段在此同样有效。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| accessModes | []string | accessModes 包含此 volume 应具有的期望访问模式。更多信息:https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1 | false |
| dataSource | object | dataSource 字段可用于指定以下二者之一:* 已存在的 VolumeSnapshot 对象(snapshot.storage.k8s.io/VolumeSnapshot)* 已存在的 PVC(PersistentVolumeClaim)。如果 provisioner 或外部控制器支持指定的数据源,它将基于指定数据源的内容创建新 volume。启用 AnyVolumeDataSource feature gate 后,dataSource 的内容会被复制到 dataSourceRef;未指定 dataSourceRef.namespace 时,dataSourceRef 的内容会被复制到 dataSource。如果指定了命名空间,则 dataSourceRef 不会被复制到 dataSource。 | false |
| dataSourceRef | object | dataSourceRef 指定在需要非空 volume 时用于填充数据的对象。可以是非空 API 组(非核心对象)中的任何对象,或 PersistentVolumeClaim 对象。指定此字段后,仅当指定对象的类型与某个已安装的 volume populator 或动态 provisioner 匹配时,volume 绑定才会成功。此字段将取代 dataSource 字段的功能,因此如果两个字段都非空,它们的值必须相同。为了向后兼容,当 dataSourceRef 中未指定命名空间时,如果其中一个字段为空而另一个非空,两个字段(dataSource 和 dataSourceRef)将自动设置为相同的值。当在 dataSourceRef 中指定了命名空间时,dataSource 不会被设置为相同的值且必须为空。dataSource 与 dataSourceRef 有三个重要区别:* dataSource 只允许两种特定类型的对象,而 dataSourceRef 允许任何非核心对象以及 PersistentVolumeClaim 对象。* dataSource 会忽略不允许的值(将其丢弃),而 dataSourceRef 会保留所有值,并在出现不允许的值时生成错误。* dataSource 只允许本地对象,而 dataSourceRef 允许任何命名空间中的对象。(Beta) 使用此字段需要启用 AnyVolumeDataSource feature gate。(Alpha) 使用 dataSourceRef 的命名空间字段需要启用 CrossNamespaceVolumeDataSource feature gate。 | false |
| resources | object | resources 表示此 volume 应具有的最小资源。如果启用了 RecoverVolumeExpansionFailure 特性,用户可以指定低于之前值的资源需求,但仍必须高于 claim 的 status 字段中记录的容量。更多信息:https://kubernetes.io/docs/concepts/storage/persistent-volumes#resources | false |
| selector | object | selector 是用于筛选可绑定 volume 的标签查询。 | false |
| storageClassName | string | storageClassName 是此 claim 所需的 StorageClass 的名称。更多信息:https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1 | false |
| volumeAttributesClassName | string | volumeAttributesClassName 可用于设置此 claim 所使用的 VolumeAttributesClass。如果指定,CSI 驱动将使用相应 VolumeAttributesClass 中定义的属性创建或更新 volume。它与 storageClassName 的用途不同,可以在 claim 创建后更改。空字符串值表示不对此 claim 应用任何 VolumeAttributesClass,但一旦设置就不允许将此字段重置为空字符串。如果未指定且 PersistentVolumeClaim 未绑定,则在存在默认 VolumeAttributesClass 时由 persistentvolume controller 设置它。如果 volumeAttributesClass 引用的资源不存在,此 PersistentVolumeClaim 将被设置为 Pending 状态(反映在 modifyVolumeStatus 字段中),直到该资源存在。更多信息:https://kubernetes.io/docs/concepts/storage/volume-attributes-classes/ (Beta) 使用此字段需要启用 VolumeAttributesClass feature gate(默认关闭)。 | false |
| volumeMode | string | volumeMode 定义此 claim 所需的 volume 类型。未包含在 claim spec 中时默认为 Filesystem。 | false |
| volumeName | string | volumeName 是绑定到支持此 claim 的 PersistentVolume 的引用。 | false |
SpinApp.spec.volumes[index].ephemeral.volumeClaimTemplate.spec.dataSourcedataSource 字段可用于指定以下二者之一:* 已存在的 VolumeSnapshot 对象(snapshot.storage.k8s.io/VolumeSnapshot)* 已存在的 PVC(PersistentVolumeClaim)。如果 provisioner 或外部控制器支持指定的数据源,它将基于指定数据源的内容创建新 volume。启用 AnyVolumeDataSource feature gate 后,dataSource 的内容会被复制到 dataSourceRef;未指定 dataSourceRef.namespace 时,dataSourceRef 的内容会被复制到 dataSource。如果指定了命名空间,则 dataSourceRef 不会被复制到 dataSource。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| kind | string | Kind 是被引用资源的类型 | true |
| name | string | Name 是被引用资源的名称 | true |
| apiGroup | string | APIGroup 是被引用资源所属的 API 组。如果未指定 APIGroup,则指定的 Kind 必须位于核心 API 组中。对于任何其他第三方类型,APIGroup 为必填。 | false |
SpinApp.spec.volumes[index].ephemeral.volumeClaimTemplate.spec.dataSourceRefdataSourceRef 指定在需要非空 volume 时用于填充数据的对象。可以是非空 API 组(非核心对象)中的任何对象,或 PersistentVolumeClaim 对象。指定此字段后,仅当指定对象的类型与某个已安装的 volume populator 或动态 provisioner 匹配时,volume 绑定才会成功。此字段将取代 dataSource 字段的功能,因此如果两个字段都非空,它们的值必须相同。为了向后兼容,当 dataSourceRef 中未指定命名空间时,如果其中一个字段为空而另一个非空,两个字段(dataSource 和 dataSourceRef)将自动设置为相同的值。当在 dataSourceRef 中指定了命名空间时,dataSource 不会被设置为相同的值且必须为空。dataSource 与 dataSourceRef 有三个重要区别:* dataSource 只允许两种特定类型的对象,而 dataSourceRef 允许任何非核心对象以及 PersistentVolumeClaim 对象。* dataSource 会忽略不允许的值(将其丢弃),而 dataSourceRef 会保留所有值,并在出现不允许的值时生成错误。* dataSource 只允许本地对象,而 dataSourceRef 允许任何命名空间中的对象。(Beta) 使用此字段需要启用 AnyVolumeDataSource feature gate。(Alpha) 使用 dataSourceRef 的命名空间字段需要启用 CrossNamespaceVolumeDataSource feature gate。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| kind | string | Kind 是被引用资源的类型 | true |
| name | string | Name 是被引用资源的名称 | true |
| apiGroup | string | APIGroup 是被引用资源所属的 API 组。如果未指定 APIGroup,则指定的 Kind 必须位于核心 API 组中。对于任何其他第三方类型,APIGroup 为必填。 | false |
| namespace | string | Namespace 是被引用资源所在的命名空间。注意:指定命名空间时,需要在被引用方的命名空间中存在 gateway.networking.k8s.io/ReferenceGrant 对象,以允许该命名空间的所有者接受该引用。详情参见 ReferenceGrant 文档。(Alpha) 此字段需要启用 CrossNamespaceVolumeDataSource feature gate。 | false |
SpinApp.spec.volumes[index].ephemeral.volumeClaimTemplate.spec.resourcesresources 表示此 volume 应具有的最小资源。如果启用了 RecoverVolumeExpansionFailure 特性,用户可以指定低于之前值的资源需求,但仍必须高于 claim 的 status 字段中记录的容量。更多信息:https://kubernetes.io/docs/concepts/storage/persistent-volumes#resources
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| limits | map[string]int or string | Limits 描述允许的最大计算资源量。更多信息:https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | false |
| requests | map[string]int or string | Requests 描述所需的最小计算资源量。如果容器未指定 Requests,则在显式指定了 Limits 时默认取 Limits 的值,否则取由实现定义的值。Requests 不能超过 Limits。更多信息:https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | false |
SpinApp.spec.volumes[index].ephemeral.volumeClaimTemplate.spec.selectorselector 是用于筛选可绑定 volume 的标签查询。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| matchExpressions | []object | matchExpressions 是标签选择器要求的列表。各要求之间为 AND 关系。 | false |
| matchLabels | map[string]string | matchLabels 是一个 {key,value} 键值对映射。matchLabels 中的单个 {key,value} 等价于 matchExpressions 中的一个元素:其 key 字段为 "key",operator 为 "In",values 数组只包含 "value"。各要求之间为 AND 关系。 | false |
SpinApp.spec.volumes[index].ephemeral.volumeClaimTemplate.spec.selector.matchExpressions[index]标签选择器要求是一个包含值、键以及关联键和值的 operator 的选择器。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | key 是选择器所适用的标签键。 | true |
| operator | string | operator 表示键与一组值之间的关系。有效的 operator 为 In、NotIn、Exists 和 DoesNotExist。 | true |
| values | []string | values 是字符串值数组。如果 operator 为 In 或 NotIn,values 数组不能为空。如果 operator 为 Exists 或 DoesNotExist,values 数组必须为空。此数组在 strategic merge patch 时会被替换。 | false |
SpinApp.spec.volumes[index].fcfc 表示挂接到 kubelet 宿主机并随后暴露给 Pod 的 Fibre Channel 资源。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| fsType | string | fsType 是要挂载的文件系统类型。必须是宿主机操作系统支持的文件系统类型。例如 "ext4"、"xfs"、"ntfs"。未指定时隐式推断为 "ext4"。 | false |
| lun | integer | lun 为可选:FC 目标 lun 编号 格式:int32 | false |
| readOnly | boolean | readOnly 为可选:默认为 false(读写)。此处设为 ReadOnly 将强制在 VolumeMounts 中设置 ReadOnly。 | false |
| targetWWNs | []string | targetWWNs 为可选:FC 目标全球唯一名称(WWN) | false |
| wwids | []string | wwids 为可选:FC volume 的全球唯一标识符(wwid)。必须设置 wwids 或 targetWWNs 与 lun 的组合,但不能同时设置二者。 | false |
SpinApp.spec.volumes[index].flexVolumeflexVolume 表示使用基于 exec 的插件供给/挂接的通用 volume 资源。已弃用:FlexVolume 已弃用。请考虑改用 CSIDriver。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| driver | string | driver 是用于此 volume 的驱动名称。 | true |
| fsType | string | fsType 是要挂载的文件系统类型。必须是宿主机操作系统支持的文件系统类型。例如 "ext4"、"xfs"、"ntfs"。默认文件系统取决于 FlexVolume 脚本。 | false |
| options | map[string]string | options 为可选:此字段保存额外的命令选项(如果有)。 | false |
| readOnly | boolean | readOnly 为可选:默认为 false(读写)。此处设为 ReadOnly 将强制在 VolumeMounts 中设置 ReadOnly。 | false |
| secretRef | object | secretRef 为可选:secretRef 是对包含传递给插件脚本的敏感信息的 secret 对象的引用。如果未指定 secret 对象,可以为空。如果 secret 对象包含多个 secret,则所有 secret 都会传递给插件脚本。 | false |
SpinApp.spec.volumes[index].flexVolume.secretRefsecretRef 为可选:secretRef 是对包含传递给插件脚本的敏感信息的 secret 对象的引用。如果未指定 secret 对象,可以为空。如果 secret 对象包含多个 secret,则所有 secret 都会传递给插件脚本。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
SpinApp.spec.volumes[index].flockerflocker 表示挂接到 kubelet 宿主机的 Flocker volume。这依赖 Flocker 控制服务的运行。已弃用:Flocker 已弃用,不再支持树内 flocker 类型。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| datasetName | string | datasetName 是存储为 Flocker 数据集上 metadata -> name 的数据集名称。应视为已弃用 | false |
| datasetUUID | string | datasetUUID 是数据集的 UUID。这是 Flocker 数据集的唯一标识符 | false |
SpinApp.spec.volumes[index].gcePersistentDiskgcePersistentDisk 表示挂接到 kubelet 宿主机并随后暴露给 Pod 的 GCE Disk 资源。已弃用:GCEPersistentDisk 已弃用。树内 gcePersistentDisk 类型的所有操作都会重定向到 pd.csi.storage.gke.io CSI 驱动。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| pdName | string | pdName 是 GCE 中 PD 资源的唯一名称。用于在 GCE 中标识该磁盘。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk | true |
| fsType | string | fsType 是要挂载的 volume 的文件系统类型。提示:请确保宿主机操作系统支持该文件系统类型。示例:"ext4"、"xfs"、"ntfs"。未指定时隐式推断为 "ext4"。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk | false |
| partition | integer | partition 是要挂载的 volume 中的分区。如果省略,默认按 volume 名称挂载。示例:对于 volume /dev/sda1,分区指定为 "1";类似地,/dev/sda 的 volume 分区为 "0"(也可以将该属性留空)。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk 格式:int32 | false |
| readOnly | boolean | 此处设为 readOnly 将强制在 VolumeMounts 中设置 ReadOnly。默认为 false。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk | false |
SpinApp.spec.volumes[index].gitRepogitRepo 表示特定 revision 的 git 仓库。已弃用:GitRepo 已弃用。若要为容器提供 git 仓库,请将一个 EmptyDir 挂载到使用 git 克隆该仓库的 InitContainer,再将该 EmptyDir 挂载到 Pod 的容器中。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| repository | string | repository 是仓库的 URL | true |
| directory | string | directory 是目标目录名。不得包含 '..' 或以 '..' 开头。如果指定为 '.',volume 目录即为 git 仓库本身;否则,如果指定了名称,volume 将在以该名称命名的子目录中包含 git 仓库。 | false |
| revision | string | revision 是指定 revision 的 commit hash。 | false |
SpinApp.spec.volumes[index].glusterfsglusterfs 表示与 Pod 生命周期相同的、挂载在宿主机上的 Glusterfs。已弃用:Glusterfs 已弃用,不再支持树内 glusterfs 类型。更多信息:https://examples.k8s.io/volumes/glusterfs/README.md
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| endpoints | string | endpoints 是描述 Glusterfs 拓扑的 endpoint 名称。更多信息:https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod | true |
| path | string | path 是 Glusterfs 的 volume 路径。更多信息:https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod | true |
| readOnly | boolean | 此处设为 readOnly 将强制以只读权限挂载 Glusterfs volume。默认为 false。更多信息:https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod | false |
SpinApp.spec.volumes[index].hostPathhostPath 表示宿主机上已存在的、直接暴露给容器的文件或目录。这通常供系统代理或其他允许查看宿主机的特权程序使用。大多数容器不需要此类型。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#hostpath
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| path | string | 宿主机上目录的路径。如果该路径是符号链接,将跟随链接到真实路径。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#hostpath | true |
| type | string | HostPath Volume 的类型,默认为 ""。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#hostpath | false |
SpinApp.spec.volumes[index].imageimage 表示拉取并挂载到 kubelet 宿主机上的 OCI 对象(容器镜像或 artifact)。volume 在 Pod 启动时根据提供的 PullPolicy 值进行解析:
如果 Pod 被删除并重新创建,该 volume 会重新解析,这意味着重新创建 Pod 时新的远端内容将可用。Pod 启动期间解析或拉取镜像失败会阻止容器启动,并可能增加明显的延迟。失败将按常规 volume 回退策略重试,并记录到 Pod 的 reason 和 message 中。此 volume 可挂载的对象类型由宿主机上的容器运行时实现定义,且至少必须包含容器 image 字段所支持的所有有效类型。OCI 对象通过与容器镜像相同的方式合并 manifest 层,挂载到单个目录(spec.containers[].volumeMounts.mountPath)。该 volume 将以只读(ro)且文件不可执行(noexec)的方式挂载。1.33 之前不支持容器的子路径挂载(spec.containers[].volumeMounts.subpath)。字段 spec.securityContext.fsGroupChangePolicy 对此 volume 类型无效。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| pullPolicy | string | 拉取 OCI 对象的策略。可选值为:Always——kubelet 始终尝试拉取该引用,如果拉取失败,容器创建将失败;Never——kubelet 从不拉取该引用,仅使用本地镜像或 artifact,如果该引用不存在,容器创建将失败;IfNotPresent——如果磁盘上尚不存在该引用,kubelet 会进行拉取,如果该引用不存在且拉取失败,容器创建将失败。指定了 :latest 标签时默认为 Always,否则默认为 IfNotPresent。 | false |
| reference | string | 必填:要使用的镜像或 artifact 引用。行为与 pod.spec.containers[*].image 相同。Pull secret 的组装方式与容器镜像相同,会查找节点凭据、SA image pull secret 以及 pod spec 中的 image pull secret。此字段为可选,以便更高层的配置管理能在 Deployments 和 StatefulSets 等工作负载控制器中设置默认值或覆盖容器镜像。更多信息:https://kubernetes.io/docs/concepts/containers/images | false |
SpinApp.spec.volumes[index].iscsiiscsi 表示挂接到 kubelet 宿主机并随后暴露给 Pod 的 ISCSI Disk 资源。更多信息:https://examples.k8s.io/volumes/iscsi/README.md
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| iqn | string | iqn 是目标端的 iSCSI Qualified Name。 | true |
| lun | integer | lun 表示 iSCSI 目标的 Lun 编号。 格式:int32 | true |
| targetPortal | string | targetPortal 是 iSCSI 目标 Portal。Portal 为 IP 或 ip_addr:port(端口不是默认端口时,通常为 TCP 端口 860 和 3260)。 | true |
| chapAuthDiscovery | boolean | chapAuthDiscovery 定义是否支持 iSCSI Discovery CHAP 认证 | false |
| chapAuthSession | boolean | chapAuthSession 定义是否支持 iSCSI Session CHAP 认证 | false |
| fsType | string | fsType 是要挂载的 volume 的文件系统类型。提示:请确保宿主机操作系统支持该文件系统类型。示例:"ext4"、"xfs"、"ntfs"。未指定时隐式推断为 "ext4"。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#iscsi | false |
| initiatorName | string | initiatorName 是自定义的 iSCSI Initiator Name。如果同时指定了 initiatorName 和 iscsiInterface,将为该连接创建新的 iSCSI 接口 | false |
| iscsiInterface | string | iscsiInterface 是使用 iSCSI 传输的接口名称。默认为 'default'(tcp)。 默认:default | false |
| portals | []string | portals 是 iSCSI 目标 Portal 列表。Portal 为 IP 或 ip_addr:port(端口不是默认端口时,通常为 TCP 端口 860 和 3260)。 | false |
| readOnly | boolean | 此处设为 readOnly 将强制在 VolumeMounts 中设置 ReadOnly。默认为 false。 | false |
| secretRef | object | secretRef 是用于 iSCSI 目标与发起方认证的 CHAP Secret | false |
SpinApp.spec.volumes[index].iscsi.secretRefsecretRef 是用于 iSCSI 目标与发起方认证的 CHAP Secret
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
SpinApp.spec.volumes[index].nfsnfs 表示与 Pod 生命周期相同的、挂载在宿主机上的 NFS。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#nfs
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| path | string | 由 NFS 服务器导出的路径。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#nfs | true |
| server | string | server 是 NFS 服务器的主机名或 IP 地址。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#nfs | true |
| readOnly | boolean | 此处设为 readOnly 将强制以只读权限挂载 NFS 导出。默认为 false。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#nfs | false |
SpinApp.spec.volumes[index].persistentVolumeClaimpersistentVolumeClaimVolumeSource 表示对同一命名空间内 PersistentVolumeClaim 的引用。更多信息:https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| claimName | string | claimName 是与使用此 volume 的 Pod 位于同一命名空间内的 PersistentVolumeClaim 的名称。更多信息:https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims | true |
| readOnly | boolean | readOnly 将强制在 VolumeMounts 中设置 ReadOnly。默认为 false。 | false |
SpinApp.spec.volumes[index].photonPersistentDiskphotonPersistentDisk 表示挂接并挂载在 kubelet 宿主机上的 PhotonController 持久磁盘。已弃用:PhotonPersistentDisk 已弃用,不再支持树内 photonPersistentDisk 类型。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| pdID | string | pdID 是标识 Photon Controller 持久磁盘的 ID | true |
| fsType | string | fsType 是要挂载的文件系统类型。必须是宿主机操作系统支持的文件系统类型。例如 "ext4"、"xfs"、"ntfs"。未指定时隐式推断为 "ext4"。 | false |
SpinApp.spec.volumes[index].portworxVolumeportworxVolume 表示挂接并挂载在 kubelet 宿主机上的 portworx volume。已弃用:PortworxVolume 已弃用。当 CSIMigrationPortworx feature-gate 开启时,树内 portworxVolume 类型的所有操作都会重定向到 pxd.portworx.com CSI 驱动。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| volumeID | string | volumeID 唯一标识一个 Portworx volume | true |
| fsType | string | fSType 表示要挂载的文件系统类型。必须是宿主机操作系统支持的文件系统类型。例如 "ext4"、"xfs"。未指定时隐式推断为 "ext4"。 | false |
| readOnly | boolean | readOnly 默认为 false(读写)。此处设为 ReadOnly 将强制在 VolumeMounts 中设置 ReadOnly。 | false |
SpinApp.spec.volumes[index].projected将 secrets、configmaps 和 downward API 等资源一次性投影出来的内容
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| defaultMode | integer | defaultMode 是默认用于为创建的文件设置权限的 mode 位。必须是 0000 到 0777 之间的八进制值或 0 到 511 之间的十进制值。YAML 同时接受八进制和十进制值,JSON 要求 mode 位使用十进制值。路径内的目录不受此设置影响。这可能与影响文件 mode 的其他选项(如 fsGroup)冲突,结果可能是设置了其他 mode 位。 格式:int32 | false |
| sources | []object | sources 是 volume 投影的列表。此列表中的每个条目处理一个来源。 | false |
SpinApp.spec.volumes[index].projected.sources[index]可与其他受支持的 volume 类型一起投影的投影项。这些字段必须恰好设置一个。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| clusterTrustBundle | object | ClusterTrustBundle 允许 Pod 通过自动更新的文件访问 ClusterTrustBundle 对象的 `.spec.trustBundle` 字段。 Alpha 阶段,由 ClusterTrustBundleProjection feature gate 控制。 ClusterTrustBundle 对象可以按名称选择,也可以按签名者名称与标签选择器的组合选择。 Kubelet 会对写入 Pod 文件系统的 PEM 内容执行严格的规范化。诸如块间注释和块头等特殊 PEM 特性会被剥离。证书会被去重。文件内证书的顺序是任意的,Kubelet 可能会随时间改变其顺序。 | false |
| configMap | object | configMap 是要投影的 configMap 数据的相关信息 | false |
| downwardAPI | object | downwardAPI 是要投影的 downwardAPI 数据的相关信息 | false |
| secret | object | secret 是要投影的 secret 数据的相关信息 | false |
| serviceAccountToken | object | serviceAccountToken 是要投影的 serviceAccountToken 数据的相关信息 | false |
SpinApp.spec.volumes[index].projected.sources[index].clusterTrustBundleClusterTrustBundle 允许 Pod 通过自动更新的文件访问 ClusterTrustBundle 对象的 .spec.trustBundle 字段。
Alpha 阶段,由 ClusterTrustBundleProjection feature gate 控制。
ClusterTrustBundle 对象可以按名称选择,也可以按签名者名称与标签选择器的组合选择。
Kubelet 会对写入 Pod 文件系统的 PEM 内容执行严格的规范化。诸如块间注释和块头等特殊 PEM 特性会被剥离。证书会被去重。文件内证书的顺序是任意的,Kubelet 可能会随时间改变其顺序。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| path | string | 从 volume 根目录写入 bundle 的相对路径。 | true |
| labelSelector | object | 选择所有与此标签选择器匹配的 ClusterTrustBundle。仅在设置了 signerName 时生效。与 name 互斥。如果未设置,解释为"不匹配任何内容"。如果设置但为空,解释为"匹配所有内容"。 | false |
| name | string | 按对象名称选择单个 ClusterTrustBundle。与 signerName 和 labelSelector 互斥。 | false |
| optional | boolean | 若为 true,则在所引用的 ClusterTrustBundle 不可用时不阻塞 Pod 启动。如果使用 name,则允许该命名的 ClusterTrustBundle 不存在。如果使用 signerName,则允许 signerName 与 labelSelector 的组合匹配零个 ClusterTrustBundle。 | false |
| signerName | string | 选择所有与此签名者名称匹配的 ClusterTrustBundle。与 name 互斥。所有被选中的 ClusterTrustBundle 的内容将被合并并去重。 | false |
SpinApp.spec.volumes[index].projected.sources[index].clusterTrustBundle.labelSelector选择所有与此标签选择器匹配的 ClusterTrustBundle。仅在设置了 signerName 时生效。与 name 互斥。如果未设置,解释为"不匹配任何内容”。如果设置但为空,解释为"匹配所有内容”。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| matchExpressions | []object | matchExpressions 是标签选择器要求的列表。各要求之间为 AND 关系。 | false |
| matchLabels | map[string]string | matchLabels 是一个 {key,value} 键值对映射。matchLabels 中的单个 {key,value} 等价于 matchExpressions 中的一个元素:其 key 字段为 "key",operator 为 "In",values 数组只包含 "value"。各要求之间为 AND 关系。 | false |
SpinApp.spec.volumes[index].projected.sources[index].clusterTrustBundle.labelSelector.matchExpressions[index]标签选择器要求是一个包含值、键以及关联键和值的 operator 的选择器。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | key 是选择器所适用的标签键。 | true |
| operator | string | operator 表示键与一组值之间的关系。有效的 operator 为 In、NotIn、Exists 和 DoesNotExist。 | true |
| values | []string | values 是字符串值数组。如果 operator 为 In 或 NotIn,values 数组不能为空。如果 operator 为 Exists 或 DoesNotExist,values 数组必须为空。此数组在 strategic merge patch 时会被替换。 | false |
SpinApp.spec.volumes[index].projected.sources[index].configMapconfigMap 是要投影的 configMap 数据的相关信息
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| items | []object | items 如果未指定,被引用 ConfigMap 的 Data 字段中的每个键值对都会以文件形式投影到 volume 中,文件名为键,内容为值。如果指定,则列出的键会被投影到指定的路径,未列出的键不会出现。如果指定的键不存在于 ConfigMap 中,除非标记为可选,volume 设置将报错。路径必须是相对路径,且不得包含 '..' 路径或以 '..' 开头。 | false |
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
| optional | boolean | optional 指定是否必须定义该 ConfigMap 或其键 | false |
SpinApp.spec.volumes[index].projected.sources[index].configMap.items[index]将字符串键映射到 volume 内的某个路径。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | key 是要投影的键。 | true |
| path | string | path 是将键映射到的文件的相对路径。不得是绝对路径。不得包含路径元素 '..'。不得以字符串 '..' 开头。 | true |
| mode | integer | mode 为可选:用于为此文件设置权限的 mode 位。必须是 0000 到 0777 之间的八进制值或 0 到 511 之间的十进制值。YAML 同时接受八进制和十进制值,JSON 要求 mode 位使用十进制值。如果未指定,将使用 volume 的 defaultMode。这可能与影响文件 mode 的其他选项(如 fsGroup)冲突,结果可能是设置了其他 mode 位。 格式:int32 | false |
SpinApp.spec.volumes[index].projected.sources[index].downwardAPIdownwardAPI 是要投影的 downwardAPI 数据的相关信息
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| items | []object | Items 是 DownwardAPIVolume 文件的列表 | false |
SpinApp.spec.volumes[index].projected.sources[index].downwardAPI.items[index]DownwardAPIVolumeFile 表示用于创建包含 Pod 字段的文件的信息。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| path | string | 必填:Path 是要创建的文件的相对路径名。不得是绝对路径或包含 '..' 路径。必须为 utf-8 编码。相对路径的第一项不得以 '..' 开头 | true |
| fieldRef | object | 必填:选择 Pod 的某个字段:仅支持 annotations、labels、name、namespace 和 uid。 | false |
| mode | integer | 可选:用于为此文件设置权限的 mode 位,必须是 0000 到 0777 之间的八进制值或 0 到 511 之间的十进制值。YAML 同时接受八进制和十进制值,JSON 要求 mode 位使用十进制值。如果未指定,将使用 volume 的 defaultMode。这可能与影响文件 mode 的其他选项(如 fsGroup)冲突,结果可能是设置了其他 mode 位。 格式:int32 | false |
| resourceFieldRef | object | 选择容器的某个资源:目前仅支持资源的 limits 和 requests(limits.cpu、limits.memory、requests.cpu 和 requests.memory)。 | false |
SpinApp.spec.volumes[index].projected.sources[index].downwardAPI.items[index].fieldRef必填:选择 Pod 的某个字段:仅支持 annotations、labels、name、namespace 和 uid。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| fieldPath | string | 在指定 API 版本中要选择的字段路径。 | true |
| apiVersion | string | FieldPath 所基于的 schema 版本,默认为 "v1"。 | false |
SpinApp.spec.volumes[index].projected.sources[index].downwardAPI.items[index].resourceFieldRef选择容器的某个资源:目前仅支持资源的 limits 和 requests(limits.cpu、limits.memory、requests.cpu 和 requests.memory)。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| resource | string | 必填:要选择的资源 | true |
| containerName | string | 容器名称:对 volume 为必填,对环境变量为可选 | false |
| divisor | int or string | 指定所公开资源的输出格式,默认为 "1" | false |
SpinApp.spec.volumes[index].projected.sources[index].secretsecret 是要投影的 secret 数据的相关信息
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| items | []object | items 如果未指定,被引用 Secret 的 Data 字段中的每个键值对都会以文件形式投影到 volume 中,文件名为键,内容为值。如果指定,则列出的键会被投影到指定的路径,未列出的键不会出现。如果指定的键不存在于 Secret 中,除非标记为可选,volume 设置将报错。路径必须是相对路径,且不得包含 '..' 路径或以 '..' 开头。 | false |
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
| optional | boolean | optional 字段指定是否必须定义该 Secret 或其键 | false |
SpinApp.spec.volumes[index].projected.sources[index].secret.items[index]将字符串键映射到 volume 内的某个路径。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | key 是要投影的键。 | true |
| path | string | path 是将键映射到的文件的相对路径。不得是绝对路径。不得包含路径元素 '..'。不得以字符串 '..' 开头。 | true |
| mode | integer | mode 为可选:用于为此文件设置权限的 mode 位。必须是 0000 到 0777 之间的八进制值或 0 到 511 之间的十进制值。YAML 同时接受八进制和十进制值,JSON 要求 mode 位使用十进制值。如果未指定,将使用 volume 的 defaultMode。这可能与影响文件 mode 的其他选项(如 fsGroup)冲突,结果可能是设置了其他 mode 位。 格式:int32 | false |
SpinApp.spec.volumes[index].projected.sources[index].serviceAccountTokenserviceAccountToken 是要投影的 serviceAccountToken 数据的相关信息
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| path | string | path 是相对于挂载点、用于投影 token 的文件路径。 | true |
| audience | string | audience 是 token 的预期受众。token 的接收方必须以 token audience 中指定的标识符表明身份,否则应拒绝该 token。audience 默认为 apiserver 的标识符。 | false |
| expirationSeconds | integer | expirationSeconds 是所请求的 service account token 的有效期。随着 token 接近过期,kubelet volume 插件会主动轮换该 token。如果 token 的存活时间超过其 TTL 的 80% 或超过 24 小时,kubelet 将开始尝试轮换该 token。默认为 1 小时,且不得少于 10 分钟。 格式:int64 | false |
SpinApp.spec.volumes[index].quobytequobyte 表示与 Pod 生命周期相同的、挂载在宿主机上的 Quobyte。已弃用:Quobyte 已弃用,不再支持树内 quobyte 类型。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| registry | string | registry 表示一个或多个 Quobyte Registry 服务,以字符串形式的 host:port 对指定(多个条目用逗号分隔),作为 volume 的中央注册表 | true |
| volume | string | volume 是按名称引用已创建的 Quobyte volume 的字符串。 | true |
| group | string | 映射 volume 访问权限的组。默认为无组 | false |
| readOnly | boolean | 此处设为 readOnly 将强制以只读权限挂载 Quobyte volume。默认为 false。 | false |
| tenant | string | 在后端拥有给定 Quobyte volume 的租户。与动态供给的 Quobyte volume 一起使用,其值由插件设置 | false |
| user | string | 映射 volume 访问权限的用户。默认为 service account 用户 | false |
SpinApp.spec.volumes[index].rbdrbd 表示与 Pod 生命周期相同的、挂载在宿主机上的 Rados Block Device。已弃用:RBD 已弃用,不再支持树内 rbd 类型。更多信息:https://examples.k8s.io/volumes/rbd/README.md
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| image | string | image 是 rados 镜像名称。更多信息:https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it | true |
| monitors | []string | monitors 是 Ceph monitor 的集合。更多信息:https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it | true |
| fsType | string | fsType 是要挂载的 volume 的文件系统类型。提示:请确保宿主机操作系统支持该文件系统类型。示例:"ext4"、"xfs"、"ntfs"。未指定时隐式推断为 "ext4"。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#rbd | false |
| keyring | string | keyring 是 RBDUser 的 key ring 路径。默认为 /etc/ceph/keyring。更多信息:https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it 默认:/etc/ceph/keyring | false |
| pool | string | pool 是 rados pool 的名称。默认为 rbd。更多信息:https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it 默认:rbd | false |
| readOnly | boolean | 此处设为 readOnly 将强制在 VolumeMounts 中设置 ReadOnly。默认为 false。更多信息:https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it | false |
| secretRef | object | secretRef 是 RBDUser 认证 secret 的名称。如果提供,将覆盖 keyring。默认为 nil。更多信息:https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it | false |
| user | string | user 是 rados 用户名。默认为 admin。更多信息:https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it 默认:admin | false |
SpinApp.spec.volumes[index].rbd.secretRefsecretRef 是 RBDUser 认证 secret 的名称。如果提供,将覆盖 keyring。默认为 nil。更多信息:https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
SpinApp.spec.volumes[index].scaleIOscaleIO 表示挂接并挂载在 Kubernetes 节点上的 ScaleIO 持久卷。已弃用:ScaleIO 已弃用,不再支持树内 scaleIO 类型。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| gateway | string | gateway 是 ScaleIO API Gateway 的主机地址。 | true |
| secretRef | object | secretRef 引用包含 ScaleIO 用户及其他敏感信息的 secret。如果未提供,Login 操作将失败。 | true |
| system | string | system 是在 ScaleIO 中配置的存储系统的名称。 | true |
| fsType | string | fsType 是要挂载的文件系统类型。必须是宿主机操作系统支持的文件系统类型。例如 "ext4"、"xfs"、"ntfs"。默认为 "xfs"。 默认:xfs | false |
| protectionDomain | string | protectionDomain 是所配置存储的 ScaleIO Protection Domain 的名称。 | false |
| readOnly | boolean | readOnly 默认为 false(读写)。此处设为 ReadOnly 将强制在 VolumeMounts 中设置 ReadOnly。 | false |
| sslEnabled | boolean | sslEnabled 标志用于启用/禁用与 Gateway 的 SSL 通信,默认为 false | false |
| storageMode | string | storageMode 指示 volume 的存储应采用 ThickProvisioned 还是 ThinProvisioned。默认为 ThinProvisioned。 默认:ThinProvisioned | false |
| storagePool | string | storagePool 是与保护域关联的 ScaleIO Storage Pool。 | false |
| volumeName | string | volumeName 是已在 ScaleIO 系统中创建的、与此 volume 源关联的 volume 的名称。 | false |
SpinApp.spec.volumes[index].scaleIO.secretRefsecretRef 引用包含 ScaleIO 用户及其他敏感信息的 secret。如果未提供,Login 操作将失败。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
SpinApp.spec.volumes[index].secretsecret 表示应填充此 volume 的 secret。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#secret
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| defaultMode | integer | defaultMode 为可选:默认用于为创建的文件设置权限的 mode 位。必须是 0000 到 0777 之间的八进制值或 0 到 511 之间的十进制值。YAML 同时接受八进制和十进制值,JSON 要求 mode 位使用十进制值。默认为 0644。路径内的目录不受此设置影响。这可能与影响文件 mode 的其他选项(如 fsGroup)冲突,结果可能是设置了其他 mode 位。 格式:int32 | false |
| items | []object | items 如果未指定,被引用 Secret 的 Data 字段中的每个键值对都会以文件形式投影到 volume 中,文件名为键,内容为值。如果指定,则列出的键会被投影到指定的路径,未列出的键不会出现。如果指定的键不存在于 Secret 中,除非标记为可选,volume 设置将报错。路径必须是相对路径,且不得包含 '..' 路径或以 '..' 开头。 | false |
| optional | boolean | optional 字段指定是否必须定义该 Secret 或其键 | false |
| secretName | string | secretName 是要使用的、位于 Pod 命名空间内的 secret 的名称。更多信息:https://kubernetes.io/docs/concepts/storage/volumes#secret | false |
SpinApp.spec.volumes[index].secret.items[index]将字符串键映射到 volume 内的某个路径。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| key | string | key 是要投影的键。 | true |
| path | string | path 是将键映射到的文件的相对路径。不得是绝对路径。不得包含路径元素 '..'。不得以字符串 '..' 开头。 | true |
| mode | integer | mode 为可选:用于为此文件设置权限的 mode 位。必须是 0000 到 0777 之间的八进制值或 0 到 511 之间的十进制值。YAML 同时接受八进制和十进制值,JSON 要求 mode 位使用十进制值。如果未指定,将使用 volume 的 defaultMode。这可能与影响文件 mode 的其他选项(如 fsGroup)冲突,结果可能是设置了其他 mode 位。 格式:int32 | false |
SpinApp.spec.volumes[index].storageosstorageOS 表示挂接并挂载在 Kubernetes 节点上的 StorageOS volume。已弃用:StorageOS 已弃用,不再支持树内 storageos 类型。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| fsType | string | fsType 是要挂载的文件系统类型。必须是宿主机操作系统支持的文件系统类型。例如 "ext4"、"xfs"、"ntfs"。未指定时隐式推断为 "ext4"。 | false |
| readOnly | boolean | readOnly 默认为 false(读写)。此处设为 ReadOnly 将强制在 VolumeMounts 中设置 ReadOnly。 | false |
| secretRef | object | secretRef 指定用于获取 StorageOS API 凭据的 secret。如果未指定,将尝试默认值。 | false |
| volumeName | string | volumeName 是 StorageOS volume 的可读名称。volume 名称仅在命名空间内唯一。 | false |
| volumeNamespace | string | volumeNamespace 指定 volume 在 StorageOS 中的作用域。如果未指定命名空间,则使用 Pod 的命名空间。这允许将 Kubernetes 的名称作用域映射到 StorageOS 中,以实现更紧密的集成。将 VolumeName 设置为任意名称即可覆盖默认行为。如果在 StorageOS 中未使用命名空间,请设置为 "default"。StorageOS 中预先不存在的命名空间将被创建。 | false |
SpinApp.spec.volumes[index].storageos.secretRefsecretRef 指定用于获取 StorageOS API 凭据的 secret。如果未指定,将尝试默认值。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| name | string | 被引用对象的名称。此字段实际上是必填的,但出于向后兼容的考虑,允许为空。此处为空值的实例几乎可以肯定是错误的。更多信息:https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 默认: | false |
SpinApp.spec.volumes[index].vsphereVolumevsphereVolume 表示挂接并挂载在 kubelet 宿主机上的 vSphere volume。已弃用:VsphereVolume 已弃用。树内 vsphereVolume 类型的所有操作都会重定向到 csi.vsphere.vmware.com CSI 驱动。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| volumePath | string | volumePath 是标识 vSphere volume vmdk 的路径 | true |
| fsType | string | fsType 是要挂载的文件系统类型。必须是宿主机操作系统支持的文件系统类型。例如 "ext4"、"xfs"、"ntfs"。未指定时隐式推断为 "ext4"。 | false |
| storagePolicyID | string | storagePolicyID 是与 StoragePolicyName 关联的存储策略管理(SPBM)配置文件 ID。 | false |
| storagePolicyName | string | storagePolicyName 是存储策略管理(SPBM)配置文件的名称。 | false |
SpinApp.statusSpinAppStatus 定义 SpinApp 的实际状态
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| readyReplicas | integer | 表示应用 deployment 上当前活跃副本的数量。 格式:int32 | true |
| activeScheduler | string | ActiveScheduler 是当前正在调度此 SpinApp 的调度器名称。 | false |
| conditions | []object | 表示对 SpinApp 当前状态的观测。SpinApp.status.conditions.type 包括:"Available" 和 "Progressing"。SpinApp.status.conditions.status 为 True、False、Unknown 之一。SpinApp.status.conditions.reason 的值应为 CamelCase 字符串,特定条件类型的生产者可以为此字段定义期望的值和含义,以及这些值是否被视为有保证的 API。SpinApp.status.conditions.Message 是人类可读的消息,用于说明状态转换的详情。更多信息参见:https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties | false |
SpinApp.status.conditions[index]Condition 包含此 API 资源当前状态某一方面的详细信息。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| lastTransitionTime | string | lastTransitionTime 是条件最近一次从一种状态转换到另一种状态的时间。应为底层条件发生变化的时间。如果无法确定,则使用 API 字段发生变化的时间也可接受。 格式:date-time | true |
| message | string | message 是人类可读的消息,用于说明状态转换的详情。可以为空字符串。 | true |
| reason | string | reason 包含一个程序化标识符,用于说明条件最近一次转换的原因。特定条件类型的生产者可以为此字段定义期望的值和含义,以及这些值是否被视为有保证的 API。值应为 CamelCase 字符串。此字段不得为空。 | true |
| status | enum | 条件的状态,为 True、False、Unknown 之一。 枚举:True, False, Unknown | true |
| type | string | 条件的类型,采用 CamelCase 或 foo.example.com/CamelCase 形式。 | true |
| observedGeneration | integer | observedGeneration 表示设置此条件时所基于的 .metadata.generation。例如,如果 .metadata.generation 当前为 12,而 .status.conditions[x].observedGeneration 为 9,则该条件相对于实例的当前状态已过期。 格式:int64 最小值:0 | false |
SpinAppExecutor 的 Custom Resource Definition (CRD) 参考资源类型:
SpinAppExecutor 是 spinappexecutors API 的 schema
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| apiVersion | string | core.spinkube.dev/v1alpha1 | true |
| kind | string | SpinAppExecutor | true |
| metadata | object | `metadata` 字段的各字段说明参见 Kubernetes API 文档。 | true |
| spec | object | SpinAppExecutorSpec 定义 SpinAppExecutor 的期望状态 | false |
| status | object | SpinAppExecutorStatus 定义 SpinAppExecutor 的实际观测状态 | false |
SpinAppExecutor.specSpinAppExecutorSpec 定义 SpinAppExecutor 的期望状态
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| createDeployment | boolean | CreateDeployment 指定 Executor 是希望由 SpinKube operator 为应用创建
deployment,还是将由外部方式实现。 | true |
| deploymentConfig | object | DeploymentConfig 指定当 createDeployment 为 true 时
deployment 应如何配置。 | false |
SpinAppExecutor.spec.deploymentConfigDeploymentConfig 指定当 createDeployment 为 true 时 deployment 应如何配置。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| caCertSecret | string | CACertSecret 指定包含要挂载到 deployment 的 CA
证书的 secret 名称。 | false |
| installDefaultCACerts | boolean | InstallDefaultCACerts 指定是否应生成默认 CA
证书包。设置后将创建一个包含这些证书的新 secret。如果未在
`CACertSecret` 中定义 secret 名称,则 secret 名称为
`spin-ca`。 | false |
| otel | object | Otel 提供到 Otel 变量的 Kubernetes 绑定。 | false |
| runtimeClassName | string | RuntimeClassName 是 deployment 所创建的 Pod 应使用的
RuntimeClass 名称。仅应在未定义 SpintainerImage 时定义。 | false |
| spinImage | string | SpinImage 指向一个将在容器中运行 Spin 以执行
SpinApp 的 image。这是使用 shim 执行 SpinApp 之外的另一种方式。仅应在未定义 RuntimeClassName 时
定义。指定后,应用 image 必须可在无需认证的情况下获取。 | false |
SpinAppExecutor.spec.deploymentConfig.otelOtel 提供到 Otel 变量的 Kubernetes 绑定。
| 名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
| exporter_otlp_endpoint | string | ExporterOtlpEndpoint 配置用于发送遥测数据的默认合并 otlp endpoint | false |
| exporter_otlp_logs_endpoint | string | ExporterOtlpLogsEndpoint 配置日志专用的 otlp endpoint | false |
| exporter_otlp_metrics_endpoint | string | ExporterOtlpMetricsEndpoint 配置指标专用的 otlp endpoint | false |
| exporter_otlp_traces_endpoint | string | ExporterOtlpTracesEndpoint 配置 trace 专用的 otlp endpoint | false |
spin kube completion --help
为指定的 shell 生成 kube 的自动补全脚本。
关于如何使用生成的脚本,请参阅各子命令的帮助信息。
Usage:
kube completion [command]
Available Commands:
bash 生成 bash 的自动补全脚本
fish 生成 fish 的自动补全脚本
powershell 生成 powershell 的自动补全脚本
zsh 生成 zsh 的自动补全脚本
Flags:
-h, --help completion 的帮助信息
spin kube completion bash --help
为 bash shell 生成自动补全脚本。
此脚本依赖 'bash-completion' 包。
如果尚未安装,可以通过操作系统的包管理器安装。
要在当前 shell 会话中加载补全:
source <(kube completion bash)
要为每个新会话加载补全,只需执行一次:
#### Linux:
kube completion bash > /etc/bash_completion.d/kube
#### macOS:
kube completion bash > $(brew --prefix)/etc/bash_completion.d/kube
此设置需要启动新的 shell 才能生效。
Usage:
kube completion bash
Flags:
-h, --help bash 的帮助信息
--no-descriptions 禁用补全描述
spin kube completion fish --help
为 fish shell 生成自动补全脚本。
要在当前 shell 会话中加载补全:
kube completion fish | source
要为每个新会话加载补全,只需执行一次:
kube completion fish > ~/.config/fish/completions/kube.fish
此设置需要启动新的 shell 才能生效。
Usage:
kube completion fish [flags]
Flags:
-h, --help fish 的帮助信息
--no-descriptions 禁用补全描述
spin kube completion powershell --help
为 powershell 生成自动补全脚本。
要在当前 shell 会话中加载补全:
kube completion powershell | Out-String | Invoke-Expression
要为每个新会话加载补全,请将上述命令的输出
添加到你的 powershell 配置文件(profile)中。
Usage:
kube completion powershell [flags]
Flags:
-h, --help powershell 的帮助信息
--no-descriptions 禁用补全描述
spin kube completion zsh --help
为 zsh shell 生成自动补全脚本。
如果你的环境中尚未启用 shell 补全,需要先启用它。
只需执行以下命令一次:
echo "autoload -U compinit; compinit" >> ~/.zshrc
要在当前 shell 会话中加载补全:
source <(kube completion zsh)
要为每个新会话加载补全,只需执行一次:
#### Linux:
kube completion zsh > "${fpath[1]}/_kube"
#### macOS:
kube completion zsh > $(brew --prefix)/share/zsh/site-functions/_kube
此设置需要启动新的 shell 才能生效。
Usage:
kube completion zsh [flags]
Flags:
-h, --help zsh 的帮助信息
--no-descriptions 禁用补全描述
spin kube --help
管理运行在 Kubernetes 上的应用
Usage:
kube [command]
Available Commands:
completion 为指定的 shell 生成自动补全脚本
help 任何命令的帮助信息
scaffold 生成 SpinApp 清单(manifest)
version 显示版本信息
Flags:
-h, --help kube 的帮助信息
--kubeconfig string kubeconfig 文件的路径
-n, --namespace string namespace 作用域
-v, --version kube 的版本信息
spin kube scaffold --help
生成 SpinApp 清单(manifest)
Usage:
kube scaffold [flags]
Flags:
--autoscaler string 要使用的 autoscaler。有效值为 'hpa' 和 'keda'
--autoscaler-target-cpu-utilization int32 要在所有 Pod 上维持的目标 CPU 利用率百分比(默认 60)
--autoscaler-target-memory-utilization int32 要在所有 Pod 上维持的目标内存利用率百分比(默认 60)
--cpu-limit string 允许 Spin 应用使用的最大 CPU 资源量
--cpu-request string Spin 应用请求的 CPU 资源量。用于确定 Spin 应用将运行在哪个节点上
--executor string 用于运行 Spin 应用的 executor(默认 "containerd-shim-spin")
-f, --from string Spin 应用在 registry 中的引用
-h, --help scaffold 的帮助信息
-s, --image-pull-secret strings 拉取 image 时使用的、位于同一 namespace 中的 secret
--max-replicas int32 spin 应用的最大副本数。使用此 flag 需启用自动缩放(默认 3)
--memory-limit string 允许 Spin 应用使用的最大内存量
--memory-request string Spin 应用请求的内存量。用于确定 Spin 应用将运行在哪个节点上
-o, --out string 写入 manifest yaml 的文件路径
-r, --replicas int32 spin 应用的最小副本数(默认 2)
-c, --runtime-config-file string runtime config 文件的路径
spin kube version
Spintainer(由 Spin 与 container 两词拼合而成)执行器是一种 SpinAppExecutor,它将 Spin 应用直接运行在容器中,而不是通过 shim 运行。这在许多场景下都很有用:
注意:对于大多数使用场景,我们推荐使用 shim。Spintainer 执行器最好仅作为替代方案。
以下是一个 Spintainer 执行器的示例配置:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinAppExecutor
metadata:
name: spintainer
spec:
createDeployment: true
deploymentConfig:
installDefaultCACerts: true
spinImage: ghcr.io/fermyon/spin:v2.7.0
将其保存为名为 spintainer-executor.yaml 的文件,然后应用到集群中。
kubectl apply -f spintainer-executor.yaml
要使用 Spintainer 执行器,你需要在 SpinApp 中将其指定为 executor。
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: simple-spinapp
spec:
image: "ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.13.0"
replicas: 1
executor: spintainer
Spintainer 执行器会在一个容器中运行你的 Spin 应用,该容器基于 .spec.deploymentConfig.spinImage 指定的镜像创建。容器镜像必须以 Spin 二进制作为容器的入口点(entrypoint),并使用以下参数启动:
up --listen {spin-operator-defined-port} -f {spin-operator-defined-image} --runtime-config-file {spin-operator-defined-config-file}
为方便使用,你可以直接使用 Spin 项目发布在这里的镜像,也可以根据自己的独特需求自行构建镜像。
Kubernetes Event-Driven Autoscaling(KEDA) 为 Kubernetes 工作负载提供事件驱动的自动伸缩能力。它使 Kubernetes 能够根据外部事件(例如队列中的消息)自动伸缩应用,从而实现更高效的资源利用,并基于实际需求而非静态指标进行响应式伸缩。KEDA 在 Kubernetes 与各类事件源之间充当桥梁,让你在云原生环境中更轻松地动态伸缩应用。如果你想了解 SpinKube 如何与 KEDA 集成,请阅读《使用 KEDA 进行伸缩》教程,该教程会将一个 SpinApp 以及 KEDA ScaledObject 实例部署到集群中。教程还会使用 Bombardier 生成流量,以测试 KEDA 对 SpinApp 的伸缩效果。
Rancher Desktop 1.13.0 版本已提供对运行 WebAssembly(Wasm)容器并将其部署到 Kubernetes 的基本支持。Rancher Desktop 由 SUSE 出品,是一款开源应用,为你在桌面上使用容器和 Kubernetes 提供了所需的一切。如果你想了解 SpinKube 如何与 Rancher Desktop 集成,请阅读《与 Rancher Desktop 集成》教程,该教程会逐步介绍安装 SpinKube 所需组件的过程(包括用于 SSL 的 CertManager、CRD,以及通过 Helm chart 安装的 Runtime Class Manager)。随后教程会演示如何创建一个简单的 Spin JavaScript 应用,并将其部署到 Rancher Desktop 的本地集群中。
以下列出了可运行 Spin Operator 的兼容 Kubernetes 发行版与平台:
--container-runtime=containerd,
并确保 minikube 版本 >= 1.33)免责声明:请注意,这份兼容 Kubernetes 发行版与平台的列表仍在持续完善中。对于托管 Kubernetes 服务,云服务商可能会选择停止对某些特定依赖(例如容器运行时)的支持,这一点需要格外留意。尽管我们会尽力保证本文档的准确性,但最终仍需由您自行向 Kubernetes 服务商确认所需依赖是否仍然受支持。
如果您想验证 Spin Operator 与某个新 Kubernetes 发行版或平台的兼容性,或者只是想亲自测试上述列表中的某个平台,请按照以下步骤进行验证:
安装 Spin Operator:首先在 Kubernetes 集群中安装 Spin Operator,包括部署其必要的依赖以及 Spin Operator 本身。(参见 使用 Helm 安装)
创建、打包并部署 Spin 应用:接下来创建一个 Spin 应用,将其打包,并成功部署到 Kubernetes 环境中。(参见 打包并部署 Spin 应用)
调用 Spin 应用:Spin 应用部署完成后,确保该应用至少成功处理了一个请求。
Spin Operator 要求运行 Spin 应用的目标节点支持 containerd 版本
1.6.26+ 或
1.7.7+。
使用 kubectl get nodes -o wide 命令查看每个节点上安装的容器运行时:
# 查看各节点的容器运行时
kubectl get nodes -o wide
NAME STATUS VERSION OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
generalnp-vmss000000 Ready v1.27.9 Ubuntu 22.04.4 LTS 5.15.0-1056-azure containerd://1.7.7-1
generalnp-vmss000001 Ready v1.27.9 Ubuntu 22.04.4 LTS 5.15.0-1056-azure containerd://1.7.7-1
generalnp-vmss000002 Ready v1.27.9 Ubuntu 22.04.4 LTS 5.15.0-1056-azure containerd://1.7.7-1
Spin Operator v0.4.0 引入了一项破坏性的 API 变更:SpinApp 和 SpinAppExecutor 的 API 域名将从 spinoperator.dev 迁移到 spinkube.dev。这是一项不兼容变更,因此在升级到 v0.4.0 时需要重新安装 Spin Operator。
卸载现有的所有 SpinApp。
注意:先备份它们!TODO
kubectl get spinapps.core.spinoperator.dev -o yaml > spinapps.yaml
kubectl delete spinapp.core.spinoperator.dev --all
卸载现有的所有 SpinAppExecutor。
kubectl delete spinappexecutor.core.spinoperator.dev --all
卸载旧版 Spin Operator。
注意:如果你在安装 Spin Operator 时使用了不同的 release 名称或命名空间,则需要相应地调整命令。另外,如果你当初不是通过 Helm 安装的 Spin Operator,则需要按照你当时所用的安装方式来卸载它。
helm uninstall spin-operator --namespace spin-operator
卸载旧的 CRD。
kubectl delete crd spinapps.core.spinoperator.dev
kubectl delete crd spinappexecutors.core.spinoperator.dev
修改你的 SpinApp 以使用新的 apiVersion。
现在你需要修改 SpinApp 中的 apiVersion,将 core.spinoperator.dev/v1alpha1 替换为 core.spinkube.dev/v1alpha1。
注意:如果你的 SpinApp 没有在源代码中进行版本管理,那么你在第 1 步中已经将集群里的 SpinApp 备份到了名为
spinapps.yaml的文件中。如果是这种情况,你需要替换spinapps.yaml文件中的apiVersion。下面的命令可以帮你完成这件事:
sed 's|apiVersion: core.spinoperator.dev/v1alpha1|apiVersion: core.spinkube.dev/v1alpha1|g' spinapps.yaml > modified-spinapps.yaml
安装新的 CRD。
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.4.0/spin-operator.crds.yaml
重新安装 SpinAppExecutor。
kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.4.0/spin-operator.shim-executor.yaml
如果你之前还使用了其他执行器,也需要一并安装。
安装新版 Spin Operator。
# 使用 Helm 安装 Spin Operator
helm install spin-operator \
--namespace spin-operator \
--create-namespace \
--version 0.4.0 \
--wait \
oci://ghcr.io/spinkube/charts/spin-operator
重新应用你修改后的 SpinApp。 按照你平时惯用的方式将 SpinApp 部署到集群中,例如 Kubectl、Flux、Helm 等。
注意:如果你在第 1 步中备份了 SpinApp,可以使用下面的命令重新应用它们:
kubectl apply -f modified-spinapps.yaml
升级你的 spin kube 插件。
如果你正在使用 spin kube 插件,需要将其升级到新版本,以保证通过脚手架生成的应用仍然有效。
spin plugins upgrade kube
SpinKube 是一个开源的社区驱动项目。你可以通过多种方式做出贡献,既可以贡献于项目本身,也可以服务于更广泛的社区。
欢迎加入我们每两周一次的社区例会,与团队成员和其他贡献者建立联系。这些例会是旁听、提问或分享想法的绝佳机会!
在 Slack 上与社区保持联系,参与实时讨论并获取最新动态:
请访问 CNCF Slack 上的 #spinkube 频道。
期待在那里见到你!
本页面提供了一些较为通用的建议,介绍你可以通过哪些方式为 SpinKube 做出贡献,以及如何着手去做。
如果你需要一份关于代码贡献具体细节的参考,请参阅编写代码文档。
按照以下步骤开始,你就能顺利地成为 SpinKube 的贡献者。
可以说,协作与沟通是开源开发中最重要的环节。就项目方向达成共识,并确保你的工作与该方向保持一致,是让你的工作被接受的关键。因此,尽早且经常地加入交流十分重要。
要加入交流,请访问 CNCF Slack 上的 #spinkube 频道。
SpinKube 文档是一个很好的起点。它包含如何开始使用项目、如何做贡献以及如何使用项目的信息,也是了解项目架构与设计的绝佳去处。
SpinKube 的文档很棒,但并非完美无缺。如果你发现内容不清晰或有错误,请提交 pull request 予以修正。更多信息请参阅编写文档指南。
如果某个 issue 报告了 bug,请尝试复现它。如果能够复现且看起来有效,请在 issue 中注明你已确认该 bug,并确保 issue 的标签设置得当。如果无法复现,请向报告者询问更多信息。
可以考虑为 bug 的行为编写一个测试,即使你并不亲自修复这个 bug。
带有 good first issue 标签的 issue 是很好的起点。这些 issue 被特别标记为适合新贡献者上手的工作。
作为大型项目的新人,很容易感到挫败。以下建议可以让你的 SpinKube 贡献工作更有价值、更有收获。
你不必在动手之前就成为某个领域的专家;正是通过持续不断地向代码贡献,你才会成为专家。
小 issue 比大 issue 更容易获得反馈,对新贡献者来说尤其如此;维护者更有可能抽出时间来评审一个小的改动。
也就是说,在修复 issue 之前,先请他人确认 bug 确实存在;在动手实现一个新功能之前,先确保大家对提案已达成共识。
把你的观点公之于众,说“这个 issue 是有效的”或“这个 patch 还需要改进”,有时可能让人忐忑,但这是项目前进的唯一方式。整个 SpinKube 社区的贡献最终会产生远超任何个人的影响力。没有你,我们做不到!
如果你实在不确定某个 pull request 是否已可供评审,就不要做此标记。可以留下评论,说明你的想法。如果你大体确定但不是完全确定,也可以在 Slack 上问问,看看是否有人能证实你的判断。
专注于一个或两个 issue,从头到尾跟进完成,然后再开始下一轮。那种同时接下大量 issue、任由其中一些不了了之的“霰弹枪式”做法,最终往往弊大于利。
当我们说“这个 pull request 必须包含文档和测试”时,是认真的。如果一个 patch 缺少文档和测试,最好有一个充分的理由。诸如“我找不到这个功能的现有测试”之类的说辞并没有多少说服力;即便这是事实,那也意味着你承担着为该功能编写第一批测试的格外重要的任务,而不是可以免写测试。
你的 issue 或 patch 不总是能很快得到评审。这并非针对个人,因为需要处理的 issue 和 pull request 实在太多了。
让你的 patch 保持更新很重要。请在 GitHub 上查看你的 pull request,确保所有评审意见都已得到处理。
想为社区做一点回馈吗?也许你在 SpinKube 中发现了一个想要修复的 bug,也许你希望添加一个小功能。
为 SpinKube 本身做贡献,是让你的诉求得到解决的最佳方式。这乍看之下可能令人生畏,但这是一条被无数人走过的路,有文档、工具和社区为你提供支持。我们会带你走完全部流程,让你通过实例来学习。
在本教程中,我们假设你对 SpinKube 的工作原理至少有基本的了解。也就是说,你应该能够顺利完成现有教程中“将第一个应用部署到 SpinKube”的部分。另外,学一点 Rust 也很有价值,因为 SpinKube 的许多项目都是用 Rust 编写的。如果你还不会,Learn Rust 是一个很好的起点。
如果你不熟悉 git 和 GitHub,会发现本教程及其链接中提供的信息足以让你上手。不过,如果你打算长期为 SpinKube 做贡献,可能还需要进一步阅读这些工具的相关资料。
总的来说,本教程会尽可能解释清楚每一个环节,以便惠及最广泛的读者。
作为一名贡献者,你可以帮助我们保持 SpinKube 社区的开放与包容。请阅读并遵守我们的行为准则。
在本教程中,你需要安装 Git,以便下载 SpinKube 的当前开发版本,并为你的修改创建分支。
要检查是否已安装 Git,请在命令行中输入 git。如果提示找不到该命令,你就需要下载并安装它。更多信息请参阅 Git 的下载页面。
如果你对 Git 不太熟悉,在安装之后,随时可以在命令行中输入 git help 来了解更多命令的用法。
SpinKube 托管在 GitHub 上,你需要一个 GitHub 账号才能做贡献。如果你还没有,可以在 GitHub 上免费注册。
SpinKube 的各个仓库都归属于 spinframework GitHub 组织。拥有账号后,访问某个仓库的页面,点击右上角的 “Fork”,即可创建该仓库的 fork。
然后,在命令行中克隆你的 fork。例如,如果你 fork 了 spin-operator 仓库,可以运行:
git clone https://github.com/YOUR-USERNAME/spin-operator.git
SpinKube 组织下的每个仓库都有一个 README 文件,说明项目的功能以及如何开始。这是很好的切入点,它能让你对项目以及如何运行测试套件有一个整体的认识。
为项目做贡献时,非常重要的是你的代码改动不要引入 bug。验证改动之后项目仍然正常工作的一种方式,就是运行项目的测试套件。如果所有测试仍然通过,你就可以比较有把握地认为你的改动是有效的,并且没有破坏项目的其他部分。如果你之前从未运行过项目的测试套件,最好先运行一次,熟悉它的输出。
大多数项目都有运行测试套件的命令,通常是 make test 或 cargo test 之类。请查看项目的 README 文件以了解如何运行测试套件。如果不确定,随时可以在 #spinkube 频道Slack 上求助。
如果不确定从哪里开始,你可以在感兴趣的仓库中寻找带有 good first issue 标签的 issue。这类 issue 通常更简单,被特别标记为适合新贡献者上手的工作。
在进行任何修改之前,先为这个 issue 创建一个新分支:
git checkout -b issue-123
分支名称可以随意取,issue-123 只是一个示例。在这个分支中所做的所有修改都只针对该 issue,不会影响我们之前克隆的代码主副本。
如果你在修复一个 bug,请编写一个(或多个)能够复现该 bug 的测试。如果你在添加新功能,请编写一个验证该功能按预期工作的测试。这有助于确保你的改动符合预期,并且不会破坏项目的其他部分。
写好测试之后,我们需要确认它确实失败。这一点很重要,因为它能验证测试确实在检验我们认为的东西。如果测试通过了,那说明它并没有真正测试我们要修复的问题。
如何运行测试套件,请参阅项目的 README,或在 Slack 上求助。
现在我们有了一个失败的测试,可以着手修改代码来修复这个问题了。这是有趣的部分!用你喜欢的文本编辑器进行修改吧。
修改完成之后,再次运行测试套件以确认测试通过。如果测试通过,你就可以比较有把握地认为你的改动符合预期。
一旦确认你的改动和测试都能正常工作,建议运行完整的测试套件,验证你的改动没有在项目的其他部分引入 bug。虽然完整测试套件全部通过并不能保证你的代码毫无 bug,但它确实有助于发现许多否则可能被忽视的 bug 和回归问题。
完成修改并确认测试通过后,将你的改动提交到分支上:
git add .
git commit -m "Fix issue 123"
现在你已经把改动提交到了分支上,把分支推送到 GitHub 上的 fork:
git push origin issue-123
将改动推送到 GitHub 上的 fork 之后,你就可以创建 pull request 了。这是请求将你的改动合并到代码主副本的提议。要创建 pull request,请在 GitHub 上访问你的 fork,点击 “New pull request” 按钮。
如果你的改动引入了新功能或改变了现有行为,务必更新文档。这有助于其他贡献者理解你的改动以及如何使用它们。
更多信息请参阅编写文档指南。
恭喜!你已经为 SpinKube 做出了一次贡献。
pull request 提交之后,需要由维护者进行评审。请在 CNCF Slack 的 #spinkube 频道上发起请求,请大家来评审。
我们高度重视文档的一致性与可读性。我们对待文档如同对待代码一样:力求尽可能频繁地改进它。
文档的变更通常有以下两种形式:
本节介绍文档作者如何以最有用、最不易出错的方式来编写文档变更。
尽管 SpinKube 的文档最终以 HTML 形式发布在 https://spinkube.dev/docs 供人阅读,但我们是以 Markdown 编写的纯文本文件集合来编辑它的,以获得最大的灵活性。
SpinKube 的文档使用名为 docsy 的文档系统,而 docsy 又基于 Hugo Web 框架。其基本思路是:通过称为静态站点生成(SSG)的过程,将轻度格式化的纯文本文档转换为 HTML。
如果你想在工作中运行自己的本地 Hugo 服务器来预览改动:
spinframework/spinkube-docs 仓库。README.md 文件,了解如何从源码构建本站点。如果你在使用文档时刚发现了一处想要修改的地方,本网站为你提供了快捷方式:
如果你在文档中发现了问题,但不确定如何自己修复,请在文档仓库中提交一个 issue。你也可以通过点击页面右上角的 Create Issue 按钮,针对某个特定页面提交 issue。
以下列出了常见的错误信息以及相应的故障排除建议,希望能对你的工作有所帮助。
SpinKube 在尽力而为(best-effort)的基础上提供支持。对于按照文档手动安装 SpinKube 的用户,请在 Spin Operator 仓库中报告问题。对于通过 Azure Marketplace 安装的用户,请在 Azure 仓库中开一个 issue 以寻求帮助。如果你的问题比较紧急,也可以在 Slack 中提出。
虽然 Spin Operator Helm chart 是公开的,可以匿名拉取,但如果你之前曾对 ghcr.io registry 进行过身份认证,而认证令牌后来已过期,拉取 chart 时就可能出错。
错误大致如下所示:
helm install spin-operator \
--namespace spin-operator --create-namespace --version 0.6.1 --wait oci://ghcr.io/spinframework/charts/spin-operator
Error: INSTALLATION FAILED: failed to download "oci://ghcr.io/spinframework/charts/spin-operator" at version "0.6.1"
解决方法是:要么使用有效的令牌重新向 registry 进行认证(例如 docker login ghcr.io),要么退出登录并以匿名方式拉取 chart(例如 docker logout ghcr.io)。
在按照快速开始指南操作时,运行 kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.shim-executor.yaml
命令后可能出现如下错误:
Error from server (InternalError): error when creating "https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.shim-executor.yaml": Internal error occurred: failed calling webhook "mspinappexecutor.kb.io": failed to call webhook: Post "https://spin-operator-webhook-service.spin-operator.svc:443/mutate-core-spinkube-dev-v1alpha1-spinappexecutor?timeout=10s": no endpoints available for service "spin-operator-webhook-service"
要解决上述错误,首先检查 Spin Operator 是否正在运行:
get pods -n spin-operator
NAME READY STATUS RESTARTS AGE
spin-operator-controller-manager-5bdcdf577f-htshb 0/2 ContainerCreating 0 26m
如果得到上述结果(READY 为 0/2),则使用结果中的名称对 spin-operator 执行 kubectl describe pod:
kubectl describe pod spin-operator-controller-manager-5bdcdf577f-htshb -n spin-operator
如果上述命令的输出中包含 SetUp failed for volume "cert" : secret "webhook-server-cert" not found 这条消息,请检查证书。spin operator 需要该证书来提供 webhook 服务,证书缺失可能是 spin operator 无法启动的原因之一。
检查证书的命令及期望的输出如下:
kubectl get certificate -n spin-operator
NAME READY SECRET AGE
spin-operator-serving-cert True webhook-server-cert 11m
你可能得到的是 No resources found in spin-operator namespace. 这样的响应,而不是上面期望的输出。例如:
kubectl get certificate -n spin-operator
No resources found in spin-operator namespace.
要解决此问题,请尝试重新安装 Spin Operator。不过这一次,请使用 helm upgrade --install 语法,而不只是 helm install:
helm upgrade --install spin-operator \
--namespace spin-operator \
--create-namespace \
--version 0.6.1 \
--wait \
oci://ghcr.io/spinframework/charts/spin-operator
Spin Operator 安装完成后,你可以再次运行 kubectl apply -f https://github.com/spinframework/spin-operator/releases/download/v0.6.1/spin-operator.shim-executor.yaml
命令。此时问题应该已经解决。
在尝试运行 kubectl apply -f <URL> 命令时(例如安装 cert-manager
等),你可能会遇到类似下面的错误:
$ kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.20.0/cert-manager.yaml
error: error validating "https://github.com/cert-manager/cert-manager/releases/download/v1.20.0/cert-manager.yaml": error validating data: failed to download openapi: Get "https://127.0.0.1:6443/openapi/v2?timeout=32s": dial tcp 127.0.0.1:6443: connect: connection refused; if you choose to ignore these errors, turn validation off with --validate=false
这是因为不存在任何集群。你可以按照快速开始指南创建一个集群。
在尝试创建集群(例如名为 wasm-cluster 的集群)时,你可能会收到类似下面的错误消息:
FATA[0000] Failed to create cluster 'wasm-cluster' because a cluster with that name already exists
安装了 kind 之后,你可以使用以下命令获取集群列表:
$ kind get clusters
wasm-cluster
安装了 kubectl 之后,你可以使用以下命令导出集群信息(输出会详细得多):
kubectl cluster-info dump
安装了 kind 之后,你可以按名称删除集群,命令如下所示:
kind delete cluster --name wasm-cluster
运行 kubectl apply -f my-file.yaml 时,如果 yaml 文件过大,可能出现如下错误:
Too long: must have at most 262144 bytes
使用 --server-side=true 选项可以解决此问题:
kubectl apply --server-side=true -f my-file.yaml
安装 Redis Operator 时遇到过一个错误:
$ helm repo add redis-operator https://spotahome.github.io/redis-operator
"redis-operator" has been added to your repositories
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "redis-operator" chart repository
Update Complete. ⎈Happy Helming!⎈
$ helm install redis-operator redis-operator/redis-operator
Error: INSTALLATION FAILED: failed to install CRD crds/databases.spotahome.com_redisfailovers.yaml: error parsing : error converting YAML to JSON: yaml: line 4: did not find expected node content
在等待该 PR 修复合并期间,使用了以下命令强制安装另一个版本的 Redis Operator:
$ helm install redis-operator redis-operator/redis-operator --version 3.2.9
NAME: redis-operator
LAST DEPLOYED: Mon Jan 22 12:33:54 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
在构建 cpu-load-gen 这类 Spin 应用时,如果你的 TinyGo 不是最新版本,可能会遇到如下错误。该错误提示需要 go 版本 1.18 到 1.20,但实际情况未必如此。我们确实建议你安装最新的 go(例如 1.21),无需降级。请直接安装最新版本的 TinyGo 来解决此错误:
user@user:~/spin-operator/apps/cpu-load-gen$ spin build
Building component cpu-load-gen with `tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go`
error: requires go version 1.18 through 1.20, got go1.21
以下术语表中的术语,均以在容器化环境中部署、伸缩、自动化和管理 Spin 应用为语境。
Helm Chart 是 Kubernetes 中用于部署应用的一种包格式。它包含在 Kubernetes 集群上部署和管理应用所需的全部文件、配置和依赖。Helm Chart 提供了一种便捷的方式,以一致且可复现的方式定义、安装和升级复杂应用。
Kubernetes 集群是一组协同工作以运行容器化应用的节点(服务器)。它由控制平面和工作节点组成。控制平面负责管理和编排集群,而工作节点负责承载容器。控制平面包含 API 服务器、调度器和控制器管理等组件;工作节点则使用 Docker 等容器运行时引擎来运行容器。Kubernetes 集群在分布式环境中为容器化应用提供可伸缩性、高可用性和自动化管理。
容器运行时(container runtime)是管理容器执行的软件,负责容器的启动、停止和生命周期管理。容器运行时与底层操作系统交互,为容器提供隔离和资源管理,同时处理容器化在网络、存储和安全方面的相关事务。常见的容器运行时包括 Docker、containerd 和 CRI-O。它们支持容器化应用的部署和管理,让开发者能够将应用连同其全部必要依赖一起打包,并在不同环境中一致地运行。
控制器(Controller)是负责管理某个或某组资源期望状态的核心组件。它持续监视集群,并采取行动确保实际状态与期望状态一致。控制器处理资源的创建、更新和删除等任务,并调和当前状态与期望状态之间的偏差。它们提供自动化和自愈能力,即使出现故障或变更,也能确保集群保持在期望状态。控制器对维持 Kubernetes 部署的稳定性和可靠性起着至关重要的作用。
在 Kubernetes 语境中,自定义资源(Custom Resource,CR)是一种扩展机制,允许用户定义和管理自己的 API 资源。它可以创建面向特定应用或工作负载的新资源类型。自定义资源通过自定义资源定义(CRD)来定义,并且可以像其他任何 Kubernetes 资源一样被处理和管理。它们提供了一种扩展 Kubernetes API 的方式,并支持开发自定义控制器来管理这些资源的生命周期和行为。自定义资源为 Kubernetes 部署带来了更大的灵活性和可定制性。
自定义资源定义(Custom Resource Definition,CRD)是一种允许用户定义自定义资源的扩展机制。它可以创建具有特定 schema 和行为的新资源类型。CRD 为自定义资源定义结构和校验规则,允许用户在内置 Kubernetes 资源之外存储和管理额外的信息。CRD 创建之后,即可通过 Kubernetes API 创建、更新和删除该自定义资源的实例。CRD 提供了一种扩展 Kubernetes 并使其适配特定应用需求的方式。
SpinApp CRD 是一种 Kubernetes 资源,它扩展了 Kubernetes API 的功能以支持 Spin 应用。它定义了一个名为 “SpinApp” 的自定义资源,封装了在 Kubernetes 集群中部署和管理 Spin 应用所需的全部信息。SpinApp CRD 由若干关键字段组成,用于定义 Spin 应用的期望状态。
下面是一个使用 SpinApp CRD schema 的 SpinApp 自定义资源示例:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: simple-spinapp
spec:
image: "ghcr.io/spinframework/containerd-shim-spin/examples/spin-rust-hello:v0.27.2"
replicas: 1
executor: "containerd-shim-spin"
SpinApp CRD 与 Helm 保持分离。如果使用 Helm,必须在安装 Helm chart 之前先安装 CustomResourceDefinition(CRD)资源。
你可以修改上面的示例,通过 YAML 文件自定义 SpinApp。下面是一个包含更多自定义选项的更新版 YAML 文件:
apiVersion: core.spinkube.dev/v1alpha1
kind: SpinApp
metadata:
name: simple-spinapp
spec:
image: 'ghcr.io/spinframework/containerd-shim-spin/examples/spin-rust-hello:v0.27.2'
replicas: 3
imagePullSecrets:
- name: spin-image-secret
serviceAnnotations:
key: value
podAnnotations:
key: value
resources:
limits:
cpu: '1'
memory: 512Mi
requests:
cpu: '0.5'
memory: 256Mi
env:
- name: ENV_VAR1
value: value1
- name: ENV_VAR2
value: value2
# 在此处添加任何其他用户自定义的值
在这个更新后的示例中,我们添加了以下自定义选项:
imagePullSecrets:可选字段,用于引用一个 Kubernetes secret,其中包含从私有镜像仓库拉取镜像所需的凭据。serviceAnnotations:可选字段,用于在所创建的底层 Service 上设置特定的注解。podAnnotations:可选字段,用于在所创建的底层 Pod 上设置特定的注解。resources:可以为 CPU 和内存指定资源限制与请求。请根据应用的资源需求调整相应数值。env:可以为 SpinApp 定义环境变量。按需添加任意数量的环境变量,并为每个变量提供名称和值。要应用这些变更,请保存 YAML 文件(例如 updated-spinapp.yaml),然后使用以下命令将其应用到你的 Kubernetes 集群:
kubectl apply -f updated-spinapp.yaml
Helm 是 Kubernetes 的包管理器,用于简化应用的部署和管理。它使用 chart(预先配置好的模板)来定义应用的结构和配置。Helm 让用户能够方便地在 Kubernetes 集群上安装、升级和卸载应用,同时还支持版本管理、依赖管理和部署自定义。Helm chart 可以共享和复用,这使它成为在 Kubernetes 环境中管理复杂应用的得力工具。
在 Kubernetes 语境中,镜像(image)指一个打包好的可执行软件制品,其中包含运行特定应用或服务所需的全部依赖和配置。镜像通常由 Dockerfile 构建并存储在容器镜像仓库中。镜像是创建容器的基础,而容器是轻量、隔离的运行时环境。Kubernetes 从镜像仓库拉取所需的镜像,并将其部署到集群的工作节点上。镜像对于保证 Kubernetes 中应用部署的一致性和可复现性至关重要。
Kubernetes 是一个开源的容器编排平台,可自动化容器化应用的部署、伸缩和管理。它提供了一个跨节点集群运行和协调容器的框架。Kubernetes 对底层基础设施进行了抽象,并提供负载均衡、服务发现和自愈等能力。它帮助组织高效地管理和扩展应用,确保高可用性与韧性。
开放容器倡议(Open Container Initiative,OCI)是一个开放治理结构和项目,旨在为容器格式和运行时创建行业标准。它的成立是为了确保不同容器技术之间的兼容性与互操作性。OCI 定义了容器镜像和运行时的规范,Docker 和 containerd 等容器运行时均采用这些规范。这些规范为容器的打包和运行提供了通用框架,让用户能够构建和分发可在任何兼容 OCI 的运行时上执行的容器镜像。OCI 在促进容器生态的可移植性和标准化方面发挥着关键作用。
Pod 是最小、最基本的部署单元,表示集群中一个运行中的进程实例。一个 Pod 可以包含一个或多个紧密耦合的容器,它们共享网络、存储等相同资源。Pod 内的容器会被一起调度并部署到同一节点上。Pod 是短暂的(ephemeral),可以被动态地创建、删除或替换。它们为在 Kubernetes 中封装和管理容器化应用的生命周期提供了一种方式。
基于角色的访问控制(Role-Based Access Control,RBAC)是 Kubernetes 中的一种安全机制,可对集群资源的访问进行细粒度控制。RBAC 允许管理员为用户或组定义角色和权限,从而授予或限制其对集群内特定操作和资源的访问。RBAC 确保只有经过授权的用户才能执行特定操作,有助于落实安全策略并防止对敏感资源的未授权访问。它增强了 Kubernetes 集群的整体安全性和治理能力。
RuntimeClass 是一种允许用户为工作负载指定不同容器运行时的资源。它提供了一种定义并选择 Pod 运行时环境的方式。通过使用 RuntimeClass,用户可以根据自身特定需求在不同的容器运行时之间进行选择。这种灵活性使得部署具有不同运行时特性的工作负载成为可能,从而在 Kubernetes 集群中实现更好的资源利用和性能优化。
调度器(scheduler)是负责将 Pod 分配到集群中各节点的组件。它会综合考虑资源可用性、节点容量以及任何已定义的调度约束或策略等因素。调度器确保 Pod 被放置到合适的节点上,以优化资源利用并保持高可用性。在做出调度决策时,它还会考虑亲和性、反亲和性以及资源需求等因素。调度器持续监视集群,并根据需要进行调整,以维持工作负载分布的期望状态。
在 Kubernetes 中,Service 是一种抽象,它定义了一组逻辑上的 Pod,使客户端能够与一个稳定的 Pod 集合交互——无论其代码是为云原生环境而设计,还是被容器化的传统应用。
Spin 是一个用于使用 WebAssembly(Wasm)组件构建和运行事件驱动微服务应用的框架。
SpinApp 清单SpinApp 清单的目标有两个:
因此,最简单的 SpinApp 清单只需要提供镜像仓库引用,即可创建带有正确 Wasm executor 的 Deployment、Pod 和 Service。
此外,SpinApp 清单目前还支持配置以下选项:
SpinAppExecutor CRD 是一种自定义资源定义,Spin Operator 使用它来确定运行 SpinApp 时应采用哪种 executor 类型。
Spin Operator 是一个 Kubernetes operator,负责根据 SpinApp 资源来管理 Spin 应用的生命周期。