yaml
28 lines · 1 tab
Kai Nakamura
Apr 2026
1 tab
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: api-ingress
namespace: production
spec:
podSelector:
matchLabels:
app: api
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: ingress-nginx
ports:
- protocol: TCP
port: 3000
egress:
- to:
- podSelector:
matchLabels:
app: postgres
ports:
- protocol: TCP
port: 5432
1 file · yaml
Explain with highlit
Cluster flat networking is convenient right up until an attacker lands in one pod. I define NetworkPolicy resources early so east-west communication is explicit, reviewable, and least-privilege by default. This makes later incident containment far more realistic.
Related snips
ruby
require "timeout"
module HealthCheck
class Probe
Result = Struct.new(:name, :status, :latency_ms, :critical, :error, keyword_init: true) do
def healthy?
Health Check Endpoint with Dependency Probes
rails
reliability
health-check
by codesnips
3 tabs
javascript
// Express app with health checks and graceful shutdown
const express = require('express');
const { createServer } = require('http');
const app = express();
const server = createServer(app);
Container health checks and graceful shutdown patterns
docker
kubernetes
health-checks
by Ryan Nakamura
1 tab
yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: metrics-reader
namespace: production
---
Kubernetes RBAC roles with least privilege service accounts
kubernetes
rbac
least-privilege
by Kai Nakamura
1 tab
yaml
# Headless Service for stable DNS
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: production
Kubernetes StatefulSets for stateful workloads
kubernetes
k8s
statefulsets
by Ryan Nakamura
1 tab
yaml
# === One-off Job: Database migration ===
apiVersion: batch/v1
kind: Job
metadata:
name: db-migrate
namespace: production
Kubernetes Jobs and CronJobs for batch workloads
kubernetes
cronjob
batch
by Ryan Nakamura
1 tab
yaml
# ClusterIP Service (internal only)
apiVersion: v1
kind: Service
metadata:
name: web-app
namespace: production
Kubernetes Services and Ingress for traffic routing
kubernetes
k8s
services
by Ryan Nakamura
2 tabs
Share this code
Here's the card — post it anywhere.