(01)Build image and load into cluster
Linux
1# Build local image2docker build -t api:local .3 4# For Minikube / Kind — load image into cluster5minikube image load api:local6# OR: kind load docker-image api:localDeploy a local Docker image to Kubernetes with resource limits and NodePort access
deployment.yml
Deployment with resource requests/limits and local image
1apiVersion: apps/v12kind: Deployment3metadata:4 labels:5 app: api-deploy6 name: api-deploy7spec:8 replicas: 19 selector:10 matchLabels:11 app: api-deploy12 template:13 metadata:14 labels:15 app: api-deploy16 spec:17 containers:18 - image: api:local19 name: api20 imagePullPolicy: IfNotPresent21 ports:22 - containerPort: 300023 resources:24 limits:25 memory: "512Mi"26 cpu: "500m"27 requests:28 memory: "256Mi"29 cpu: "250m"services.yml
NodePort Service exposing the API on port 32000
1apiVersion: v12kind: Service3metadata:4 labels:5 app: api-deploy6 name: api-deploy-service7spec:8 type: NodePort9 selector:10 app: api-deploy11 ports:12 - port: 300013 protocol: TCP14 targetPort: 300015 nodePort: 32000What to add before production merge
| Aspect | Minimal | Production |
|---|---|---|
| Replicas | replicas: 1 | replicas: 3+ with PodDisruptionBudget |
| Probes | none | readinessProbe + livenessProbe on /health |
| Resources | no limits | requests/limits for CPU and memory |
| Security | default SA | runAsNonRoot, readOnlyRootFilesystem, drop capabilities |
| Image | :latest | pinned digest or semver tag from CI |
| Secrets | env in Deployment YAML | Secret + external-secrets or SealedSecrets |
Step 01
1# Build local image2docker build -t api:local .3 4# For Minikube / Kind — load image into cluster5minikube image load api:local6# OR: kind load docker-image api:local1kubectl apply -f deployment.yml2kubectl apply -f services.yml3kubectl get pods,svc4curl http://localhost:32000 # or minikube service api-deploy-service