Linking StatefulSet to a service

First, let's remove our existing elasticsearch Deployment Object:

$ kubectl delete deployment elasticsearch

Now, the final step is to create our StatefulSet, which provides each Pod with a unique identity, and link it to the Service, which gives each Pod a subdomain. We do this by specifying the name of the Service as the spec.serviceName property in our StatefulSet manifest file:

...spec:  replicas: 3  serviceName: elasticsearch  ...

Now, the Service linked to the StatefulSet will get a domain with the following structure:

<service-name>.<namespace>.svc.<cluster-domain>

Our Service's name is elasticsearch. By default, Kubernetes will use the default namespace, and cluster.local as the Cluster Domain. Therefore, ...

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.