Skip to content

Commit 3c2ea8b

Browse files
committed
clarify hostname vs podname, fix examples
Signed-off-by: Rohan Varma <[email protected]>
1 parent 6d7dc1b commit 3c2ea8b

File tree

3 files changed

+80
-18
lines changed

3 files changed

+80
-18
lines changed

docs/user-guide/environment-variables.md

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,56 @@ Grove automatically injects environment variables into every container and init
2020
- **Coordination**: Understanding your role in a distributed system
2121
- **Configuration**: Self-configuring based on your position in the hierarchy
2222

23-
**Key insight:** Pod discovery in Grove is **index-based**, not name-based. While Kubernetes assigns each pod a name with a random suffix (e.g., `my-service-0-frontend-abc12`), you never need to know these suffixes for service discovery. Instead, Grove's environment variables let you construct deterministic addresses using the PodClique name and pod index (e.g., `my-service-0-frontend-0.<headless-service>`).
23+
However, before we get to the environment variables it is important to first make a distinction between a Pod's Name and its Hostname.
24+
25+
## Understanding Pod Names vs. Hostnames in Kubernetes
26+
27+
A common source of confusion is the difference between a pod's **name** and its **hostname**. Understanding this distinction is essential for using Grove's environment variables correctly.
28+
29+
### Pod Name (Kubernetes Resource Identifier)
30+
31+
The **pod name** is the unique identifier for the Pod resource in Kubernetes (stored in `metadata.name`). When Grove creates pods, it uses Kubernetes' `generateName` feature, which appends a random 5-character suffix to ensure uniqueness:
32+
33+
```
34+
<pclq-name>-<random-suffix>
35+
Example: env-demo-standalone-0-frontend-abc12
36+
```
37+
38+
This name is what you see when running `kubectl get pods`. However, you **cannot use this name for DNS-based service discovery** because the random suffix is unpredictable.
39+
40+
### Hostname (DNS-Resolvable Identity)
41+
42+
The **hostname** is a separate field (`spec.hostname`) that Grove explicitly sets on each pod. Unlike the pod name, the hostname follows a **deterministic pattern**:
43+
44+
```
45+
<pclq-name>-<pod-index>
46+
Example: env-demo-standalone-0-frontend-0
47+
```
48+
49+
Grove also sets the pod's **subdomain** (`spec.subdomain`) to match the headless service name. Grove automatically creates a headless service for each PodCliqueSet replica, so you don't need to create one yourself. In Kubernetes, when a pod has both `hostname` and `subdomain` set, and a matching headless service exists, the pod becomes DNS-resolvable at:
50+
51+
```
52+
<hostname>.<subdomain>.<namespace>.svc.cluster.local
53+
```
54+
55+
For example:
56+
```
57+
env-demo-standalone-0-frontend-0.env-demo-standalone-0.default.svc.cluster.local
58+
```
59+
60+
### Why This Matters
61+
62+
| Attribute | Pod Name | Hostname |
63+
|-----------|----------|----------|
64+
| Source | `metadata.name` | `spec.hostname` |
65+
| Pattern | `<pclq-name>-<random-suffix>` | `<pclq-name>-<pod-index>` |
66+
| Predictable? | ❌ No (random suffix) | ✅ Yes (index-based) |
67+
| DNS resolvable? | ❌ No | ✅ Yes (with headless service) |
68+
| Use case | `kubectl` commands, logs | Service discovery, pod-to-pod communication |
69+
70+
**The environment variables Grove provides (`GROVE_PCLQ_NAME`, `GROVE_PCLQ_POD_INDEX`, `GROVE_HEADLESS_SERVICE`) give you the building blocks to construct the hostname-based FQDN, not the pod name.** This is why pod discovery in Grove is deterministic and doesn't require knowledge of random suffixes.
71+
72+
With this explained we can now get into the environment variables Grove provides.
2473

2574
## Environment Variables Reference
2675

