StatefulSet without service and rollback support yaml

7/20/2020

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:

enter image description here

-- Jayashree Madanala
kubernetes
kubernetes-pod
kubernetes-statefulset

3 Answers

7/20/2020

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.

-- Ken Chen
Source: StackOverflow

7/20/2020

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.

-- Arghya Sadhu
Source: StackOverflow

7/20/2020

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.

✌️

-- Rico
Source: StackOverflow