kubernetes
Use when deploying services to Kubernetes — starting with a local cluster (kind or k3d), writing Deployments, Services, ConfigMaps and probes, resource requests and limits, rolling updates, debugging
SKILL.mdskills/tech/kubernetes/SKILL.md
GitHubKubernetes
Default: learn and test on a local cluster (kind or k3d) first, plain YAML manifests (add Kustomize for environments), one namespace per app, probes and resource requests on every container, a managed cluster only after estimating its monthly cost.
Local cluster
kind create cluster --name dev
docker build -t app:dev . && kind load docker-image app:dev --name dev
kubectl apply -k k8s/overlays/dev
kubectl -n app get pods -w
kind load puts a local image into the cluster; without it, imagePullPolicy and a non-existent registry cause ErrImagePull.
Minimal manifest set
- Deployment with
replicas, labels that match the Service selector,readinessProbeandlivenessProbe(different endpoints or thresholds),resources.requestsandlimits. - Service (
ClusterIP) selecting the pods; an Ingress orkubectl port-forwardto reach it. - ConfigMap for settings, Secret for credentials (created from the environment, not committed).
- Run as non-root (
securityContext.runAsNonRoot: true) with a read-only root filesystem where possible.
Rolling updates
- Change the image tag (immutable tags, not
latest) andkubectl apply; watchkubectl rollout status deploy/app. - Readiness gates traffic; a missing readiness probe sends requests to pods that are still starting.
kubectl rollout undofor a quick rollback.
Debugging order
kubectl get pods→ status (Pending,CrashLoopBackOff,ImagePullBackOff).kubectl describe pod→ events (scheduling, image pulls, probe failures, OOMKilled).kubectl logs pod [-p]→ application output (-pfor the previous crashed container).kubectl get endpoints svc→ empty means the selector does not match pod labels or pods are not ready.kubectl exec -it pod -- shto test DNS and connectivity from inside.
Managed clusters
- Estimate before creating: control-plane fee (varies by provider), nodes, load balancers, storage and egress. A small always-on cluster costs real money every month even when idle.
- Create budgets and alerts first; tear down test clusters the same day; keep the cluster definition in Terraform so it can be recreated.
Verification loop
kubectl apply --dry-run=server -k ...validates against the API.- Pods become Ready;
rollout statussucceeds. - A smoke request through the Service or Ingress returns the expected response.
- Delete and re-apply from scratch to prove the manifests are complete.
Pitfalls
- Limits without requests set requests equal to limits; too-low memory limits cause OOMKilled loops.
- Liveness probes that are too aggressive restart healthy but slow pods; give a startup probe to slow starters.
- Selectors are immutable on Deployments; changing labels later means recreating the Deployment.
latesttags make rollouts and rollbacks unpredictable.- Local-only assumptions (host paths,
kind load) do not exist in cloud clusters; push images to a registry the cluster can pull from.