@@ -91,12 +140,19 @@ spec:
91140
echo "GROVE_HEADLESS_SERVICE=$GROVE_HEADLESS_SERVICE"
92141
echo "GROVE_PCLQ_POD_INDEX=$GROVE_PCLQ_POD_INDEX"
93142
echo ""
94-
echo "=== Pod Information ==="
95-
echo "Pod Name: $(hostname)"
96-
echo "PCS Replica: $GROVE_PCS_NAME-$GROVE_PCS_INDEX"
143+
echo "=== Pod Name vs Hostname ==="
144+
echo "Pod Name (random suffix): $POD_NAME"
145+
echo "Hostname (deterministic): $(hostname)"
146+
echo ""
147+
echo "My FQDN: $GROVE_PCLQ_NAME-$GROVE_PCLQ_POD_INDEX.$GROVE_HEADLESS_SERVICE"
97148
echo ""
98149
echo "Sleeping..."
99150
sleep infinity
151+
env:
152+
- name: POD_NAME
153+
valueFrom:
154+
fieldRef:
155+
fieldPath: metadata.name
100156
resources:
101157
requests:
102158
cpu: "10m"
@@ -145,18 +201,21 @@ GROVE_PCLQ_NAME=env-demo-standalone-0-frontend
145201
GROVE_HEADLESS_SERVICE=env-demo-standalone-0.default.svc.cluster.local
146202
GROVE_PCLQ_POD_INDEX=0
147203
148-
=== Pod Information ===
149-
Pod Name: env-demo-standalone-0-frontend-abc12
150-
Pod Namespace: env-demo-standalone-0
204+
=== Pod Name vs Hostname ===
205+
Pod Name (random suffix): env-demo-standalone-0-frontend-abc12
206+
Hostname (deterministic): env-demo-standalone-0-frontend-0
207+
208+
My FQDN: env-demo-standalone-0-frontend-0.env-demo-standalone-0.default.svc.cluster.local
151209
152210
Sleeping...
153211
```
154212

155213
**Key Observations:**
156-
- The pod name (`env-demo-standalone-0-frontend-abc12`) follows the pattern `<pcs-name>-<pcs-index>-<pclq-name>-<suffix>`
214+
- The **pod name** (`env-demo-standalone-0-frontend-abc12`) has a random suffix—this is the Kubernetes resource identifier, not used for DNS
215+
- The **hostname** (constructed as `$GROVE_PCLQ_NAME-$GROVE_PCLQ_POD_INDEX`) is deterministic—this is what you use for service discovery
157216
- `GROVE_PCLQ_NAME` contains the fully qualified PodClique name without the random suffix
158217
- `GROVE_PCLQ_POD_INDEX` tells us this is the first pod (index 0) in the PodClique
159-
- `GROVE_HEADLESS_SERVICE` provides the FQDN for the headless service serving all pods in this PodCliqueSet replica
218+
- `GROVE_HEADLESS_SERVICE` provides the FQDN for the headless service, so the full DNS address is: `$GROVE_PCLQ_NAME-$GROVE_PCLQ_POD_INDEX.$GROVE_HEADLESS_SERVICE`
160219

161220
### Cleanup
162221

@@ -447,8 +506,4 @@ nslookup $GROVE_HEADLESS_SERVICE
447506
For pods in a PodCliqueScalingGroup, Grove exposes additional variables that identify the PCSG replica and its composition. This allows components to understand which *logical unit (super-pod)* they belong to and how many peers are expected.
448507

449508
5. **Designed for Distributed Systems**
450-
Grove’s environment variables are intentionally low-level and composable. They are meant to support a wide range of distributed system patterns—leader election, sharding, rendezvous, collective communication—without imposing a fixed discovery or coordination model.
451-
452-
453-
454-
509+
Grove’s environment variables are intentionally low-level and composable. They are meant to support a wide range of distributed system patterns—leader election, sharding, rendezvous, collective communication—without imposing a fixed discovery or coordination model.

docs/user-guide/pod-naming.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Pod Naming Scheme
22

3-
This guide explains Grove's hierarchical pod naming scheme and best practices for naming your resources. **Grove's naming convention is designed to be self-documenting**: when you run `kubectl get pods`, the pod names immediately tell you which PodCliqueSet, PodClique, and (if applicable) PodCliqueScalingGroup each pod belongs to, reflecting the complete hierarchy of your system.
3+
This guide explains Grove's hierarchical pod naming scheme and best practices for naming your resources. **Grove's naming convention is designed to be self-documenting**: when you run `kubectl get pods`, the pod names immediately tell you which PodCliqueSet, PodCliqueScalingGroup (if applicable), and PodClique each pod belongs to, reflecting the complete hierarchy of your system.
44

55
## Why Hierarchical Naming Matters
66

operator/samples/user-guide/naming-and-env-vars/standalone-env-vars.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ spec:
3232
echo "GROVE_HEADLESS_SERVICE=$GROVE_HEADLESS_SERVICE"
3333
echo "GROVE_PCLQ_POD_INDEX=$GROVE_PCLQ_POD_INDEX"
3434
echo ""
35-
echo "=== Pod Information ==="
36-
echo "Pod Name: $(hostname)"
37-
echo "Pod Namespace: $GROVE_PCS_NAME-$GROVE_PCS_INDEX"
35+
echo "=== Pod Name vs Hostname ==="
36+
echo "Pod Name (random suffix): $POD_NAME"
37+
echo "Hostname (deterministic): $(hostname)"
38+
echo ""
39+
echo "My FQDN: $GROVE_PCLQ_NAME-$GROVE_PCLQ_POD_INDEX.$GROVE_HEADLESS_SERVICE"
3840
echo ""
3941
echo "Sleeping..."
4042
sleep infinity
43+
env:
44+
- name: POD_NAME
45+
valueFrom:
46+
fieldRef:
47+
fieldPath: metadata.name
4148
resources:
4249
requests:
4350
cpu: "10m"

0 commit comments

Comments
 (0)