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:
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.
spec.serviceName
in statefulset is required as per the API. Hence you have to have it.
kubectl explain statefulset.spec.serviceName
KIND: StatefulSet
VERSION: apps/v1
FIELD: serviceName <string>
DESCRIPTION:
serviceName is the name of the service that governs this StatefulSet. This
service must exist before the StatefulSet, and is responsible for the
network identity of the set. Pods get DNS/hostnames that follow the
pattern: pod-specific-string.serviceName.default.svc.cluster.local where
"pod-specific-string" is managed by the StatefulSet controller.
As you can see above This service must exist before the StatefulSet.
Actually, that's one of the StatefulSet's limitations, it's mandatory to have a headless service. ✅
StatefulSets currently require a Headless Service to be responsible for the network identity of the Pods. You are responsible for creating this 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.
✌️