I'm trying to run 2 replicas of cassandra statefulset per namespace. I'm mounting several cassandra configs into one configmap:
{{- if .Values.enabled }}
kind: ConfigMap
apiVersion: v1
metadata:
name: {{ template "cassandra.fullname" . }}
labels:
app: {{ template "cassandra.name" . }}
chart: {{ template "cassandra.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
cassandra.yaml: |
{{ .Files.Get "files/cassandra.yaml" | printf "%s" | indent 4 }}
cassandra-topology.properties: |
{{ .Files.Get "files/cassandra-topology.properties" | printf "%s" | indent 4 }}
{{- end }
which works perfectly fine with any file format and I don't have to parse it through kubectl create configmap <name> --from-file <file>
and then get the parsed format back and use it.
However cassandra.yaml should contain its own name/IP in the "listen_address:" field. But this is managed by kubernetes. So the question is: Is there any way/code that I can put in cassandra.yaml, which will be later translated into pod-IP/pod-name/pod-FQDN, or do I need to write some command for the pod, to edit this value after the pod starts?
you can use hostname of the stateful pod or capture the pod IP using downwardAPI in an environment variable. You can use the variable in cassandra.yaml
refer below sample that you need to include in your pod spec
env:
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: MY_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
One simple way is to write a startup script and from that update the pod ip/name in cassandra.yaml file adn start cassandra