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]>
880 lines
29 KiB
HTML
880 lines
29 KiB
HTML
<!doctype html>
|
|
<html lang="en"><head>
|
|
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>infrastructure-kubernetes-basics</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="/infrastructure-kubernetes-basics.md">
|
|
|
|
<link rel="icon" href="/favicon.svg">
|
|
<link rel="canonical" href="https://hanzoskills.com/infrastructure-kubernetes-basics">
|
|
</head>
|
|
<!-- Reading this with a machine? Every page here is also plain markdown.
|
|
This one: https://hanzoskills.com/infrastructure-kubernetes-basics.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>infrastructure-kubernetes-basics</h1><p class="lede">Deploying containerized applications at scale</p><h1>Kubernetes Basics</h1>
|
|
<p><strong>Scope</strong>: Container orchestration with Kubernetes - Pods, Deployments, Services, ConfigMaps, Secrets, Ingress <strong>Lines</strong>: 378 <strong>Last Updated</strong>: 2025-10-18 <strong>Format Version</strong>: 1.0 (Atomic)</p>
|
|
<hr>
|
|
<h2>When to Use This Skill</h2>
|
|
<p><strong>Activate when</strong>:</p>
|
|
<ul><li>Deploying containerized applications at scale</li><li>Managing microservices architectures</li><li>Automating container orchestration and scaling</li><li>Implementing rolling updates and rollbacks</li><li>Managing application configuration and secrets</li><li>Setting up load balancing and service discovery</li></ul>
|
|
<p><strong>Prerequisites</strong>:</p>
|
|
<ul><li>Docker installed and basic Docker knowledge</li><li>kubectl CLI installed (<code>brew install kubectl</code> or from kubernetes.io)</li><li>Access to Kubernetes cluster (Minikube, EKS, GKE, AKS)</li><li>Basic understanding of YAML syntax</li><li>Container registry account (Docker Hub, ECR, GCR)</li></ul>
|
|
<p><strong>Common scenarios</strong>:</p>
|
|
<ul><li>Deploying web applications and APIs</li><li>Running batch jobs and cron tasks</li><li>Implementing blue-green deployments</li><li>Auto-scaling based on load</li><li>Managing multi-environment deployments</li><li>Service mesh implementation</li></ul>
|
|
<hr>
|
|
<h2>Core Concepts</h2>
|
|
<h3>1. Pods</h3>
|
|
<pre><code class="lang-yaml"># pod.yaml - Smallest deployable unit
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: nginx-pod
|
|
labels:
|
|
app: nginx
|
|
environment: production
|
|
spec:
|
|
containers:
|
|
- name: nginx
|
|
image: nginx:1.25
|
|
ports:
|
|
- containerPort: 80
|
|
name: http
|
|
resources:
|
|
requests:
|
|
memory: "64Mi"
|
|
cpu: "250m"
|
|
limits:
|
|
memory: "128Mi"
|
|
cpu: "500m"
|
|
env:
|
|
- name: ENVIRONMENT
|
|
value: "production"
|
|
livenessProbe:
|
|
httpGet:
|
|
path: /health
|
|
port: 80
|
|
initialDelaySeconds: 30
|
|
periodSeconds: 10
|
|
readinessProbe:
|
|
httpGet:
|
|
path: /ready
|
|
port: 80
|
|
initialDelaySeconds: 5
|
|
periodSeconds: 5
|
|
restartPolicy: Always</code></pre>
|
|
<h3>2. Deployments</h3>
|
|
<pre><code class="lang-yaml"># deployment.yaml - Manages ReplicaSets and rolling updates
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: web-app
|
|
labels:
|
|
app: web-app
|
|
spec:
|
|
replicas: 3
|
|
strategy:
|
|
type: RollingUpdate
|
|
rollingUpdate:
|
|
maxSurge: 1 # Max pods above desired count
|
|
maxUnavailable: 0 # Max pods unavailable during update
|
|
selector:
|
|
matchLabels:
|
|
app: web-app
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: web-app
|
|
version: v1.0.0
|
|
spec:
|
|
containers:
|
|
- name: web-app
|
|
image: myregistry/web-app:1.0.0
|
|
ports:
|
|
- containerPort: 8080
|
|
name: http
|
|
env:
|
|
- name: DATABASE_URL
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: db-credentials
|
|
key: url
|
|
- name: APP_CONFIG
|
|
valueFrom:
|
|
configMapKeyRef:
|
|
name: app-config
|
|
key: config.json
|
|
resources:
|
|
requests:
|
|
memory: "256Mi"
|
|
cpu: "500m"
|
|
limits:
|
|
memory: "512Mi"
|
|
cpu: "1000m"
|
|
livenessProbe:
|
|
httpGet:
|
|
path: /healthz
|
|
port: 8080
|
|
initialDelaySeconds: 30
|
|
periodSeconds: 10
|
|
timeoutSeconds: 5
|
|
failureThreshold: 3
|
|
readinessProbe:
|
|
httpGet:
|
|
path: /ready
|
|
port: 8080
|
|
initialDelaySeconds: 10
|
|
periodSeconds: 5</code></pre>
|
|
<h3>3. Services</h3>
|
|
<pre><code class="lang-yaml"># service-clusterip.yaml - Internal service
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: web-app-service
|
|
spec:
|
|
type: ClusterIP # Only accessible within cluster
|
|
selector:
|
|
app: web-app
|
|
ports:
|
|
- port: 80
|
|
targetPort: 8080
|
|
protocol: TCP
|
|
name: http
|
|
|
|
---
|
|
# service-loadbalancer.yaml - External load balancer
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: web-app-lb
|
|
spec:
|
|
type: LoadBalancer # Cloud provider load balancer
|
|
selector:
|
|
app: web-app
|
|
ports:
|
|
- port: 80
|
|
targetPort: 8080
|
|
protocol: TCP
|
|
|
|
---
|
|
# service-nodeport.yaml - Exposes on node IP
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: web-app-nodeport
|
|
spec:
|
|
type: NodePort # Accessible on node IP:NodePort
|
|
selector:
|
|
app: web-app
|
|
ports:
|
|
- port: 80
|
|
targetPort: 8080
|
|
nodePort: 30080 # 30000-32767 range</code></pre>
|
|
<h3>4. ConfigMaps</h3>
|
|
<pre><code class="lang-yaml"># configmap.yaml - Configuration data
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: app-config
|
|
data:
|
|
# Key-value pairs
|
|
log_level: "info"
|
|
max_connections: "100"
|
|
|
|
# File-like keys
|
|
config.json: |
|
|
{
|
|
"apiUrl": "https://api.example.com",
|
|
"timeout": 30,
|
|
"retries": 3
|
|
}
|
|
|
|
nginx.conf: |
|
|
server {
|
|
listen 80;
|
|
server_name _;
|
|
|
|
location / {
|
|
proxy_pass http://backend:8080;
|
|
proxy_set_header Host $host;
|
|
}
|
|
}
|
|
|
|
---
|
|
# Use ConfigMap in Pod
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: app-pod
|
|
spec:
|
|
containers:
|
|
- name: app
|
|
image: myapp:1.0
|
|
# Environment variables from ConfigMap
|
|
envFrom:
|
|
- configMapRef:
|
|
name: app-config
|
|
# Individual env vars
|
|
env:
|
|
- name: LOG_LEVEL
|
|
valueFrom:
|
|
configMapKeyRef:
|
|
name: app-config
|
|
key: log_level
|
|
# Mount as volume
|
|
volumeMounts:
|
|
- name: config-volume
|
|
mountPath: /etc/config
|
|
volumes:
|
|
- name: config-volume
|
|
configMap:
|
|
name: app-config
|
|
items:
|
|
- key: nginx.conf
|
|
path: nginx.conf</code></pre>
|
|
<h3>5. Secrets</h3>
|
|
<pre><code class="lang-yaml"># secret.yaml - Sensitive data (base64 encoded)
|
|
apiVersion: v1
|
|
kind: Secret
|
|
metadata:
|
|
name: db-credentials
|
|
type: Opaque
|
|
data:
|
|
username: YWRtaW4= # echo -n 'admin' | base64
|
|
password: cGFzc3dvcmQxMjM= # echo -n 'password123' | base64
|
|
url: cG9zdGdyZXM6Ly9hZG1pbjpwYXNzd29yZDEyM0BkYi5leGFtcGxlLmNvbTo1NDMyL215ZGI=
|
|
|
|
---
|
|
# Use Secret in Pod
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: db-client
|
|
spec:
|
|
containers:
|
|
- name: client
|
|
image: postgres:15
|
|
env:
|
|
- name: DB_USERNAME
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: db-credentials
|
|
key: username
|
|
- name: DB_PASSWORD
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: db-credentials
|
|
key: password
|
|
# Mount as files
|
|
volumeMounts:
|
|
- name: db-secret
|
|
mountPath: /etc/secrets
|
|
readOnly: true
|
|
volumes:
|
|
- name: db-secret
|
|
secret:
|
|
secretName: db-credentials</code></pre>
|
|
<h3>6. Ingress</h3>
|
|
<pre><code class="lang-yaml"># ingress.yaml - HTTP/HTTPS routing
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: Ingress
|
|
metadata:
|
|
name: app-ingress
|
|
annotations:
|
|
nginx.ingress.kubernetes.io/rewrite-target: /
|
|
cert-manager.io/cluster-issuer: "letsencrypt-prod"
|
|
spec:
|
|
ingressClassName: nginx
|
|
tls:
|
|
- hosts:
|
|
- app.example.com
|
|
secretName: app-tls-cert
|
|
rules:
|
|
- host: app.example.com
|
|
http:
|
|
paths:
|
|
- path: /api
|
|
pathType: Prefix
|
|
backend:
|
|
service:
|
|
name: api-service
|
|
port:
|
|
number: 80
|
|
- path: /
|
|
pathType: Prefix
|
|
backend:
|
|
service:
|
|
name: web-service
|
|
port:
|
|
number: 80</code></pre>
|
|
<hr>
|
|
<h2>Patterns</h2>
|
|
<h3>Multi-Container Pods</h3>
|
|
<pre><code class="lang-yaml"># Sidecar pattern - logging container
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: web-app-with-logging
|
|
spec:
|
|
containers:
|
|
# Main application container
|
|
- name: web-app
|
|
image: myapp:1.0
|
|
ports:
|
|
- containerPort: 8080
|
|
volumeMounts:
|
|
- name: shared-logs
|
|
mountPath: /var/log/app
|
|
|
|
# Sidecar logging container
|
|
- name: log-shipper
|
|
image: fluent/fluent-bit:2.0
|
|
volumeMounts:
|
|
- name: shared-logs
|
|
mountPath: /var/log/app
|
|
- name: fluent-bit-config
|
|
mountPath: /fluent-bit/etc/
|
|
|
|
volumes:
|
|
- name: shared-logs
|
|
emptyDir: {}
|
|
- name: fluent-bit-config
|
|
configMap:
|
|
name: fluent-bit-config</code></pre>
|
|
<h3>CronJobs</h3>
|
|
<pre><code class="lang-yaml"># cronjob.yaml - Scheduled jobs
|
|
apiVersion: batch/v1
|
|
kind: CronJob
|
|
metadata:
|
|
name: daily-backup
|
|
spec:
|
|
schedule: "0 2 * * *" # Daily at 2 AM UTC
|
|
successfulJobsHistoryLimit: 3
|
|
failedJobsHistoryLimit: 1
|
|
jobTemplate:
|
|
spec:
|
|
template:
|
|
spec:
|
|
containers:
|
|
- name: backup
|
|
image: backup-tool:1.0
|
|
env:
|
|
- name: BACKUP_TARGET
|
|
value: "s3://backups/daily"
|
|
- name: AWS_ACCESS_KEY_ID
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: aws-credentials
|
|
key: access_key_id
|
|
- name: AWS_SECRET_ACCESS_KEY
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: aws-credentials
|
|
key: secret_access_key
|
|
restartPolicy: OnFailure</code></pre>
|
|
<h3>Horizontal Pod Autoscaler</h3>
|
|
<pre><code class="lang-yaml"># hpa.yaml - Auto-scaling based on metrics
|
|
apiVersion: autoscaling/v2
|
|
kind: HorizontalPodAutoscaler
|
|
metadata:
|
|
name: web-app-hpa
|
|
spec:
|
|
scaleTargetRef:
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
name: web-app
|
|
minReplicas: 2
|
|
maxReplicas: 10
|
|
metrics:
|
|
- type: Resource
|
|
resource:
|
|
name: cpu
|
|
target:
|
|
type: Utilization
|
|
averageUtilization: 70
|
|
- type: Resource
|
|
resource:
|
|
name: memory
|
|
target:
|
|
type: Utilization
|
|
averageUtilization: 80
|
|
behavior:
|
|
scaleDown:
|
|
stabilizationWindowSeconds: 300
|
|
policies:
|
|
- type: Percent
|
|
value: 50
|
|
periodSeconds: 60
|
|
scaleUp:
|
|
stabilizationWindowSeconds: 0
|
|
policies:
|
|
- type: Percent
|
|
value: 100
|
|
periodSeconds: 15</code></pre>
|
|
<h3>StatefulSets</h3>
|
|
<pre><code class="lang-yaml"># statefulset.yaml - For stateful applications
|
|
apiVersion: apps/v1
|
|
kind: StatefulSet
|
|
metadata:
|
|
name: postgres
|
|
spec:
|
|
serviceName: postgres-headless
|
|
replicas: 3
|
|
selector:
|
|
matchLabels:
|
|
app: postgres
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: postgres
|
|
spec:
|
|
containers:
|
|
- name: postgres
|
|
image: postgres:15
|
|
ports:
|
|
- containerPort: 5432
|
|
name: postgres
|
|
env:
|
|
- name: POSTGRES_PASSWORD
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: postgres-secret
|
|
key: password
|
|
volumeMounts:
|
|
- name: postgres-data
|
|
mountPath: /var/lib/postgresql/data
|
|
volumeClaimTemplates:
|
|
- metadata:
|
|
name: postgres-data
|
|
spec:
|
|
accessModes: ["ReadWriteOnce"]
|
|
storageClassName: "fast-ssd"
|
|
resources:
|
|
requests:
|
|
storage: 10Gi</code></pre>
|
|
<h3>NetworkPolicies</h3>
|
|
<pre><code class="lang-yaml"># networkpolicy.yaml - Network segmentation
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: NetworkPolicy
|
|
metadata:
|
|
name: api-network-policy
|
|
spec:
|
|
podSelector:
|
|
matchLabels:
|
|
app: api
|
|
policyTypes:
|
|
- Ingress
|
|
- Egress
|
|
ingress:
|
|
- from:
|
|
- podSelector:
|
|
matchLabels:
|
|
app: web
|
|
ports:
|
|
- protocol: TCP
|
|
port: 8080
|
|
egress:
|
|
- to:
|
|
- podSelector:
|
|
matchLabels:
|
|
app: database
|
|
ports:
|
|
- protocol: TCP
|
|
port: 5432
|
|
- to: # Allow DNS
|
|
- namespaceSelector: {}
|
|
ports:
|
|
- protocol: UDP
|
|
port: 53</code></pre>
|
|
<hr>
|
|
<h2>Quick Reference</h2>
|
|
<h3>kubectl Commands</h3>
|
|
<pre><code class="lang-bash"># Cluster info
|
|
kubectl cluster-info
|
|
kubectl get nodes
|
|
kubectl top nodes
|
|
|
|
# Pods
|
|
kubectl get pods
|
|
kubectl get pods -o wide
|
|
kubectl describe pod <pod-name>
|
|
kubectl logs <pod-name>
|
|
kubectl logs <pod-name> -f # Follow logs
|
|
kubectl logs <pod-name> -c <container-name> # Multi-container
|
|
kubectl exec -it <pod-name> -- /bin/bash
|
|
|
|
# Deployments
|
|
kubectl get deployments
|
|
kubectl describe deployment <deployment-name>
|
|
kubectl rollout status deployment/<deployment-name>
|
|
kubectl rollout history deployment/<deployment-name>
|
|
kubectl rollout undo deployment/<deployment-name>
|
|
kubectl scale deployment/<deployment-name> --replicas=5
|
|
|
|
# Services
|
|
kubectl get services
|
|
kubectl describe service <service-name>
|
|
kubectl get endpoints
|
|
|
|
# ConfigMaps and Secrets
|
|
kubectl create configmap app-config --from-file=config.json
|
|
kubectl create secret generic db-creds --from-literal=password=secret123
|
|
kubectl get configmaps
|
|
kubectl get secrets
|
|
kubectl describe configmap <name>
|
|
|
|
# Apply manifests
|
|
kubectl apply -f deployment.yaml
|
|
kubectl apply -f ./manifests/ # Directory
|
|
kubectl delete -f deployment.yaml
|
|
|
|
# Port forwarding
|
|
kubectl port-forward pod/<pod-name> 8080:80
|
|
kubectl port-forward service/<service-name> 8080:80
|
|
|
|
# Labels and selectors
|
|
kubectl get pods --selector=app=web
|
|
kubectl label pods <pod-name> environment=production
|
|
kubectl get pods --show-labels
|
|
|
|
# Contexts and namespaces
|
|
kubectl config get-contexts
|
|
kubectl config use-context <context-name>
|
|
kubectl get namespaces
|
|
kubectl create namespace dev
|
|
kubectl config set-context --current --namespace=dev
|
|
|
|
# Debug
|
|
kubectl debug <pod-name> -it --image=busybox
|
|
kubectl get events
|
|
kubectl get all -n <namespace></code></pre>
|
|
<h3>Resource Requests and Limits</h3>
|
|
<pre><code class="lang-yaml">resources:
|
|
requests:
|
|
memory: "256Mi" # Guaranteed
|
|
cpu: "500m" # 0.5 CPU cores
|
|
limits:
|
|
memory: "512Mi" # Maximum
|
|
cpu: "1000m" # 1 CPU core
|
|
|
|
# CPU units:
|
|
# 1 CPU = 1000m (millicores)
|
|
# 100m = 0.1 CPU
|
|
# 500m = 0.5 CPU
|
|
|
|
# Memory units:
|
|
# 128Mi = 128 Mebibytes
|
|
# 1Gi = 1 Gibibyte</code></pre>
|
|
<hr>
|
|
<h2>Anti-Patterns</h2>
|
|
<h3>Critical Violations</h3>
|
|
<pre><code class="lang-yaml"># ❌ NEVER: Run as root without necessity
|
|
spec:
|
|
containers:
|
|
- name: app
|
|
image: myapp:1.0
|
|
# No securityContext - runs as root
|
|
|
|
# ✅ CORRECT: Run as non-root user
|
|
spec:
|
|
securityContext:
|
|
runAsNonRoot: true
|
|
runAsUser: 1000
|
|
fsGroup: 1000
|
|
containers:
|
|
- name: app
|
|
image: myapp:1.0
|
|
securityContext:
|
|
allowPrivilegeEscalation: false
|
|
readOnlyRootFilesystem: true</code></pre>
|
|
<pre><code class="lang-yaml"># ❌ NEVER: Use 'latest' tag in production
|
|
spec:
|
|
containers:
|
|
- name: app
|
|
image: myapp:latest # Unpredictable
|
|
|
|
# ✅ CORRECT: Use specific version tags
|
|
spec:
|
|
containers:
|
|
- name: app
|
|
image: myapp:1.2.3 # Reproducible
|
|
imagePullPolicy: IfNotPresent</code></pre>
|
|
<pre><code class="lang-yaml"># ❌ NEVER: Ignore resource limits
|
|
spec:
|
|
containers:
|
|
- name: app
|
|
image: myapp:1.0
|
|
# No resources defined - can consume unlimited
|
|
|
|
# ✅ CORRECT: Always define resources
|
|
spec:
|
|
containers:
|
|
- name: app
|
|
image: myapp:1.0
|
|
resources:
|
|
requests:
|
|
memory: "256Mi"
|
|
cpu: "250m"
|
|
limits:
|
|
memory: "512Mi"
|
|
cpu: "500m"</code></pre>
|
|
<h3>Common Mistakes</h3>
|
|
<pre><code class="lang-yaml"># ❌ Don't expose secrets in environment variables unnecessarily
|
|
env:
|
|
- name: DB_PASSWORD
|
|
value: "hardcoded-password" # Visible in pod spec
|
|
|
|
# ✅ CORRECT: Use secrets and mount as files when possible
|
|
volumeMounts:
|
|
- name: db-secret
|
|
mountPath: /etc/secrets
|
|
readOnly: true
|
|
volumes:
|
|
- name: db-secret
|
|
secret:
|
|
secretName: db-credentials</code></pre>
|
|
<pre><code class="lang-yaml"># ❌ Don't skip health checks
|
|
spec:
|
|
containers:
|
|
- name: app
|
|
image: myapp:1.0
|
|
# No liveness or readiness probes
|
|
|
|
# ✅ CORRECT: Always implement health checks
|
|
spec:
|
|
containers:
|
|
- name: app
|
|
image: myapp:1.0
|
|
livenessProbe:
|
|
httpGet:
|
|
path: /healthz
|
|
port: 8080
|
|
initialDelaySeconds: 30
|
|
periodSeconds: 10
|
|
readinessProbe:
|
|
httpGet:
|
|
path: /ready
|
|
port: 8080
|
|
initialDelaySeconds: 5
|
|
periodSeconds: 5</code></pre>
|
|
<pre><code class="lang-bash"># ❌ Don't apply without reviewing
|
|
kubectl apply -f manifest.yaml # No validation
|
|
|
|
# ✅ CORRECT: Validate and review first
|
|
kubectl apply -f manifest.yaml --dry-run=client -o yaml
|
|
kubectl diff -f manifest.yaml
|
|
kubectl apply -f manifest.yaml</code></pre>
|
|
<hr>
|
|
<h2>Related Skills</h2>
|
|
<p><strong>Infrastructure</strong>:</p>
|
|
<ul><li><code>terraform-patterns.md</code> - Infrastructure as Code for Kubernetes resources</li><li><code>infrastructure-security.md</code> - RBAC, network policies, security contexts</li><li><code>cost-optimization.md</code> - Resource sizing, cluster autoscaling</li></ul>
|
|
<p><strong>Development</strong>:</p>
|
|
<ul><li><code>aws-serverless.md</code> - Alternative to container orchestration</li><li><code>cloudflare-workers.md</code> - Edge computing alternative</li></ul>
|
|
<p><strong>Standards from CLAUDE.md</strong>:</p>
|
|
<ul><li>Always define resource requests and limits</li><li>Use specific image tags (not 'latest')</li><li>Implement liveness and readiness probes</li><li>Run containers as non-root users</li><li>Use namespaces for multi-tenancy</li><li>Apply network policies for security</li></ul>
|
|
<hr>
|
|
<p><strong>Last Updated</strong>: 2025-10-18 <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="/infrastructure-kubernetes-basics.md">This page as plain text</a> · <a href="/llms.txt">Index for agents</a></div>
|
|
</footer>
|
|
</div></body></html> |