安装 Knative 服务舰队组件

安装 Knative 服务作为 GKE Enterprise 舰队组件。

准备工作

概览

将 Knative 作为舰队组件进行安装包括:

  1. 在 Google Cloud 项目中启用舰队。
  2. gke-system-gateway 网关复制到 knative-ingress-gateway 网关。
  3. 在集群上安装 Knative 服务自定义资源。

请注意,在此过程中,您现有的 Knative 服务服务将继续不间断地处理流量。

安装 Knative 服务舰队组件

在本部分中,迁移脚本用于安装 Knative 作为舰队组件。

  1. 运行以下命令以启动迁移脚本:

    ./migration-addon.sh --command install-cloud-run-v2
    

    请注意,如果您在此步骤遇到任何问题或想要更改任何内容,可以重新运行此迁移脚本命令。

  2. 在终端中,迁移脚本会提示您进行确认,以执行每项操作。在每次提示时输入 y 以继续。

    在安装 Knative 服务舰队组件过程中的提示类似于以下内容:

    In the process of installing the Knative serving fleet component, the
    script performs the following:
    1. Enabling the fleet in your Google Cloud project.
    2. Copy gke-system-gateway Gateway to knative-ingress-gateway Gateway
    3. Installing the Knative serving custom resource in your cluster.
    Continue? [Y/n] y
    
    1. Enabling Anthos services?
    Continue? [Y/n] y
    
    Operation "operations/acf.p2-625914735451-10d4b6ff-68e1-4a09-97c4-79b209be5031" finished successfully.
    
    2. Copying gke-system-gateway Gateway to knative-ingress-gateway Gateway
    
    configmap/original-knative-ingress-gateway-spec unchanged
    gateway.networking.istio.io/knative-ingress-gateway patched (no
    change)
    configmap/config-istio patched
    configmap/config-istio patched
    gateway.networking.istio.io "gke-system-gateway" deleted
    
    3. Install the Knative serving custom resource in your cluster?
    Continue? [Y/n] y
    
    Waiting for Knative serving feature to be enabled
    Knative serving feature is enabled.
    The YAML file for the new operator appdevexperience-operator was created at
    /tmp/tmp.bI7H1qagGa/cloudrun.yaml
    customresourcedefinition.apiextensions.k8s.io/cloudruns.operator.run.cloud.google.com
    condition met
    kubeconfig entry generated for my-gke-cluster.
    Added the custom resource for Knative serving
    
    Waiting for Knative serving serving to be ready...
    Knative serving serving is not ready yet.
    Knative serving serving is ready.
    
    Removing the ValidatingWebhookConfiguration used to prevent deletion
    validatingwebhookconfiguration.admissionregistration.k8s.io
    "prevent-deletion-cloud-run-resources" deleted
    
    Knative serving has been installed as an Anthos fleet component
    

    专用集群的已知问题

    如果安装的 Knative 服务在 Google Cloud 上的专用集群上,您可能会收到以下超时错误:

    Waiting for CRD cloudruns.operator.run.cloud.google.com to be created
    

    如需解决超时错误,请运行以下命令:

    cat <<EOF | kubectl apply -f -
    apiVersion: operator.run.cloud.google.com/v1alpha1
    kind: CloudRun
    metadata:
      name: cloud-run
    EOF
    
  3. 验证是否已启用 Knative 服务功能组件:

    控制台

    在 Google Cloud 控制台中查看 Knative 服务组件是否处于已启用状态:

    转到 GKE Enterprise 功能

    命令行

    查看 appdevexperience 状态是否为 ACTIVE

    gcloud alpha container hub features list  --project=PROJECT_ID
    

    PROJECT_ID 替换为您的 Google Cloud 项目的 ID。

    如需了解详情和其他选项,请参阅 gcloud alpha container hub 功能列表参考。

后续步骤

在安装 Cloud Service Mesh 和 Knative 服务后,您可以开始迁移流量并将其发布到新资源

回滚

如果您需要回滚通过上述步骤所做的更改,则可以使用迁移脚本执行以下操作:

  • 从运算符 appdevexperience-operator 中移除对 Knative 传送资源的控制。
  • 删除 Knative 传送自定义资源并卸载运算符 appdevexperience-operator
  • 可选:在 Google Cloud 项目舰队中停用 Knative 服务。

如需开始回滚过程,请执行以下操作:

  1. 运行以下命令以启动迁移脚本:

    ./migration-addon.sh --command rollback-install-cloud-run-v2
    
  2. 在终端中,迁移脚本会提示您进行确认,以执行每项操作。在每次提示时输入 y 以继续。

    卸载舰队组件过程中的提示类似于以下内容:

    In the step of rolling back the Knative serving fleet installation, the
    script performs the following:
    1. Remove control of Knative serving resources from the operator
       `appdevexperience-operator`.
    2. Delete the Knative serving custom resource and uninstall the operator
       `appdevexperience-operator`.
    3. Revert the changes installed by the Knative serving fleet component.
    4. Optional: Disable Knative serving in the GKE Enterprise fleet of your
       Google Cloud project.
    Continue? [Y/n] y
    
    1. Removing control of Knative serving resources from the operator
       `appdevexperience-operator`.
    
    Creating a ValidatingWebhookConfiguration to prevent the deletion of the
    resources under the following namespaces:
    knative-serving, cloud-run-system, and gke-system
    
    waiting for OwnerReferences of Knative serving resources to be deleted
    
    OwnerReferences of Knative serving resources are deleted
    
    Waiting for Knative serving serving to be ready...
    Knative serving serving is ready.
    
    2. Delete the Knative serving custom resource and uninstall the operator
       `appdevexperience-operator`?
    Continue? [Y/n] y
    
    cloudrun.operator.run.cloud.google.com "cloud-run" deleted
    clusteractiveoperand.operand.run.cloud.google.com/sha256-3c1c80a329 patched
    
    waiting for appdevexperience namespace to be deleted
    
    3. Revert the changes installed by the fleet component?
    configmap/config-observability patched
    
    4. Optional: Disable Knative serving in the Anthos fleet of your
       Google Cloud project?
       You can choose to skip this step and keep the feature enable within your
       Anthos fleet. For example, you might want to keep the
       Knative serving fleet component enabled because it was enabled prior to
       this migration.
    Continue (or Skip)? [Y/n] n