Create a cache that refuses to share a node with itself:
sh
kubectl apply -n peaks-l33cts -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: market-cache
spec:
replicas: 3
selector:
matchLabels:
app: market-cache
template:
metadata:
labels:
app: market-cache
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: market-cache
topologyKey: kubernetes.io/hostname
containers:
- name: redis
image: redis:7.2
EOF
kubectl get pods -n peaks-l33cts -o wideScale it to 4 and read why the newcomer waits. Scale back to 3. Then place two web Pods next to the cache:
sh
kubectl apply -n peaks-l33cts -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: market-web
spec:
replicas: 2
selector:
matchLabels:
app: market-web
template:
metadata:
labels:
app: market-web
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: market-cache
topologyKey: kubernetes.io/hostname
containers:
- name: web
image: nginx:1.27
EOF