1.15. 网关迁移


作为网络管理员,部署入口和出口网关的首选方法是使用网关注入的 Deployment 资源。

1.15.1. 关于网关迁移

在 Red Hat OpenShift Service Mesh 2.x 中,Service Mesh Operator 默认在 control plane 命名空间中创建入口和出口网关。您可以在 ServiceMeshControlPlane 资源中定义额外的网关。

使用网关注入使用 Deployment 资源部署入口和出口网关提供了更大的灵活性和控制。这种部署方法是一种更好的做法,因为它允许您管理网关以及相应的应用,而不是在 control plane 资源中管理。因此,您应该禁用默认网关,离开 Service Mesh Control Plane 声明,并开始使用网关注入。

1.15.2. 从 SMCP-Defined 网关迁移到网关注入

此流程解释了如何使用零停机时间从 ServiceMeshControlPlane 资源中定义的网关迁移到使用网关注入管理的网关。此迁移是通过使用现有网关 Service 对象为目标的新网关部署来实现,该部署使用网关注入创建。

先决条件

  • cluster-admin 用户身份登录到 OpenShift Container Platform Web 控制台。
  • 必须安装 Red Hat OpenShift Service Mesh Operator。
  • ServiceMeshControlPlane 资源必须部署,且配置中存在入口网关。

流程

  1. 创建新的入口网关,配置为使用网关注入。

    注意

    此流程从 ServiceMeshControlPlane 资源中定义的默认入口网关部署迁移到网关注入。该流程可以被修改,以便从 SMCP 中配置的额外入口网关迁移。

    带有网关注入的 ingress 网关资源示例

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: istio-ingressgateway-canary
      namespace: istio-system 
    1
    
    spec:
      selector:
        matchLabels:
          app: istio-ingressgateway
          istio: ingressgateway
      template:
        metadata:
          annotations:
            inject.istio.io/templates: gateway
          labels: 
    2
    
            app: istio-ingressgateway
            istio: ingressgateway
            sidecar.istio.io/inject: "true"
        spec:
          containers:
            - name: istio-proxy
              image: auto
          serviceAccountName: istio-ingressgateway
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: istio-ingressgateway
      namespace: istio-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      name: secret-reader
      namespace: istio-system
    rules:
      - apiGroups: [""]
        resources: ["secrets"]
        verbs: ["get", "watch", "list"]
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: istio-ingressgateway-secret-reader
      namespace: istio-system
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: secret-reader
    subjects:
      - kind: ServiceAccount
        name: istio-ingressgateway
    ---
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy 
    3
    
    metadata:
      name: gatewayingress
      namespace: istio-system
    spec:
      podSelector:
        matchLabels:
          istio: ingressgateway
      ingress:
        - {}
      policyTypes:
        - Ingress
    Copy to Clipboard Toggle word wrap

    1
    网关注入部署和所有支持资源都应部署到与 SMCP 定义网关相同的命名空间中。
    2
    确保 pod 模板中指定的标签包括与现有 SMCP 定义网关关联的 Service 对象中指定的所有标签选择器。
    3
    从集群外部授予对新网关的访问权限。当 ServiceMeshControlPlane 资源的 spec.security.manageNetworkPolicy 设置为 true 时,都需要这个访问权限,这是默认设置。
  2. 验证新网关部署是否已成功处理请求。

    如果在 ServiceMeshControlPlane 资源中配置了访问日志记录,请查看新网关部署的访问日志以确认行为。

  3. 缩减旧部署并扩展新部署。

    通过执行以下步骤,逐步将流量从旧网关部署移到新的网关部署:

    1. 运行以下命令,增加新网关部署的副本数:

      $ oc scale -n istio-system deployment/<new_gateway_deployment> --replicas <new_number_of_replicas>
      Copy to Clipboard Toggle word wrap
    2. 运行以下命令来减少旧网关部署的副本数量:

      $ oc scale -n istio-system deployment/<old_gateway_deployment> --replicas <new_number_of_replicas>
      Copy to Clipboard Toggle word wrap
    3. 重复运行前面的两个命令。每次,增加新网关部署的副本数量,并减少旧网关部署的副本数量。继续重复,直到新网关部署处理到网关 Service 对象的所有流量。
  4. 运行以下命令,从网关 Service 对象中删除 app.kubernetes.io/managed-by 标签:

    $ oc label service -n istio-system istio-ingressgateway app.kubernetes.io/managed-by-
    Copy to Clipboard Toggle word wrap

    删除标签可防止在 ServiceMeshControlPlane 资源中禁用网关时删除服务。

  5. 运行以下命令,从网关 Service 对象中删除 ownerReferences 对象:

    $ oc patch service -n istio-system istio-ingressgateway --type='json' -p='[{"op": "remove", "path": "/metadata/ownerReferences"}]'
    Copy to Clipboard Toggle word wrap

    删除此对象可防止删除 ServiceMeshControlPlane 资源时收集服务。

  6. 运行以下命令,禁用由 ServiceMeshControlPlane 资源管理的旧网关部署:

    $ oc patch smcp -n istio-system <smcp_name> --type='json' -p='[{"op": "replace", "path": "/spec/gateways/ingress/enabled", "value": false}]'
    Copy to Clipboard Toggle word wrap
    注意

    当禁用旧的 ingress 网关 Service 对象时,它不会被删除。您可以将此 Service 对象保存到文件中,并将其与新的网关注入资源一起进行管理。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat