I need to deploy pod with Persistent volume claim support and at the same time, I also need support for modification of pod(edit any configuration) and also rollback to the previous version of the previous container image version.
I went through docs, but everywhere they included service in statefulset.yaml file.
I don’t want service here, it should just deploy statefulset pod with rollback support.
Can you help me giving any sample statefulset YAML file
apiVersion: v1
kind: Service
metadata:
name: redis
namespace: default
......................
.................
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
spec:
3
Answers
Service is needed only when you want to expose your application. Without a service, you can only access your statefulSet via IP within the cluster. You can find more details in official docs.
Your requirements of PVC, editing, and rollback are builtin features of statefulset(you can only edit a few fields of a statefulset tho), so you are good to go.
Actually, that’s one of the StatefulSet’s limitations, it’s mandatory to have a headless service. ✅
Also, if you’d like other pods to access your Redis instance from other pods in your Kubernetes cluster or from somewhere outside the cluster it is a must-have.
If you don’t want to use services you can switch 🔀 your StatefulSet to a regular Deployment.
✌️
spec.serviceName
in statefulset is required as per the API. Hence you have to have it.As you can see above This service must exist before the StatefulSet.