k8s newbie here.
StatefulSets allow creating pods with a) predefined names and b) an order. In my case, I don't need an order (b), and this is giving me trouble. (a) is useful in my case because I need to keep the state if a container dies.
Example, I have [ pod-0, pod-1, pod-2 ], and just want pod-0 to die, but this is what happens:
This is expected:
1. [ pod-0:Running, pod-1:Running, pod-2:Running ]
2. My app needs to scale to 2 replicas by killing pod-0, so "k delete pod/pod-0" and "Replicas: 2"
3. [ pod-0:terminating, pod-1:Running, pod-2:Running ]
I want to keep this state!
4. [ pod-1:Running, pod-2:Running ]
This, I don't want!!!, but can't prevent K8s from doing:
5. [ pod-0:Starting, pod-1:Running, pod-2:Running ] (K8s shifts the pipe!!!)
6. [ pod-0:Running, pod-1:Running, pod-2:Terminating ] (K8s shifts the pipe!!!)
7. [ pod-0:Running, pod-1:Running ] (K8s shifts the pipe!!!)
How can I achieve the desired behavior with K8s (keep a set of non-sequential named pods)?
I've seen a promising "AdvancedStatefulSet"(1) by Openkruise.ui, which would allow this, but the product is not yet mature for production. At least, it does not work on minikube (minikube 1.16.0, docker 19.03.13, OpenKruise 0.7.0).
Someone asked for my deployment file, here it goes:
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: contextcf
labels:
name: contextcf
spec:
serviceName: contextcf
selector:
matchLabels:
name: contextcf
replicas: 3
template:
metadata:
labels:
name: contextcf
spec:
containers:
- name: contextcf
image: (my-registry)/contextcf:1.0.0
ports:
- name: web
containerPort: 80
# Volume sections removed, no issues there. The application is a simple as this.