TL;DR
Master Google Cloud's networking services. Learn about Virtual Private Cloud (VPC), Cloud Load Balancing, Cloud CDN, Cloud Interconnect, and best practices for network design and security.
GCP Networking Services: Architecture and Best Practices
Google Cloud Platform provides a comprehensive suite of networking services to build secure, scalable, and high-performance applications. This guide covers key networking services and their implementation.
$1
`` graph TB
subgraph VPC["Virtual Private Cloud"]
direction TB
subgraph Networking["Core Networking"]
direction LR
SUBNET["Subnets"]
ROUTE["Routes"]
FW["Firewalls"]
end
subgraph LoadBalancing["Load Balancing"]
direction LR
GCLB["Global LB"]
RGLB["Regional LB"]
SSL["SSL Proxy"]
end
subgraph Connectivity["Connectivity"]
direction LR
VPN["Cloud VPN"]
IC["Cloud Interconnect"]
PS["Peering"]
end
end
subgraph Services["Network Services"]
direction TB
CDN["Cloud CDN"]
DNS["Cloud DNS"]
NAT["Cloud NAT"]
ARMOR["Cloud Armor"]
end
VPC --> Services
classDef primary fill:#4285f4,stroke:#666,stroke-width:2px,color:#fff
classDef secondary fill:#34a853,stroke:#666,stroke-width:2px,color:#fff
classDef tertiary fill:#fbbc05,stroke:#666,stroke-width:2px,color:#fff
class VPC,Networking primary
class LoadBalancing,Connectivity secondary
class Services tertiary
mermaid
`
$1
$1
` gcloud compute networks create my-vpc \
--subnet-mode=custom \
--bgp-routing-mode=regional gcloud compute networks subnets create subnet-1 \
--network=my-vpc \
--region=us-central1 \
--range=10.0.1.0/24 \
--secondary-range=services=192.168.1.0/24,pods=172.16.0.0/20 gcloud compute firewall-rules create allow-internal \
--network=my-vpc \
--allow=tcp,udp,icmp \
--source-ranges=10.0.0.0/8
bash
`Create VPC network
Create subnets
Create firewall rules
$1
` vpc:
name: my-vpc
subnets:
- name: subnet-1
region: us-central1
primary: 10.0.1.0/24
secondary:
- range_name: services
ip_range: 192.168.1.0/24
- range_name: pods
ip_range: 172.16.0.0/20
- name: subnet-2
region: europe-west1
primary: 10.0.2.0/24
firewall_rules:
- name: allow-internal
direction: INGRESS
priority: 1000
source_ranges: ["10.0.0.0/8"]
allow:
- protocol: tcp
- protocol: udp
- protocol: icmp
yaml
`network-config.yaml
$1
$1
` apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: "gce"
kubernetes.io/ingress.global-static-ip-name: "my-static-ip"
spec:
rules:
- host: my-app.example.com
http:
paths:
- path: /*
pathType: ImplementationSpecific
backend:
service:
name: my-service
port:
number: 80
yaml
`load-balancer.yaml
$1
` gcloud compute ssl-certificates create my-cert \
--domains=my-app.example.com gcloud compute target-ssl-proxies create my-ssl-proxy \
--ssl-certificates=my-cert \
--backend-service=my-backend-service
bash
`Create SSL certificate
Configure SSL proxy
$1
$1
` backends:
- name: my-backend
balancing_mode: UTILIZATION
capacity_scaler: 1.0
cdn_policy:
cache_mode: CACHE_ALL_STATIC
client_ttl: 3600
default_ttl: 3600
max_ttl: 86400
negative_caching: true
serve_while_stale: 86400
yaml
`cdn-config.yaml
$1
` gcloud compute backend-services update my-backend-service \
--enable-cdn \
--global gcloud compute backend-services update my-backend-service \
--global \
--cache-key-policy-include-host \
--cache-key-policy-include-protocol \
--cache-key-policy-include-query-string
bash
`Enable Cloud CDN
Configure cache key
$1
$1
` gcloud compute interconnects dedicated create my-interconnect \
--customer-name="My Company" \
--interconnect-type=IT_PRIVATE \
--location=my-location gcloud compute interconnects attachments dedicated create my-attachment \
--region=us-central1 \
--interconnect=my-interconnect \
--router=my-router \
--vlan=1234
bash
`Create interconnect
Create VLAN attachment
$1
` vpn_tunnel:
name: my-vpn
region: us-central1
peer_ip: "203.0.113.1"
shared_secret: "your-secret-key"
router: my-router
ike_version: 2
local_traffic_selector: ["10.0.1.0/24"]
remote_traffic_selector: ["192.168.1.0/24"]
yaml
`vpn-config.yaml
$1
$1
` securityPolicies:
- name: my-policy
rules:
- action: allow
priority: 1000
match:
versionedExpr: SRC_IPS_V1
config:
srcIpRanges: ["10.0.0.0/8"]
- action: deny(403)
priority: 2000
match:
versionedExpr: EXPR_V1
expr:
xss: {}
yaml
`security-policy.yaml
$1
` gcloud compute firewall-policies create my-policy \
--organization=123456789 gcloud compute firewall-policies rules create 1000 \
--firewall-policy=my-policy \
--action=allow \
--direction=INGRESS \
--enable-logging \
--target-service-accounts=my-sa@my-project.iam.gserviceaccount.com \
--layer4-configs=tcp:80,tcp:443
bash
`Create hierarchical firewall policy
Add rules to policy
$1
$1
` flowLogs:
enabled: true
aggregationInterval: "INTERVAL_5_SEC"
flowSampling: 0.5
metadata: "INCLUDE_ALL_METADATA"
yaml
`flow-logs.yaml
$1
` gcloud services enable \
networkmanagement.googleapis.com gcloud network-management connectivity-tests create my-test \
--source=projects/my-project/zones/us-central1-a/instances/source-vm \
--destination=projects/my-project/zones/us-central1-b/instances/dest-vm \
--protocol=TCP \
--port=80
bash
`Enable network intelligence
Create connectivity test
$1
$1
` gcloud compute addresses create my-address \
--network-tier=PREMIUM \
--region=us-central1 gcloud compute instances create my-instance \
--network-interface=network-tier=PREMIUM,subnet=subnet-1
bash
`Set network tier
Configure instance network interface
$1
` backendConfig:
timeoutSec: 30
connectionDraining:
drainingTimeoutSec: 300
sessionAffinity:
type: CLIENT_IP
cookieTtlSec: 3600
customRequestHeaders:
- "X-Client-Region: {client_region}"
- "X-Client-IP: {client_ip}"
yaml
``lb-optimization.yaml
$1
1. Network Design
- Use appropriate network tiers
- Optimize egress traffic
- Implement caching strategies
- Right-size load balancers
2. Traffic Management
- Use Cloud CDN effectively
- Optimize routing paths
- Monitor usage patterns
- Clean up unused resources
$1
1. Network Security
- Implement defense in depth
- Use Cloud Armor
- Enable flow logs
- Regular security audits
2. Performance
- Use Global Load Balancing
- Implement Cloud CDN
- Optimize routing
- Monitor latency
3. Reliability
- Design for high availability
- Use multiple regions
- Implement health checks
- Plan for disaster recovery
$1
GCP provides comprehensive networking services for building secure and scalable applications. Key takeaways:
For more information, refer to the official documentation:
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.