Are Kubernetes StatefulSets Ready For Production?

What Are StatefulSets

As mentioned in the opening paragraph of this blog post, a stateful application is a process that can be returned again and again. An example of that is email. Every time you’re logging into email, you’re the “process” of the stateful application that’s returning again and again. If your email account wasn’t stateful, that means all of your emails and everything else (signatures, drafts, etc.) would be gone.

  • Unique network identifiers that stick with Pods as they come up and go down
  • Persistent storage
  • Scaling gracefully. New replicas won’t come up until the previous replica is up and running
  • Rolling updates

StatefulSet vs Stateless

There are, more or less, two types of applications:

  • Stateful apps
  • Stateless apps

Example StatefulSet Breakdown (Deployment Spec vs StatefulSet Spec)

Now that you know what stateless and stateful are, let’s take a look at a few examples via Kubernetes manifests.

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
  • The kind is now StatefulSet
  • There are volumes
  • Mount paths exist to store the data

Deployment Spec vs StatefulSet Spec

Deployment specs and StatefulSet specs are quite similar. They both have self-healing, scalability features, and replica counts. The key difference between the two is a StatefulSet spec maintains a sticky identity for each Pod. Remember in the previous section when you learned that with StatefulSets, the Pods keep the network IDs and they’re unique? This is what was being referred to.

StatefulSets For Production?

To answer this question, there are two ways you have to think about it:

  • From a technical perspective
  • From a user perspective

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Michael Levan

Michael Levan

Leader in Kubernetes consulting, research, and content creation ┇AWS Community Builder (Dev Tools Category)┇ HashiCorp Ambassador