Homelab P5

 Since we're just talking, here's my take — no file edits, just the game plan for you to execute.


1. Redis/MySQL: keep on host via Docker, don't move into k3s

Your plan doc already commits to this and I think it's right. Two reasons:


It genuinely mirrors reality — nobody runs their own RDS/ElastiCache inside their app cluster; you consume it as an external managed endpoint. Practicing "reach an external stateful service from k8s" is a more valuable, more common skill than "run MySQL in a StatefulSet" (that's explicitly P5.5's job instead, as a deliberately separate, non-blocking exercise).

It sidesteps PV/StorageClass complexity this early, which would otherwise dominate the P5 lesson instead of the actual target: namespaces, no-selector Services, and Service/Endpoint mechanics.

Mechanics: create a Service with no selector in toy-infra, plus a matching Endpoints/EndpointSlice object pointing at the host's real routable IP (not 127.0.0.1 — a pod's netns can't see that). Business pods then just talk to mysql.toy-infra.svc.cluster.local:3306 like it's any other in-cluster service — the "managed DB" illusion is transparent from the app's point of view, which is the whole point.


I checked your current infra/docker-compose.dev.yml — MySQL/Redis already bind 0.0.0.0, so this should just work. Sanity-check reachability with a throwaway pod (kubectl run tmp --rm -it --image=busybox -- sh, then nc -zv <host-ip> 3306) before wiring the real Service — much faster feedback than debugging through a full app.


One landmine you haven't hit yet: Kafka. Unlike MySQL/Redis (dumb TCP), Kafka's protocol has brokers tell clients "here's my advertised address, reconnect there" as part of the handshake. Your compose file currently advertises PLAINTEXT_HOST://localhost:9092 — that's fine for host-run services, but a pod that connects to the no-selector Service will get the initial connection through, then Kafka will hand back localhost:9092 as the address to actually produce/consume on, and inside a pod that resolves to the pod itself. Classic confusing half-working failure. Fix: change that advertised listener from localhost to the host's real IP — works for both host processes and k3s pods uniformly. ES doesn't have this problem (plain HTTP, no address-handback), so it's Kafka-specific.


2. Env vars: ConfigMap + Secret, imperative for now

Your services already default cleanly (${SPRING_DATASOURCE_URL:...} pattern everywhere) — that design already sets you up well for k8s. Natural split:


Non-secret stuff (URLs, ports, feature toggles) → ConfigMap, injected via envFrom

Passwords/JWT secret → Secret, created imperatively (kubectl create secret generic ...) since P5 explicitly stays pre-CI/CD — no need to reach for sealed-secrets/external-secrets yet, that's a GitOps-phase concern.

One thing to note: ConfigMap changes don't auto-propagate to running pods (no restart = stale env vars) unless you roll manually or use something like Reloader. That's fine to just know and manually restart when you tweak config, don't over-engineer it now.


3. Nacos — good idea, but don't fold it into P5

k8s already gives you service discovery (Service + CoreDNS) and static config (ConfigMap). What Nacos actually adds on top is dynamic config push without redeploy (change a value, app picks it up via long-poll) and, if you want it, a Spring-Cloud-style registry layered over k8s's own. That's a distinct, well-scoped lesson — mixing it into P5 would blur "bare k8s YAML mechanics" with "config-center client integration" and you'd learn both less cleanly. I'd insert it as its own phase later (something like P5.6 or post-P6, once monitoring exists so you can actually watch a config hot-reload take effect) — matches the .5-insertion pattern you've already been using for practice detours.


Things you probably haven't hit yet

No Dockerfiles exist yet for any of the 5 services (checked — only an nginx-ingress demo manifest exists under infra/k8s/). Writing those, and figuring out how images get into k3s's containerd (no registry currently configured) is real work before any Deployment YAML matters. For homelab scale, either docker save | sudo k3s ctr images import - per build, or stand up a tiny local registry:2 container — the latter is more annoying now but pays off once you're iterating fast.

Pin image tags (not latest) even without CI/CD — imagePullPolicy: IfNotPresent + latest is a classic "why is it still running the old code" trap.

Wire your existing /actuator/health endpoints into readinessProbe/livenessProbe — you already built these, free win.

Cross-namespace DNS: toy-system pods reaching toy-infra Services need the full <svc>.<ns>.svc.cluster.local form, not the short name.

Check host firewall (ufw/firewalld) isn't blocking the k3s pod CIDR from reaching your host-bound MySQL/Redis/Kafka ports — easy to forget, only shows up as pods timing out.

Loosely set resource requests/limits even if the numbers are guesses — worth the muscle memory since P6 (Prometheus/Grafana) will make the consequences of not setting them visible.

That covers your three questions plus the gaps I'd flag. Shout if you want me to go deeper on any one piece (e.g. the exact no-selector Service/Endpoints shape, or the Kafka listener fix) once you're actually in it.

コメント

このブログの人気の投稿

大题材 大全 脑暴

FP3 シミュレーション

日本保险知识体系地图