Configures GKE edge networking, traffic routing, load balancing, and private service endpoints. Use when configuring Gateway API manifests, standard Ingress, Cl
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-gke-service-networking-dbf406534dac ,按照其中的说明把「gke-service-networking」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
This skill provides workflows for exposing applications running on GKE securely to the internet or internal networks.
Deployable manifest templates live in assets/ — edit the # Replace ...
placeholders before applying.
The Gateway API is the modern way to manage routing in Kubernetes.
Prerequisites: Gateway API must be enabled on the cluster (enabled by
default on new clusters running GKE 1.26+; on older supported versions enable it
with --gateway-api=standard).
Templates:
assets/gateway.yaml — external Gateway using the
gke-l7-global-external-managed GatewayClass with an HTTP listener.assets/httproute.yaml — HTTPRoute attaching to the Gateway via
parentRefs and routing a path prefix to a Service backendRef.assets/httproute-traffic-split.yaml — HTTPRoute demonstrating weighted
traffic splitting (e.g. 90/10) for canary deployments across backend
services.kubectl apply -f assets/gateway.yaml
kubectl apply -f assets/httproute.yaml
Traffic Splitting (Canary Deployments):
HTTPRoute supports weighted traffic splitting across multiple backend Services for canary rollouts:
spec:
rules:
- backendRefs:
- name: app-v1
port: 80
weight: 90
- name: app-v2
port: 80
weight: 10
Use standard Ingress for simpler use cases or legacy setups.
Template: assets/ingress.yaml — GCE Ingress (kubernetes.io/ingress.class: "gce" annotation) routing to a Service.
Cloud Armor provides WAF and DDoS protection.
Create a Security Policy in Cloud Armor:
gcloud compute security-policies create {security_policy_name} \
--description "WAF policy for {app_name}"
# Example rule: block an abusive IP range
gcloud compute security-policies rules create 1000 \
--security-policy {security_policy_name} \
--action deny-403 \
--src-ip-ranges "203.0.113.0/24" \
--description "Block abusive range"
Reference it in a BackendConfig: assets/backendconfig.yaml (sets
spec.securityPolicy.name).
Associate the BackendConfig with your Service via annotations:
# In your Kubernetes Service manifest metadata.annotations:
cloud.google.com/backend-config: '{"default": "{backend_config_name}"}'
# Or for specific port mappings:
cloud.google.com/backend-config: '{"ports": {"80": "{backend_config_name}"}}'
Automatically provision and renew SSL certificates.
Legacy Ingress approach: apply assets/managed-certificate.yaml (a
ManagedCertificate listing your domains), then reference it in the Ingress
annotations:
networking.gke.io/managed-certificates: {certificate_name}
Gateway API approach: for standard Certificate Manager integration, create a
CertificateMap and reference it in the Gateway metadata annotations using the
exact annotation networking.gke.io/certmap (spelled without any hyphens in
certmap):
metadata:
annotations:
networking.gke.io/certmap: {certificate_map_name}
[!IMPORTANT] The annotation key is strictly
networking.gke.io/certmap(do not usecert-maporcertificate-map).
Alternatively, reference a Kubernetes Secret in the HTTPS listener's
tls.certificateRefs. Both variants are in assets/gateway-https.yaml.
Container-native load balancing allows load balancers to target Kubernetes Pods directly, rather than targeting nodes. This improves latency and distribution.
Prerequisites: Cluster must be VPC-native.
How it works: the cloud.google.com/neg annotation on a Service triggers
creation of a NEG that mirrors the Pod IPs. GKE often adds it for you — but not
always, and knowing which case you are in is the whole point.
# In your Kubernetes Service manifest metadata.annotations:
cloud.google.com/neg: '{"ingress": true}'
When the annotation is automatic (do not add it by hand):
GCE_VM_IP_PORT NEGs and requires a
VPC-native cluster.HttpLoadBalancing add-on enabled (on by default — do not disable it).
GKE then annotates Services automatically.When you must add it explicitly:
Not supported / no NEG fallback:
Scale consequence: without NEGs a cluster is capped at 1,000 nodes, and non-NEG Services behind Ingress stop functioning correctly beyond that. With NEGs there is no GKE node limit.
Private Service Connect allows you to expose services in one VPC to consumers in another VPC securely, without VPC peering.
Prerequisite: The backing Service must be an internal passthrough Network
Load Balancer — i.e. type: LoadBalancer with the
networking.gke.io/load-balancer-type: "Internal" annotation. The
ServiceAttachment requires this; a ClusterIP or external LoadBalancer Service
will not work.
Steps:
ServiceAttachment referencing that Service:
assets/service-attachment.yaml (sets connectionPreference, the PSC NAT
subnet, and the Service resourceRef).ServiceAttachment URI with consumers to create a PSC endpoint in
their VPC.To minimize cross-zone data transfer costs and network latency, configure Kubernetes Services with Topology Aware Routing. This routes traffic to Pods in the same zone as the originating client:
# In your Kubernetes Service manifest metadata.annotations:
service.kubernetes.io/topology-mode: auto
networking.gke.io/certmap annotation to work (gcloud services enable certificatemanager.googleapis.com); without it the Gateway fails to
provision the certificate map.gke-l7-regional-external-managed and gke-l7-rilb require a subnet with
--purpose=REGIONAL_MANAGED_PROXY in the region; the Gateway stays
unprogrammed without it.Provisioning until the domain's A/AAAA records point at the load balancer
IP, and can take 15-60 minutes after DNS is correct.