But what should the value of this environment variable be? Currently, the IP addresses of the Elasticsearch Pods is random (within a large range) and may change at any time.
To resolve this issue, we need to give each Pod a unique hostname that sticks to the Pod, even if it gets rescheduled.
When you visit a website, you usually won't type the site's IP address directly onto the browser; instead, you'd use the website's domain name. Even if the host of the website changes to a different IP address, the website will still be reachable on the same domain name. This is similar to what happens when we attach a hostname to a Pod.
To achieve this, we need to do two things:
- Provide each Pod with an identity using another Kubernetes Object called StatefulSet.
- Attach a DNS subdomain to each Pod using a Headless Service, where the value of the subdomain is based on the Pod's identity.