Stateful k8s

Recently, i ran into an error with my k8 yaml file. I was defining a Stateful workload for a redis cluster and when I ran the create cluster command, I got the error below.

Results in error:
error: error validating "redis-def.yaml": error validating data: [ValidationError(StatefulSet.spec): missing required field "selector" in io.k8s.api.apps.v1.StatefulSetSpec, ValidationError(StatefulSet.spec): missing required field "serviceName" in io.k8s.api.apps.v1.StatefulSetSpec]; if you choose to ignore these errors, turn validation off with --validate=false

Looking closely at the K8 documentation, I missed the required “Selector” attribute.

kind: StatefulSet
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: redis # has to match .spec.template.metadata.labels

The snippet above was taken from the Kubernetes documentation and it shows the “Selector” attribute with the “matchLabels” and “App” attributes.

I added those attributes to my redis-def.yaml file and problem solved.

Reference

https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/