mirror of
https://github.com/hanzoai/skills.git
synced 2026-11-19 00:47:36 +00:00
hanzoskills.com/llms.txt now opens with the install line, the API reference index and the company index, so an agent that lands on any one of the three can find the rest. robots.txt claimed 537 documents while llms.txt counts 920. The number is gone from robots.txt; llms.txt derives it. public/ is regenerated from scripts/site.py, which it had fallen behind: the copy-prompt menu and agent bar were in the generator and not in the committed pages. tests/site.mjs passes against the result. Co-authored-by: Hanzo Dev <[email protected]>
657 lines
31 KiB
HTML
657 lines
31 KiB
HTML
<!doctype html>
|
|
<html lang="en"><head>
|
|
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>cloud-gcp-networking</title>
|
|
<meta name="color-scheme" content="dark">
|
|
<style>
|
|
/* Committed to one visual world: a dark instrument panel. No light variant —
|
|
the dot field and the hairline rules only read on black, and a naive
|
|
inversion would wash both out. Every colour is painted explicitly so the page
|
|
never borrows a host background. */
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Pixel Square';src:url('/fonts/ZenPixel-Square.woff2') format('woff2');font-style:normal;font-display:swap}
|
|
|
|
:root{
|
|
--ink:#f4f4f2; --soft:#9c9c98; --faint:#6a6a66; --ground:#000; --panel:#0a0a0a;
|
|
--line:#232323; --line-hi:#3a3a3a; --accent:#f4f4f2;
|
|
--font-zen-sans:'Zen',-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
|
|
--font-zen-mono:'Zen Mono',ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
|
|
--font-zen-pixel-square:'Zen Pixel Square',monospace;
|
|
--mono:var(--font-zen-mono);
|
|
--sans:var(--font-zen-sans);
|
|
/* Controls are pills and surfaces are soft, as on hanzo.ai. */
|
|
--r:999px; --r-soft:14px;
|
|
}
|
|
*{box-sizing:border-box}
|
|
html{-webkit-text-size-adjust:100%}
|
|
body{margin:0;background:var(--ground);color:var(--ink);font-family:var(--sans);
|
|
font-size:16px;line-height:1.65;-webkit-font-smoothing:antialiased}
|
|
.wrap{max-width:60rem;margin:0 auto;padding:0 1.75rem}
|
|
|
|
/* The dot field. A halftone made of one repeating radial-gradient, faded out
|
|
along the diagonal by a mask so it reads as a wave rather than wallpaper. */
|
|
/* No overflow clip here: the dot field is inset to the box already, and a clip
|
|
would cut off the copy-prompt menu. */
|
|
.hero{position:relative;border-bottom:1px solid var(--line)}
|
|
.hero::before{content:"";position:absolute;inset:0;
|
|
background-image:radial-gradient(var(--line-hi) 1px, transparent 1px);
|
|
background-size:7px 7px;
|
|
-webkit-mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
pointer-events:none}
|
|
.hero .wrap{position:relative;padding-top:5.5rem;padding-bottom:4rem}
|
|
|
|
nav{border-bottom:1px solid var(--line)}
|
|
nav .in{max-width:60rem;margin:0 auto;padding:1.1rem 1.75rem;display:flex;
|
|
justify-content:space-between;align-items:center;gap:1rem}
|
|
.brand{font-family:var(--mono);font-size:.85rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--ink);text-decoration:none;
|
|
display:inline-flex;align-items:center;gap:.6rem}
|
|
.brand i{font-style:normal;color:var(--faint)}
|
|
.mark{width:1.15em;height:1.15em;display:block;flex:0 0 auto}
|
|
nav a.up{font-family:var(--mono);font-size:.72rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--soft);text-decoration:none}
|
|
nav a.up:hover{color:var(--ink)}
|
|
|
|
h1{font-family:var(--mono);font-size:clamp(2rem,5.4vw,3.4rem);line-height:1.12;
|
|
letter-spacing:-.02em;margin:0 0 1.1rem;font-weight:500;text-wrap:balance}
|
|
h1 em{font-style:normal;color:var(--faint)}
|
|
.lede{color:var(--soft);font-size:1.05rem;max-width:52ch;margin:0 0 2.25rem}
|
|
|
|
.btns{display:flex;flex-wrap:wrap;gap:.7rem;margin:0 0 .5rem;align-items:center}
|
|
.btn{display:inline-flex;align-items:center;gap:.5rem;font-family:var(--mono);
|
|
font-size:.72rem;letter-spacing:.14em;text-transform:uppercase;
|
|
padding:.8rem 1.4rem;border:1px solid var(--line-hi);border-radius:var(--r);
|
|
color:var(--ink);text-decoration:none;background:transparent;cursor:pointer;
|
|
line-height:1.2;font-weight:400}
|
|
.btn:hover{background:#141414;text-decoration:none;border-color:var(--soft)}
|
|
.btn.solid{background:var(--ink);color:#000;border-color:var(--ink)}
|
|
.btn.solid:hover{background:#d8d8d4}
|
|
.btn .chev{width:.7em;height:.7em;flex:0 0 auto;transition:transform .15s ease}
|
|
.btn[aria-expanded="true"] .chev{transform:rotate(180deg)}
|
|
|
|
/* Copy-prompt selector. Each row copies the prompt for its own target. */
|
|
.copy{position:relative;display:inline-flex}
|
|
.menu{position:absolute;top:calc(100% + .5rem);left:0;z-index:20;min-width:21rem;
|
|
background:var(--panel);border:1px solid var(--line-hi);border-radius:var(--r-soft);
|
|
padding:.4rem;display:flex;flex-direction:column;
|
|
box-shadow:0 12px 32px rgba(0,0,0,.75)}
|
|
.menu[hidden]{display:none}
|
|
.mi{display:flex;align-items:center;gap:.7rem;width:100%;text-align:left;
|
|
padding:.62rem .8rem;border:0;border-radius:calc(var(--r-soft) - .35rem);
|
|
background:transparent;color:var(--ink);font-family:var(--mono);font-size:.76rem;
|
|
letter-spacing:.04em;text-decoration:none;cursor:pointer;line-height:1.3;
|
|
white-space:nowrap}
|
|
.mi:hover,.mi:focus-visible{background:#181818;outline:none}
|
|
.mi .mark{width:1.05rem;height:1.05rem;color:var(--soft)}
|
|
.mi:hover .mark{color:var(--ink)}
|
|
.mi u{margin-left:auto;color:var(--faint);text-decoration:none;font-size:.68rem;
|
|
letter-spacing:.1em;text-transform:uppercase}
|
|
|
|
/* Works-with bar: one scrolling row, name and mark per agent. */
|
|
.strip{border-bottom:1px solid var(--line);background:var(--panel)}
|
|
.strip .in{max-width:60rem;margin:0 auto;padding:.9rem 1.75rem;display:flex;
|
|
align-items:center;gap:1.25rem;font-family:var(--mono);font-size:.72rem;
|
|
letter-spacing:.1em;text-transform:uppercase;color:var(--faint)}
|
|
.strip b{color:var(--soft);font-weight:400;flex:0 0 auto;
|
|
border-right:1px solid var(--line);padding-right:1.25rem;align-self:stretch;
|
|
display:flex;align-items:center}
|
|
.bar{display:flex;align-items:center;gap:.5rem;flex:1 1 auto;min-width:0;
|
|
overflow-x:auto;scrollbar-width:none;scroll-snap-type:x proximity;
|
|
-webkit-overflow-scrolling:touch;
|
|
-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent);
|
|
mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent)}
|
|
.bar::-webkit-scrollbar{display:none}
|
|
.agent{display:inline-flex;align-items:center;gap:.45rem;flex:0 0 auto;
|
|
padding:.4rem .85rem;border:1px solid var(--line);border-radius:var(--r);
|
|
color:var(--soft);white-space:nowrap;scroll-snap-align:start;
|
|
text-decoration:none;background:var(--ground)}
|
|
.agent:hover{color:var(--ink);border-color:var(--line-hi);text-decoration:none}
|
|
.agent .mark{width:.95rem;height:.95rem}
|
|
|
|
h2{font-family:var(--mono);font-size:1.1rem;letter-spacing:-.01em;margin:2.75rem 0 .75rem;font-weight:500}
|
|
h3{font-size:1rem;margin:2rem 0 .5rem;font-weight:600}
|
|
h4,h5,h6{font-size:.94rem;margin:1.5rem 0 .5rem;font-weight:600}
|
|
p{margin:0 0 1rem;max-width:70ch}
|
|
ul,ol{margin:0 0 1rem;padding-left:1.35rem;max-width:70ch}
|
|
li{margin:.22rem 0}
|
|
a{color:var(--ink);text-decoration:underline;text-underline-offset:3px;
|
|
text-decoration-color:var(--line-hi)}
|
|
a:hover{text-decoration-color:var(--ink)}
|
|
a:focus-visible{outline:1px solid var(--ink);outline-offset:3px}
|
|
code{font-family:var(--mono);font-size:.85em;background:var(--panel);
|
|
border:1px solid var(--line);border-radius:5px;padding:.1em .36em}
|
|
pre{background:var(--panel);border:1px solid var(--line);padding:1rem 1.1rem;
|
|
border-radius:var(--r-soft);overflow-x:auto;margin:0 0 1.25rem}
|
|
pre code{background:none;border:0;padding:0;font-size:.82rem;line-height:1.7}
|
|
blockquote{margin:0 0 1rem;padding-left:1rem;border-left:1px solid var(--line-hi);color:var(--soft)}
|
|
hr{border:0;border-top:1px solid var(--line);margin:2.5rem 0}
|
|
table{border-collapse:collapse;width:100%;margin:0 0 1.25rem;font-size:.92rem;
|
|
display:block;overflow-x:auto}
|
|
th,td{border:1px solid var(--line);padding:.5rem .7rem;text-align:left}
|
|
|
|
.curl{display:block;background:var(--panel);border:1px solid var(--line);
|
|
border-radius:var(--r-soft);padding:.95rem 1.1rem;font-family:var(--mono);
|
|
font-size:.8rem;color:var(--soft);overflow-x:auto;margin:0 0 2.5rem;
|
|
white-space:pre;line-height:1.9}
|
|
.curl b{color:var(--ink);font-weight:400}
|
|
.curl i{font-style:normal;color:var(--faint)}
|
|
|
|
/* index */
|
|
#q{width:100%;padding:.85rem 1.2rem;font-family:var(--mono);font-size:.85rem;color:var(--ink);
|
|
background:var(--panel);border:1px solid var(--line);border-radius:var(--r);margin:0 0 .6rem}
|
|
#q::placeholder{color:var(--faint);text-transform:uppercase;letter-spacing:.1em;font-size:.72rem}
|
|
#q:focus{outline:none;border-color:var(--soft)}
|
|
#count{color:var(--faint);font-family:var(--mono);font-size:.72rem;letter-spacing:.1em;
|
|
text-transform:uppercase;margin:0 0 2rem}
|
|
.cat{margin:2.5rem 0 .5rem;font-family:var(--mono);font-size:.7rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);border-bottom:1px solid var(--line);
|
|
padding-bottom:.45rem}
|
|
.row{display:block;padding:.6rem .9rem;margin:0 -.9rem;border-bottom:1px solid var(--line);
|
|
border-radius:var(--r-soft);text-decoration:none}
|
|
.row:hover{background:#0a0a0a}
|
|
.nm{font-family:var(--mono);font-size:.84rem;color:var(--ink);display:block}
|
|
.ds{color:var(--soft);font-size:.9rem;display:block;margin-top:.12rem}
|
|
footer{margin-top:4rem;padding:2rem 0 4rem;border-top:1px solid var(--line);
|
|
color:var(--faint);font-size:.85rem}
|
|
footer a{color:var(--soft)}
|
|
.fmap{display:grid;gap:1.75rem;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));
|
|
margin:0 0 2rem;font-size:.85rem}
|
|
.fmap b{display:block;font-family:var(--mono);font-size:.68rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);font-weight:400;margin:0 0 .6rem;
|
|
border-bottom:1px solid var(--line);padding-bottom:.4rem}
|
|
.fmap a{display:inline-block;color:var(--ink);text-decoration:none;margin:.3rem .35rem 0 0}
|
|
.fmap a:hover{text-decoration:underline}
|
|
.fmap div{color:var(--faint);line-height:1.5}
|
|
.fend{border-top:1px solid var(--line);padding-top:1.25rem;font-size:.82rem}
|
|
|
|
@media (max-width:640px){
|
|
.hero .wrap{padding-top:3.25rem;padding-bottom:2.75rem}
|
|
.btns{gap:.5rem}
|
|
.btn{padding:.75rem 1.15rem;font-size:.68rem}
|
|
.copy,.copy .btn{width:100%;justify-content:center}
|
|
.menu{left:0;right:0;min-width:0}
|
|
.strip .in{flex-direction:column;align-items:flex-start;gap:.6rem;padding:.9rem 1.75rem}
|
|
.strip b{border-right:0;padding-right:0}
|
|
.bar{width:100%}
|
|
}
|
|
</style>
|
|
<link rel="alternate" type="text/markdown" href="/cloud-gcp-networking.md">
|
|
|
|
<link rel="icon" href="/favicon.svg">
|
|
<link rel="canonical" href="https://hanzoskills.com/cloud-gcp-networking">
|
|
</head>
|
|
<!-- Reading this with a machine? Every page here is also plain markdown.
|
|
This one: https://hanzoskills.com/cloud-gcp-networking.md
|
|
Index: https://hanzoskills.com/llms.txt
|
|
Corpus: https://hanzoskills.com/all.md
|
|
Append .md to any path for the markdown twin. -->
|
|
<body>
|
|
<nav><div class="in">
|
|
<a class="brand" href="/"><svg class="mark" viewBox="0 0 67 67" fill="currentColor" aria-hidden="true"><path d="M22.21 67V44.6369H0V67H22.21Z"/><path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z"/><path d="M22.21 0H0V22.3184H22.21V0Z"/><path d="M66.7198 0H44.5098V22.3184H66.7198V0Z"/><path d="M66.7198 67V44.6369H44.5098V67H66.7198Z"/></svg> HANZO<i>SKILLS</i></a>
|
|
<a class="up" href="/">All skills</a>
|
|
</div></nav>
|
|
|
|
<div class="wrap">
|
|
<h1>cloud-gcp-networking</h1><p class="lede">Google Cloud networking including VPC, firewall, DNS, CDN, and load balancing</p><h1>GCP Networking Services</h1>
|
|
<p><strong>Scope</strong>: VPC networks, firewall rules, Cloud DNS, Cloud CDN, and load balancing configurations <strong>Lines</strong>: ~320 <strong>Last Updated</strong>: 2025-10-25 <strong>Format Version</strong>: 1.0 (Atomic)</p>
|
|
<hr>
|
|
<h2>When to Use This Skill</h2>
|
|
<p>Activate this skill when:</p>
|
|
<ul><li>Setting up VPC networks and subnets for GCP resources</li><li>Configuring firewall rules and network security policies</li><li>Implementing Cloud DNS for domain management</li><li>Enabling Cloud CDN for content delivery and caching</li><li>Deploying load balancers for high availability and scaling</li><li>Connecting on-premises networks via VPN or Cloud Interconnect</li><li>Setting up Private Google Access for VM-to-service communication</li><li>Optimizing network performance and reducing egress costs</li></ul>
|
|
<h2>Core Concepts</h2>
|
|
<h3>Concept 1: VPC Networks and Subnets</h3>
|
|
<p><strong>VPC modes</strong>:</p>
|
|
<ul><li><strong>Auto mode</strong>: GCP creates subnets automatically in each region</li><li><strong>Custom mode</strong>: User defines subnets and IP ranges (recommended for production)</li><li><strong>Shared VPC</strong>: Share VPC across multiple projects in organization</li></ul>
|
|
<pre><code class="lang-bash"># Create custom VPC network
|
|
gcloud compute networks create production-vpc \
|
|
--subnet-mode=custom \
|
|
--bgp-routing-mode=regional
|
|
|
|
# Create subnets in different regions
|
|
gcloud compute networks subnets create us-central-subnet \
|
|
--network=production-vpc \
|
|
--region=us-central1 \
|
|
--range=10.0.1.0/24 \
|
|
--enable-private-ip-google-access
|
|
|
|
gcloud compute networks subnets create europe-subnet \
|
|
--network=production-vpc \
|
|
--region=europe-west1 \
|
|
--range=10.0.2.0/24 \
|
|
--enable-private-ip-google-access
|
|
|
|
# Create instance in custom subnet
|
|
gcloud compute instances create web-server \
|
|
--zone=us-central1-a \
|
|
--subnet=us-central-subnet \
|
|
--no-address # No external IP (use Private Google Access)</code></pre>
|
|
<h3>Concept 2: Firewall Rules</h3>
|
|
<p><strong>Rule components</strong>:</p>
|
|
<ul><li><strong>Direction</strong>: Ingress (incoming) or egress (outgoing)</li><li><strong>Priority</strong>: Lower numbers = higher priority (0-65535)</li><li><strong>Target</strong>: All instances, tags, or service accounts</li><li><strong>Source/Destination</strong>: IP ranges, tags, or service accounts</li></ul>
|
|
<pre><code class="lang-bash"># Allow SSH from specific IP range
|
|
gcloud compute firewall-rules create allow-ssh \
|
|
--network=production-vpc \
|
|
--allow=tcp:22 \
|
|
--source-ranges=203.0.113.0/24 \
|
|
--description="Allow SSH from office"
|
|
|
|
# Allow HTTP/HTTPS with network tags
|
|
gcloud compute firewall-rules create allow-web \
|
|
--network=production-vpc \
|
|
--allow=tcp:80,tcp:443 \
|
|
--source-ranges=0.0.0.0/0 \
|
|
--target-tags=web-server
|
|
|
|
# Deny egress to specific IP (higher priority = lower number)
|
|
gcloud compute firewall-rules create deny-malicious-ip \
|
|
--network=production-vpc \
|
|
--direction=EGRESS \
|
|
--action=DENY \
|
|
--rules=all \
|
|
--destination-ranges=198.51.100.0/24 \
|
|
--priority=100</code></pre>
|
|
<h3>Concept 3: Cloud Load Balancing</h3>
|
|
<p><strong>Load balancer types</strong>:</p>
|
|
<ul><li><strong>HTTP(S)</strong>: Layer 7, global, content-based routing</li><li><strong>TCP/SSL Proxy</strong>: Layer 4, global, TCP with SSL termination</li><li><strong>Network</strong>: Layer 4, regional, pass-through</li><li><strong>Internal</strong>: Layer 4, regional, internal traffic only</li></ul>
|
|
<pre><code class="lang-python">from google.cloud import compute_v1
|
|
|
|
def create_https_load_balancer(project_id):
|
|
# Create backend service
|
|
backend_client = compute_v1.BackendServicesClient()
|
|
backend_service = compute_v1.BackendService(
|
|
name='web-backend',
|
|
protocol='HTTP',
|
|
port_name='http',
|
|
timeout_sec=30,
|
|
health_checks=[f'projects/{project_id}/global/healthChecks/web-health-check'],
|
|
backends=[
|
|
compute_v1.Backend(
|
|
group=f'projects/{project_id}/zones/us-central1-a/instanceGroups/web-mig'
|
|
)
|
|
]
|
|
)
|
|
backend_client.insert(project=project_id, backend_service_resource=backend_service)
|
|
|
|
# Create URL map (routing rules)
|
|
url_maps_client = compute_v1.UrlMapsClient()
|
|
url_map = compute_v1.UrlMap(
|
|
name='web-url-map',
|
|
default_service=f'projects/{project_id}/global/backendServices/web-backend'
|
|
)
|
|
url_maps_client.insert(project=project_id, url_map_resource=url_map)
|
|
|
|
# Create HTTPS proxy
|
|
proxy_client = compute_v1.TargetHttpsProxiesClient()
|
|
https_proxy = compute_v1.TargetHttpsProxy(
|
|
name='web-https-proxy',
|
|
url_map=f'projects/{project_id}/global/urlMaps/web-url-map',
|
|
ssl_certificates=[f'projects/{project_id}/global/sslCertificates/web-cert']
|
|
)
|
|
proxy_client.insert(project=project_id, target_https_proxy_resource=https_proxy)
|
|
|
|
# Create forwarding rule (external IP + port)
|
|
forwarding_client = compute_v1.GlobalForwardingRulesClient()
|
|
forwarding_rule = compute_v1.ForwardingRule(
|
|
name='web-forwarding-rule',
|
|
ip_protocol='TCP',
|
|
port_range='443',
|
|
target=f'projects/{project_id}/global/targetHttpsProxies/web-https-proxy'
|
|
)
|
|
forwarding_client.insert(project=project_id, forwarding_rule_resource=forwarding_rule)</code></pre>
|
|
<h3>Concept 4: Cloud CDN</h3>
|
|
<p><strong>CDN features</strong>:</p>
|
|
<ul><li>Cache static content at Google edge locations (200+ POPs)</li><li>Reduce origin load and improve latency</li><li>Cache modes: USE_ORIGIN_HEADERS, CACHE_ALL_STATIC, FORCE_CACHE_ALL</li></ul>
|
|
<pre><code class="lang-bash"># Enable Cloud CDN on backend service
|
|
gcloud compute backend-services update web-backend \
|
|
--enable-cdn \
|
|
--cache-mode=CACHE_ALL_STATIC \
|
|
--default-ttl=3600 \
|
|
--max-ttl=86400 \
|
|
--client-ttl=3600 \
|
|
--global
|
|
|
|
# Create signed URL for private content
|
|
gcloud compute sign-url https://example.com/private/video.mp4 \
|
|
--key-name=cdn-key \
|
|
--key-file=private-key.pem \
|
|
--expires-in=1h
|
|
|
|
# Invalidate cache
|
|
gcloud compute url-maps invalidate-cdn-cache web-url-map \
|
|
--path="/static/*" \
|
|
--global</code></pre>
|
|
<hr>
|
|
<h2>Patterns</h2>
|
|
<h3>Pattern 1: Shared VPC for Multi-Project Organization</h3>
|
|
<p><strong>When to use</strong>:</p>
|
|
<ul><li>Centralize network administration across projects</li><li>Share common network resources (VPN, firewall rules)</li></ul>
|
|
<pre><code class="lang-bash"># ❌ Bad: Each project creates separate VPC (management overhead)
|
|
# Project A creates VPC, Project B creates VPC, etc.
|
|
# Duplicate firewall rules, multiple VPN tunnels
|
|
|
|
# ✅ Good: Use Shared VPC
|
|
# Enable Shared VPC in host project
|
|
gcloud compute shared-vpc enable HOST_PROJECT
|
|
|
|
# Attach service projects
|
|
gcloud compute shared-vpc associated-projects add SERVICE_PROJECT_1 \
|
|
--host-project=HOST_PROJECT
|
|
|
|
gcloud compute shared-vpc associated-projects add SERVICE_PROJECT_2 \
|
|
--host-project=HOST_PROJECT
|
|
|
|
# Service projects can now use subnets from host project
|
|
gcloud compute instances create app-server \
|
|
--project=SERVICE_PROJECT_1 \
|
|
--zone=us-central1-a \
|
|
--subnet=projects/HOST_PROJECT/regions/us-central1/subnetworks/shared-subnet</code></pre>
|
|
<p><strong>Benefits</strong>:</p>
|
|
<ul><li>Centralized network policy enforcement</li><li>Reduced complexity and administration overhead</li><li>Consistent security posture across organization</li></ul>
|
|
<h3>Pattern 2: Private Google Access</h3>
|
|
<p><strong>Use case</strong>: Access Google services (Cloud Storage, BigQuery) from instances without external IPs</p>
|
|
<pre><code class="lang-bash"># Enable Private Google Access on subnet
|
|
gcloud compute networks subnets update us-central-subnet \
|
|
--region=us-central1 \
|
|
--enable-private-ip-google-access
|
|
|
|
# Create instance without external IP
|
|
gcloud compute instances create private-instance \
|
|
--zone=us-central1-a \
|
|
--subnet=us-central-subnet \
|
|
--no-address
|
|
|
|
# Instance can now access Cloud Storage without external IP
|
|
# SSH via Cloud Identity-Aware Proxy
|
|
gcloud compute ssh private-instance \
|
|
--zone=us-central1-a \
|
|
--tunnel-through-iap</code></pre>
|
|
<h3>Pattern 3: Cloud Armor Security Policies</h3>
|
|
<p><strong>Use case</strong>: Protect applications from DDoS and web attacks</p>
|
|
<pre><code class="lang-bash"># Create Cloud Armor security policy
|
|
gcloud compute security-policies create web-security-policy \
|
|
--description="Protect web application"
|
|
|
|
# Block traffic from specific countries
|
|
gcloud compute security-policies rules create 1000 \
|
|
--security-policy=web-security-policy \
|
|
--expression="origin.region_code == 'CN' || origin.region_code == 'RU'" \
|
|
--action=deny-403 \
|
|
--description="Block traffic from specific countries"
|
|
|
|
# Rate limit requests
|
|
gcloud compute security-policies rules create 2000 \
|
|
--security-policy=web-security-policy \
|
|
--expression="true" \
|
|
--action=rate-based-ban \
|
|
--rate-limit-threshold-count=100 \
|
|
--rate-limit-threshold-interval-sec=60 \
|
|
--ban-duration-sec=600 \
|
|
--description="Rate limit: 100 req/min"
|
|
|
|
# Attach to backend service
|
|
gcloud compute backend-services update web-backend \
|
|
--security-policy=web-security-policy \
|
|
--global</code></pre>
|
|
<h3>Pattern 4: Cloud DNS with DNSSEC</h3>
|
|
<p><strong>Use case</strong>: Secure DNS resolution with cryptographic signatures</p>
|
|
<pre><code class="lang-bash"># Create managed DNS zone
|
|
gcloud dns managed-zones create production-zone \
|
|
--dns-name=example.com. \
|
|
--description="Production DNS zone"
|
|
|
|
# Enable DNSSEC
|
|
gcloud dns managed-zones update production-zone \
|
|
--dnssec-state=on
|
|
|
|
# Add DNS records
|
|
gcloud dns record-sets create www.example.com. \
|
|
--zone=production-zone \
|
|
--type=A \
|
|
--ttl=300 \
|
|
--rrdatas=203.0.113.1
|
|
|
|
gcloud dns record-sets create api.example.com. \
|
|
--zone=production-zone \
|
|
--type=CNAME \
|
|
--ttl=300 \
|
|
--rrdatas=web-lb.example.com.
|
|
|
|
# Create private DNS zone for internal resources
|
|
gcloud dns managed-zones create internal-zone \
|
|
--dns-name=internal.example.com. \
|
|
--description="Internal DNS" \
|
|
--visibility=private \
|
|
--networks=production-vpc</code></pre>
|
|
<h3>Pattern 5: Content-Based Routing with URL Maps</h3>
|
|
<p><strong>Use case</strong>: Route requests to different backends based on URL path</p>
|
|
<pre><code class="lang-bash"># Create backend services for different apps
|
|
gcloud compute backend-services create api-backend --global
|
|
gcloud compute backend-services create web-backend --global
|
|
gcloud compute backend-services create admin-backend --global
|
|
|
|
# Create URL map with path-based routing
|
|
gcloud compute url-maps create multi-service-lb \
|
|
--default-service=web-backend
|
|
|
|
gcloud compute url-maps add-path-matcher multi-service-lb \
|
|
--path-matcher-name=main \
|
|
--default-service=web-backend \
|
|
--path-rules="/api/*=api-backend,/admin/*=admin-backend"
|
|
|
|
# Example routing:
|
|
# example.com/ -> web-backend
|
|
# example.com/api/users -> api-backend
|
|
# example.com/admin/ -> admin-backend</code></pre>
|
|
<h3>Pattern 6: Cloud VPN for Hybrid Connectivity</h3>
|
|
<p><strong>Use case</strong>: Securely connect on-premises network to GCP VPC</p>
|
|
<pre><code class="lang-bash"># Create VPN gateway
|
|
gcloud compute target-vpn-gateways create on-prem-vpn-gateway \
|
|
--network=production-vpc \
|
|
--region=us-central1
|
|
|
|
# Reserve static IP for VPN gateway
|
|
gcloud compute addresses create vpn-gateway-ip \
|
|
--region=us-central1
|
|
|
|
# Create forwarding rules
|
|
gcloud compute forwarding-rules create vpn-rule-esp \
|
|
--region=us-central1 \
|
|
--ip-protocol=ESP \
|
|
--address=vpn-gateway-ip \
|
|
--target-vpn-gateway=on-prem-vpn-gateway
|
|
|
|
# Create VPN tunnel
|
|
gcloud compute vpn-tunnels create on-prem-tunnel \
|
|
--region=us-central1 \
|
|
--peer-address=203.0.113.1 \
|
|
--shared-secret=SHARED_SECRET \
|
|
--ike-version=2 \
|
|
--target-vpn-gateway=on-prem-vpn-gateway \
|
|
--local-traffic-selector=10.0.0.0/16 \
|
|
--remote-traffic-selector=192.168.0.0/16
|
|
|
|
# Create route to on-prem network
|
|
gcloud compute routes create on-prem-route \
|
|
--network=production-vpc \
|
|
--destination-range=192.168.0.0/16 \
|
|
--next-hop-vpn-tunnel=on-prem-tunnel \
|
|
--next-hop-vpn-tunnel-region=us-central1</code></pre>
|
|
<h3>Pattern 7: Health Checks for Load Balancers</h3>
|
|
<p><strong>Use case</strong>: Automatically remove unhealthy instances from load balancer pool</p>
|
|
<pre><code class="lang-bash"># Create health check
|
|
gcloud compute health-checks create http web-health-check \
|
|
--port=80 \
|
|
--request-path=/health \
|
|
--check-interval=10s \
|
|
--timeout=5s \
|
|
--unhealthy-threshold=3 \
|
|
--healthy-threshold=2
|
|
|
|
# Attach to backend service
|
|
gcloud compute backend-services update web-backend \
|
|
--health-checks=web-health-check \
|
|
--global
|
|
|
|
# Health check endpoint should return 200 OK when healthy</code></pre>
|
|
<pre><code class="lang-python"># Flask health check endpoint
|
|
from flask import Flask, jsonify
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/health')
|
|
def health_check():
|
|
# Check database connectivity, dependencies, etc.
|
|
try:
|
|
db.execute("SELECT 1")
|
|
return jsonify({"status": "healthy"}), 200
|
|
except Exception as e:
|
|
return jsonify({"status": "unhealthy", "error": str(e)}), 503</code></pre>
|
|
<h3>Pattern 8: Network Tags for Firewall Targeting</h3>
|
|
<p><strong>Use case</strong>: Apply firewall rules to specific instance groups using tags</p>
|
|
<pre><code class="lang-bash"># Create firewall rule targeting web servers
|
|
gcloud compute firewall-rules create allow-web-traffic \
|
|
--network=production-vpc \
|
|
--allow=tcp:80,tcp:443 \
|
|
--source-ranges=0.0.0.0/0 \
|
|
--target-tags=web-server
|
|
|
|
# Create firewall rule for database access (only from app servers)
|
|
gcloud compute firewall-rules create allow-db-from-app \
|
|
--network=production-vpc \
|
|
--allow=tcp:5432 \
|
|
--source-tags=app-server \
|
|
--target-tags=database-server
|
|
|
|
# Create instance with tags
|
|
gcloud compute instances create web-1 \
|
|
--zone=us-central1-a \
|
|
--tags=web-server
|
|
|
|
gcloud compute instances create db-1 \
|
|
--zone=us-central1-a \
|
|
--tags=database-server \
|
|
--no-address # No external IP for security</code></pre>
|
|
<hr>
|
|
<h2>Quick Reference</h2>
|
|
<h3>Load Balancer Selection</h3>
|
|
<pre><code>Type | Layer | Scope | Use Case
|
|
----------------|-------|---------|---------------------------
|
|
HTTP(S) | 7 | Global | Web apps, content routing
|
|
TCP/SSL Proxy | 4 | Global | Non-HTTP with SSL
|
|
Network | 4 | Regional| Low latency, pass-through
|
|
Internal HTTP(S)| 7 | Regional| Internal microservices
|
|
Internal TCP/UDP| 4 | Regional| Internal databases</code></pre>
|
|
<h3>Firewall Rule Priority</h3>
|
|
<pre><code>Priority | Use Case
|
|
---------|----------------------------------
|
|
0-99 | Critical deny rules
|
|
100-999 | Standard security rules
|
|
1000+ | Application-specific rules
|
|
65535 | Default allow rules</code></pre>
|
|
<h3>Key gcloud Commands</h3>
|
|
<pre><code class="lang-bash"># VPC
|
|
gcloud compute networks create VPC --subnet-mode=custom
|
|
gcloud compute networks subnets create SUBNET --network=VPC --range=CIDR
|
|
|
|
# Firewall
|
|
gcloud compute firewall-rules create RULE --network=VPC --allow=PROTOCOL:PORT
|
|
gcloud compute firewall-rules list --network=VPC
|
|
|
|
# Load Balancing
|
|
gcloud compute backend-services create NAME --global
|
|
gcloud compute url-maps create NAME --default-service=BACKEND
|
|
gcloud compute forwarding-rules create NAME --global --target-http-proxy=PROXY
|
|
|
|
# DNS
|
|
gcloud dns managed-zones create ZONE --dns-name=DOMAIN
|
|
gcloud dns record-sets create NAME --zone=ZONE --type=TYPE --rrdatas=DATA</code></pre>
|
|
<h3>Key Guidelines</h3>
|
|
<pre><code>✅ DO: Use custom VPC mode for production environments
|
|
✅ DO: Enable Private Google Access to reduce egress costs
|
|
✅ DO: Tag instances for granular firewall rule targeting
|
|
✅ DO: Use Cloud CDN for static content delivery
|
|
✅ DO: Implement health checks for all load-balanced services
|
|
✅ DO: Enable DNSSEC for public DNS zones
|
|
|
|
❌ DON'T: Use auto-mode VPC for production (inflexible IP ranges)
|
|
❌ DON'T: Create overly permissive firewall rules (0.0.0.0/0 on all ports)
|
|
❌ DON'T: Forget to enable Private Google Access (increases egress costs)
|
|
❌ DON'T: Use Network load balancer when HTTP(S) features needed
|
|
❌ DON'T: Skip Cloud Armor for internet-facing applications</code></pre>
|
|
<hr>
|
|
<h2>Anti-Patterns</h2>
|
|
<h3>Critical Violations</h3>
|
|
<pre><code class="lang-bash"># ❌ NEVER: Create overly permissive firewall rules
|
|
gcloud compute firewall-rules create allow-all \
|
|
--network=production-vpc \
|
|
--allow=all \
|
|
--source-ranges=0.0.0.0/0
|
|
# Exposes all services to internet!
|
|
|
|
# ✅ CORRECT: Create specific rules with least privilege
|
|
gcloud compute firewall-rules create allow-web \
|
|
--network=production-vpc \
|
|
--allow=tcp:80,tcp:443 \
|
|
--source-ranges=0.0.0.0/0 \
|
|
--target-tags=web-server
|
|
|
|
gcloud compute firewall-rules create allow-ssh-from-office \
|
|
--network=production-vpc \
|
|
--allow=tcp:22 \
|
|
--source-ranges=203.0.113.0/24 \
|
|
--target-tags=ssh-access</code></pre>
|
|
<p>❌ <strong>Overly permissive rules</strong>: Allowing all protocols from all sources exposes services to attacks. ✅ <strong>Correct approach</strong>: Create specific rules for each service with source restrictions and target tags.</p>
|
|
<h3>Common Mistakes</h3>
|
|
<pre><code class="lang-bash"># ❌ Don't: Use auto-mode VPC in production
|
|
gcloud compute networks create production-vpc --subnet-mode=auto
|
|
# Cannot control IP ranges, subnet created in every region
|
|
|
|
# ✅ Correct: Use custom-mode VPC for control
|
|
gcloud compute networks create production-vpc --subnet-mode=custom
|
|
gcloud compute networks subnets create us-subnet \
|
|
--network=production-vpc \
|
|
--region=us-central1 \
|
|
--range=10.0.1.0/24</code></pre>
|
|
<p>❌ <strong>Auto-mode VPC in production</strong>: Cannot control IP ranges, wastes IP space, inflexible. ✅ <strong>Better</strong>: Use custom-mode VPC to define only needed subnets with appropriate CIDR ranges.</p>
|
|
<pre><code class="lang-bash"># ❌ Don't: Forget to enable Private Google Access
|
|
# Instances without external IPs cannot access Cloud Storage
|
|
gcloud compute instances create app-server \
|
|
--zone=us-central1-a \
|
|
--subnet=us-central-subnet \
|
|
--no-address
|
|
# gsutil commands fail!
|
|
|
|
# ✅ Correct: Enable Private Google Access on subnet
|
|
gcloud compute networks subnets update us-central-subnet \
|
|
--region=us-central1 \
|
|
--enable-private-ip-google-access</code></pre>
|
|
<p>❌ <strong>Missing Private Google Access</strong>: Instances without external IPs cannot reach Google services, increasing egress costs. ✅ <strong>Better</strong>: Enable Private Google Access on subnets to allow access to Google APIs without external IPs.</p>
|
|
<hr>
|
|
<h2>Related Skills</h2>
|
|
<ul><li><code>gcp-compute.md</code> - Creating instances in VPC subnets with network tags</li><li><code>gcp-iam-security.md</code> - Service accounts for network access control</li><li><code>gcp-databases.md</code> - Private IP configuration for Cloud SQL instances</li><li><code>gcp-serverless.md</code> - VPC connector for Cloud Run and Cloud Functions</li></ul>
|
|
<hr>
|
|
<p><strong>Last Updated</strong>: 2025-10-25 <strong>Format Version</strong>: 1.0 (Atomic)</p>
|
|
<footer>
|
|
<div class="fmap">
|
|
<div><b>Build</b>
|
|
<a href="https://hanzo.app">hanzo.app</a> app builder
|
|
<a href="https://hanzo.codes">hanzo.codes</a> code with an agent
|
|
<a href="https://hanzoskills.com">hanzoskills.com</a> what an agent reads</div>
|
|
<div><b>Run</b>
|
|
<a href="https://console.hanzo.ai">console.hanzo.ai</a> cloud console
|
|
<a href="https://api.hanzo.ai">api.hanzo.ai</a> the API</div>
|
|
<div><b>Account</b>
|
|
<a href="https://hanzo.id">hanzo.id</a> sign in
|
|
<a href="https://pay.hanzo.ai">pay.hanzo.ai</a> top up
|
|
<a href="https://billing.hanzo.ai">billing.hanzo.ai</a> invoices and usage</div>
|
|
<div><b>Company</b>
|
|
<a href="https://hanzo.ai">hanzo.ai</a> canonical
|
|
<a href="https://hanzo.ventures">hanzo.ventures</a> ventures</div>
|
|
</div>
|
|
<div class="fend"><a href="/cloud-gcp-networking.md">This page as plain text</a> · <a href="/llms.txt">Index for agents</a></div>
|
|
</footer>
|
|
</div></body></html> |