dragonflydb / dragonflydb/dragonfly
Helm chart: cannot expose Memcached port (11211) correctly via Service; `service.port=11211` still routes to Redis port (6379) because Service `targetPort` is fixed
- Dominant language
- C++
- Stars
- 31.5k
- Forks
- 1.3k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 127
Description
**Describe the bug**
When deploying Dragonfly via the official OCI Helm chart and enabling Memcached mode (`--memcached_port=11211`), setting `service.port: 11211` does **not** expose the Memcached protocol on the Service. The Service still routes traffic to the Redis listener (6379) because the chart’s Service `targetPort` is fixed to the named port `dragonfly` (which maps to containerPort 6379).
This makes “drop-in memcached replacement on Kubernetes” non-trivial: users have to create an additional Service (e.g. via `extraObjects`) that explicitly targets port 11211.
**To Reproduce**
1. Install the chart `oci://ghcr.io/dragonflydb/dragonfly/helm/dragonfly` (example version `v1.34.2`) with values like:
```yaml
extraArgs:
- --memcached_port=11211
service:
port: 11211
```
2. Observe Service and endpoints:
```bash
kubectl -n get svc -o yaml
kubectl -n get endpoints -o wide
```
3. You’ll see that even if the Service port is 11211, the endpoints point to `:6379` (Redis).
4. Optional protocol proof (port-forwarding the Service to localhost):
```bash
kubectl -n port-forward svc/ 11211:11211
printf '*1\r\n$4\r\nPING\r\n' | nc -w 2 127.0.0.1 11211
```
Output is `+PONG` (Redis), i.e. the Service is routing to 6379, not to Memcached.
**Expected behavior**
If `--memcached_port=11211` is configured and I set `service.port: 11211`, the Service should route to the Memcached listener (pod port 11211), so memcached clients can use `:11211` normally.
**Actual behavior**
The Service exposes port 11211 but routes to pod port 6379 because `targetPort` remains the fixed named port `dragonfly` (containerPort 6379). Memcached text protocol via the Service does not work as expected because traffic hits the Redis listener.
**Reproducible Code Snippet**
```yaml
# values.yaml
extraArgs:
- --memcached_port=11211
service:
port: 11211
```
**Additional context**
- Root cause: Kubernetes Services route based on `targetPort` (can be a number or a named port). The chart’s Service template uses a fixed `targetPort: dragonfly`, and the pod defines only the named port `dragonfly: 6379`, so changing `service.port` alone can’t route to 11211. Kubernetes Service docs: `https://kubernetes.io/docs/concepts/services-networking/service/`
- Chart values expose `service.port`, but there is no `service.targetPort` option; however the chart supports `extraObjects` for adding manifests. Chart values/README (showing `extraObjects`):
- `https://raw.githubusercontent.com/dragonflydb/dragonfly/main/contrib/charts/dragonfly/values.yaml`
- `https://raw.githubusercontent.com/dragonflydb/dragonfly/main/contrib/charts/dragonfly/README.md`
- Workaround we used: keep the chart Service on 6379, and create a separate Service for Memcached via `extraObjects`:
```yaml
service:
port: 6379
extraObjects:
- apiVersion: v1
kind: Service
metadata:
name: memcached
spec:
type: ClusterIP
selector:
app.kubernetes.io/instance:
app.kubernetes.io/name: dragonfly
ports:
- name: memcached
port: 11211
targetPort: 11211
protocol: TCP
```
- Proposed fix (chart UX improvement):
1) Add `service.targetPort` support, or
2) Add first-class `memcachedService` / multi-port Service support when `--memcached_port` is configured, and/or
3) Add a named container port for 11211 when memcached is enabled (so `targetPort: memcached` is possible).
- Related but not the same issue (for context; none of these covers the Helm Service mapping problem directly):
- `https://github.com/dragonflydb/dragonfly/issues/303` (memcached protocol topic)
- `https://github.com/dragonflydb/dragonfly/issues/5096` (memcached_port equals redis port crash)
- `https://github.com/dragonflydb/dragonfly/issues/874` (shows chart pattern `targetPort: dragonfly`, but different problem)
Contributor guide
Research direction
Start with contrib/charts/dragonfly/values.yaml and the chart's Service template, then render the chart with extraArgs --memcached_port=11211 and service.port=11211 to inspect the targetPort mapping. Compare the rendered Service and pod ports, and define completion as Service traffic reaching the configured Memcached listener while preserving the normal Redis service behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- helm, kubernetes
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100