mcpField
G
gke-networking-edge

gke-networking-edge

github.com/googlecloudplatform云与 DevOps16948 次安装2 天前更新
代码仓库

关于 gke-networking-edge

gke-networking-edge 为在 GKE 上发布应用的团队提供网络配置工作流,涵盖对外和内部网络访问。内容涉及 Gateway API、Ingress、安全防护、证书、负载均衡和 Private Service Connect。

主要功能

  1. 01配置 Gateway API 与 HTTPRoute
  2. 02设置 GKE Ingress
  3. 03通过 Cloud Armor 防护
  4. 04配置托管 SSL 证书
  5. 05启用容器原生负载均衡
  6. 06通过 PSC 暴露服务

适用场景

  1. 01向互联网发布 GKE 应用
  2. 02为入口流量配置 WAF 与 DDoS 防护
  3. 03自动配置和续期 SSL 证书
  4. 04向其他 VPC 提供内部服务

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/googlecloudplatform/gke-mcp --skill gke-networking-edge

安装后在 Claude Code 中输入/gke-networking-edge确认已加载。

详细介绍

GKE 网络边缘技能

此技能提供相关工作流,用于将运行在 GKE 上的应用安全地暴露给互联网或内部网络。

工作流

1. 配置 Gateway API(推荐)

Gateway API 是在 Kubernetes 中管理路由的现代方式。

前提条件:必须在集群上启用 Gateway API(在 GKE 1.24+ 中默认启用)。

Gateway 示例清单:

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: my-gateway
  namespace: my-namespace
spec:
  gatewayClassName: gke-l7-global-external-managed # GKE managed external L7 load balancer
  listeners:
    - name: http
      protocol: HTTP
      port: 80

HTTPRoute 示例清单:

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: my-route
  namespace: my-namespace
spec:
  parentRefs:
    - name: my-gateway
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: my-service
          port: 80
2. 配置标准 GKE Ingress

对于较简单的用例或旧版配置,请使用标准 Ingress。

Ingress 示例清单:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  namespace: my-namespace
  annotations:
    kubernetes.io/ingress.class: "gce"
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-service
                port:
                  number: 80
3. 使用 Cloud Armor 加强安全性

Cloud Armor 提供 WAF 和 DDoS 防护。

通过 BackendConfig 启用 Cloud Armor:

  1. 在 Cloud Armor 中创建安全策略(通常通过 gcloud 或 Terraform)。
  2. 在 GKE 中的 BackendConfig 里引用该策略。

BackendConfig 示例:

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: my-backend-config
  namespace: my-namespace
spec:
  securityPolicy:
    name: my-cloud-armor-policy
  1. 通过注解将 BackendConfig 与你的 Service 关联。
4. 配置 Google 托管的 SSL 证书

自动配置和续期 SSL 证书。

ManagedCertificate 示例(旧版 Ingress):

apiVersion: networking.gke.io/v1
kind: ManagedCertificate
metadata:
  name: my-certificate
spec:
  domains:
    - example.com

在 Ingress 注解中引用它:networking.gke.io/managed-certificates: my-certificate。

Gateway API 方式: 使用 gateway.networking.k8s.io API,并集成证书管理功能。

5. 启用容器原生负载均衡(推荐)

容器原生负载均衡允许负载均衡器直接将流量发送到 Kubernetes Pod,而不是节点。这能降低延迟并优化流量分配。

前提条件:集群必须是 VPC 原生集群。

工作原理:

  • 对于 GKE Ingress 和 Gateway API,容器原生负载均衡默认通过网络端点组(NEG)启用。
  • 如需验证或为某个 Service 显式启用此功能,请使用 cloud.google.com/neg 注解。

Service 示例清单:

apiVersion: v1
kind: Service
metadata:
  name: my-service
  annotations:
    cloud.google.com/neg: '{"ingress": true}' # Enabled for Ingress
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  selector:
    app: my-app
  type: ClusterIP
6. 配置 Private Service Connect(PSC)

Private Service Connect 让你无需进行 VPC 对等互连,即可安全地将一个 VPC 中的服务暴露给另一个 VPC 中的使用者。

步骤:

  1. 为你的服务创建内部负载均衡器。
  2. 创建引用该负载均衡器的 ServiceAttachment。

ServiceAttachment 示例清单:

apiVersion: networking.gke.io/v1
kind: ServiceAttachment
metadata:
  name: my-psc-attachment
  namespace: my-namespace
spec:
  connectionPreference: ACCEPT_AUTOMATIC
  natSubnets:
    - my-psc-nat-subnet # Subnet dedicated for PSC NAT
  targetService:
    name: my-service
    namespace: my-namespace

将 ServiceAttachment URI 分享给使用者,以便他们在自己的 VPC 中创建 PSC 端点。

最佳实践

  1. 优先使用 Gateway API:与 Ingress 相比,它提供了更高的灵活性和更明确的角色分离。
  2. 启用 Cloud Armor:始终使用 Cloud Armor 保护面向公众的端点。
  3. 使用托管证书:避免手动管理证书续期。
  4. 使用容器原生负载均衡:进行 HTTP(S) 负载均衡时始终使用 NEG,以降低延迟并优化流量分配。

评论

支持 Markdown