k8s-client-js
暂无简介
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 13
- Forks
- 2
03 SKILL.md 正文
/k8s-client-js
When to Use
- Agent spawns, monitors, and terminates child agent Pods programmatically
- Scale a Deployment based on task queue depth
- Stream logs from a running agent pod back to the orchestrator
- Exec a command inside a container for health checks or remediation
Do NOT use for
- Infrastructure-as-code (use [[helm-chart-packaging]] or [[argocd-gitops]])
- High-frequency operations (K8s API has rate limits ~100 req/s)
Setup and authentication
import * as k8s from '@kubernetes/client-node'
const kc = new k8s.KubeConfig()
// Auto-detect: in-cluster (ServiceAccount) or ~/.kube/config
kc.loadFromDefault()
const coreApi = kc.makeApiClient(k8s.CoreV1Api)
const appsApi = kc.makeApiClient(k8s.AppsV1Api)
const batchApi = kc.makeApiClient(k8s.BatchV1Api)
Spawn an agent Pod
async function spawnAgentPod(agentId: string, tier: string): Promise<string> {
const pod = await coreApi.createNamespacedPod('yamtam', {
metadata: {
name: `agent-${agentId}`,
labels: { app: 'yamtam-agent', tier, agentId },
},
spec: {
restartPolicy: 'Never',
containers: [{
name: 'agent',
image: `ghcr.io/yamtam/agent:latest`,
env: [
{ name: 'YAMTAM_AGENT_ID', value: agentId },
{ name: 'YAMTAM_AGENT_TIER', value: tier },
],
resources: {
requests: { memory: '256Mi', cpu: '100m' },
limits: { memory: '512Mi', cpu: '500m' },
},
securityContext: {
readOnlyRootFilesystem: true,
allowPrivilegeEscalation: false,
runAsNonRoot: true,
},
}],
},
})
return pod.body.metadata!.name!
}
Scale a Deployment
async function scaleDeployment(name: string, namespace: string, replicas: number) {
await appsApi.patchNamespacedDeploymentScale(name, namespace,
[{ op: 'replace', path: '/spec/replicas', value: replicas }],
undefined, undefined, undefined, undefined, undefined,
{ headers: { 'Content-Type': 'application/json-patch+json' } }
)
console.log(`[k8s] scaled ${name} → ${replicas} replicas`)
}
Stream pod logs
async function streamPodLogs(podName: string, namespace = 'yamtam') {
const logStream = await new k8s.Log(kc).log(
namespace,
podName,
undefined, // container name (undefined = first)
process.stdout,
{
follow: true,
tailLines: 100,
timestamps: true,
}
)
return logStream // call logStream.destroy() to stop
}
Wait for Pod to be Running
async function waitForPod(podName: string, namespace = 'yamtam', timeoutMs = 60_000) {
const start = Date.now()
while (Date.now() - start < timeoutMs) {
const pod = await coreApi.readNamespacedPod(podName, namespace)
const phase = pod.body.status?.phase
if (phase === 'Running') return true
if (phase === 'Failed') throw new Error(`[k8s] pod ${podName} failed`)
if (phase === 'Succeeded') return true
await new Promise(r => setTimeout(r, 2000))
}
throw new Error(`[k8s] pod ${podName} not ready after ${timeoutMs}ms`)
}
Anti-Fake-Pass Checklist
❌ loadFromDefault() outside cluster without KUBECONFIG set → uses ~/.kube/config, may hit wrong cluster
❌ No resource limits on spawned pods → runaway agent exhausts node memory
❌ readOnlyRootFilesystem without emptyDir volume → agent can't write temp files
❌ Watching pods without timeout → watch connection drops after ~1h; reconnect required
❌ JSON patch without Content-Type: application/json-patch+json → K8s rejects with 415
❌ Deleting pod without waiting → successor pod starts with stale ConfigMap if not flushed
04 同仓库更多 Skills
openai--sentry--sentry
Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.
ito-basket-compare
Compare Itô prediction-market baskets against a user's knowledge base, portfolio notes, financial context, watchlist, or research thesis. Use for read-only basket comparison and gap analysis without investment advice or live trading.
implementing-network-traffic-baselining
Build network traffic baselines from NetFlow/IPFIX data using Python pandas for statistical analysis, z-score anomaly detection, and hourly/daily traffic pattern profiling
detecting-evasion-techniques-in-endpoint-logs
Detects defense evasion techniques used by adversaries in endpoint logs including log tampering, timestomping, process injection, and security tool disabling. Use when investigating suspicious endpoint behavior, building detection rules for evasion tactics, or conducting threat hunting for stealthy adversary activity. Activates for requests involving evasion detection, defense evasion analysis, log tampering detection, or MITRE ATT&CK TA0005.
implementing-microsegmentation-with-guardicore
Implementing microsegmentation using Akamai Guardicore Segmentation to map application dependencies, create granular network policies, visualize east-west traffic flows, and enforce least-privilege communication between workloads across data centers and cloud.
ramdisk-tmpfs-patterns
暂无简介