使用由 QPOptions 啟用的擴充功能¶
QPOptions 是一個 Queue Proxy 功能,可讓您使用其他 Go 套件擴充 Queue Proxy。例如,security-guard 儲存庫透過新增執行階段安全性功能來保護使用者服務,藉此擴充 Queue Proxy。
一旦您的叢集設定好 QPOptions 啟用的擴充功能,Service 就可以決定要使用哪些擴充功能以及如何設定這些擴充功能。在此說明如何啟用和設定擴充功能。
概觀¶
Service 可以透過在 Service 自訂資源定義 (CRD) 的 spec.template.metadata
下新增 qpoption.knative.dev/*
註釋來啟用和設定擴充功能。
設定值:qpoption.knative.dev/<擴充功能名稱>-activate: "enable"
可啟用擴充功能。
設定值:qpoption.knative.dev/<擴充功能名稱>-config-<key>: "<value>"
會將 key: value
設定新增至擴充功能。
此外,Service 必須確保 Pod Info 磁碟區已掛載,方法是在 Service CRD 的 spec.template.metadata
下新增 features.knative.dev/queueproxy-podinfo: enabled
註釋。
您可以透過套用 YAML 檔案或使用 kn service create
CLI 命令來建立 Knative Service。
先決條件¶
在使用 QPOptions 啟用的擴充功能之前,您必須
- 準備您的叢集
- 確定您使用的是使用您要使用的擴充功能所建置的 Queue Proxy 映像 - 請參閱 使用 QPOptions 擴充 Queue Proxy 映像。
- 確定叢集 config-features 設定為
queueproxy.mount-podinfo: allowed
。如需更多詳細資訊,請參閱 啟用 Queue Proxy Pod Info。 - 符合建立服務中的先決條件
程序¶
提示
下列命令會建立 helloworld-go
範例 Service,同時啟用和設定此 Service 的 test-gate
擴充功能。您可以修改這些命令,包括要啟用的擴充功能和擴充功能設定。
建立範例 Service
-
使用下列範例建立 YAML 檔案
apiVersion: serving.knative.dev/v1 kind: Service metadata: name: helloworld-go namespace: default spec: template: metadata: annotations: features.knative.dev/queueproxy-podinfo: enabled qpoption.knative.dev/testgate-activate: enable qpoption.knative.dev/testgate-config-response: CU qpoption.knative.dev/testgate-config-sender: Joe spec: containers: - image: ghcr.io/knative/helloworld-go:latest env: - name: TARGET value: "World"
-
執行命令以套用 YAML 檔案
其中kubectl apply -f <filename>.yaml
<filename>
是您在上一步中建立的檔案名稱。
kn service create helloworld-go \
--image ghcr.io/knative/helloworld-go:latest \
--env TARGET=World \
--annotation features.knative.dev/queueproxy-podinfo=enabled \
--annotation qpoption.knative.dev/testgate-activate=enable \
--annotation qpoption.knative.dev/testgate-config-response=Goodbye \
--annotation qpoption.knative.dev/testgate-config-sender=Joe
建立 Service 後,Knative 會將註釋傳播到 Service 部署的 podSpec。建立 Service pod 時,Queue Proxy sidecar 將會掛載包含 pod 註釋的磁碟區,並啟用 testgate
擴充功能。如果 testgate
擴充功能在 Queue Proxy 映像中可用,就會發生此情況。然後,將使用設定 { sender: "Joe", response: "CU"}
來設定 testgate
擴充功能。