跳至內容

Security-Guard 監控快速入門

本教學課程說明如何使用 Security-Guard 來保護已部署的 Knative 服務。

開始之前

在開始本教學課程之前,請務必安裝 Security-Guard

建立並部署服務

提示

以下指令會在啟動和設定此服務的 Security-Guard 擴充功能時,建立 helloworld-go 範例服務。您可以修改這些指令,包括使用 kn CLI 或根據此範例變更服務 yaml,來變更服務的 Security-Guard 設定。

建立範例 securedService

  1. 使用以下範例建立 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/guard-activate: enable
        spec:
          containers:
            - image: ghcr.io/knative/helloworld-go:latest
              env:
                - name: TARGET
                  value: "Secured World"
    
  2. 執行指令來套用 YAML 檔案

    kubectl apply -f <filename>.yaml
    

    其中 <filename> 是您在上一步建立的檔案名稱。

使用 CLI 建立服務

kn service create helloworld-go \
    --image ghcr.io/knative/helloworld-go:latest \
    --env "TARGET=Secured World" \
    --annotation features.knative.dev/queueproxy-podinfo=enabled \
    --annotation qpoption.knative.dev/guard-activate=enable

使用 CLI 建立函數。

將以下 deploy.annotations 新增至位於專案目錄中的 func.yaml 檔案"

deploy:
  annotations:
    features.knative.dev/queueproxy-podinfo: enabled
    qpoption.knative.dev/guard-activate: enable

部署方式與部署任何其他函數相同

kn func deploy

建立服務後,Guard 會開始監控服務 Pod 和傳送至服務的所有事件。

繼續前往Security-Guard 警示範例來測試您的安裝

請參閱使用 Security-Guard 區段以了解如何管理服務的安全性

清除

若要移除已部署的服務,請使用

執行指令來使用用於建立服務的 YAML 檔案刪除

kubectl delete -f <filename>.yaml

其中 <filename> 是您在上一步建立的檔案名稱。

kn service delete helloworld-go

若要移除已部署服務的 Guardian,請使用

```bash
kubectl delete guardians.guard.security.knative.dev helloworld-go
```

我們使用分析和 Cookie 來了解網站流量。關於您使用我們網站的資訊會因此目的而與 Google 分享。了解更多。