There was an issue when I mounted a configmap to the /etc/cassandra/cassandra.yaml pod. I encountered the error: /etc/cassandra read-only filesystem. After attempting various solutions, such as running the image as the cassandra user with uid=999 & gid=999 (specified in the official cassandra image), using a bash script in the statefulset command: chmod 755 /etc/cassandra, or using command:["-Dcassandra.config=file:///path/to/mounted/cassandra.yaml"], the problem persisted. so I tried some ways that changed my life.
I tried 3 different attemptsto deploy it, choose one based on your needs: Deploy Cassandra with operator This method is suggested because you’re not engaging with cassandra’s complexility.
Deploy Cassandra with Bitnami Helm It’s not working for kubernetes <v1.19
Deploy cassandra by shooting yourself in the foot
Deploy Cassandra with operator
first of all we need to install cert-manager to deploy cassandra operator
The limits line is because of an error I’ve got for pod is not creating so based on this issue I changed this values. This method is not working in k8s version <1.19 let’s try another way.
Deploy cassandra by shooting yourself in the foot
Let’s build our custome cassandra image: After days of trying I finally give up. no more charts and operators! I tried to solve main problem “Mounting Cassandra.yaml into /etc/cassandra/ facing read-only file system error“ I started to write a Docker file that pulls cassandra then start it with CMD="-Dcassandra.config=/path/to/cassandra.yaml" lets write it:
1 2 3 4 5 6 7
FROM <private-registery.io>/cassandra:5.0 WORKDIR /app COPY cassandra.yaml . COPY docker-entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/docker-entrypoint.sh CMD ["-Dcassandra.config=file:///app/cassandra.yaml"] ENTRYPOINT ["docker-entrypoint.sh"]
Extra work: This is GitLab ci to build and push image to private registery then use it in statefulset:
--- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: cassandra-test-pv-claim spec: accessModes: - ReadWriteOnce resources: requests: storage: 20Gi # how much is claimed storageClassName: standard
We should pass pod ip to image with POD_IP = valueFrom.fieldRef.fieldPath.status.podIP in statefulset. It’s important because we should set listen_address in cassandra.yaml to this ip. docker-entrypoint.sh will change these addresses by default but we need to change this entrypoint for new image we’re building.
# first arg is `-f` or `--some-option` # or there are no args if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then set -- cassandra -f "$@" fi
# allow the container to be started with `--user` if [ "$1" = 'cassandra' -a "$(id -u)" = '0' ]; then find "/etc/cassandra" /var/lib/cassandra /var/log/cassandra \ \! -user cassandra -exec chown cassandra '{}' + exec gosu cassandra "$BASH_SOURCE" "$@" fi
_ip_address() { # scrape the first non-localhost IP address of the container # in Swarm Mode, we often get two IPs -- the container IP, and the (shared) VIP, and the container IP should always be first ip address | awk ' $1 != "inet" { next } # only lines with ip addresses $NF == "lo" { next } # skip loopback devices $2 ~ /^127[.]/ { next } # skip loopback addresses $2 ~ /^169[.]254[.]/ { next } # skip link-local addresses { gsub(/\/.+$/, "", $2) print $2 exit } ' }
# "sed -i", but without "mv" (which doesn't work on a bind-mounted file, for example) _sed-in-place() { local filename="$1"; shift local tempFile tempFile="$(mktemp)" sed "$@" "$filename" > "$tempFile" cat "$tempFile" > "$filename" rm "$tempFile" }
if [ "$1" = 'cassandra' ]; then : ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}
: ${CASSANDRA_LISTEN_ADDRESS='auto'} if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then CASSANDRA_LISTEN_ADDRESS="$(_ip_address)" fi
if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then CASSANDRA_BROADCAST_ADDRESS="$(_ip_address)" fi : ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS}
if [ -n "${CASSANDRA_NAME:+1}" ]; then : ${CASSANDRA_SEEDS:="cassandra"} fi : ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"}
for yaml in \ broadcast_address \ broadcast_rpc_address \ cluster_name \ endpoint_snitch \ listen_address \ num_tokens \ rpc_address \ start_rpc \ ; do var="CASSANDRA_${yaml^^}" val="${!var}" if [ "$val" ]; then _sed-in-place "/etc/cassandra/cassandra.yaml" \ -r 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' fi done
for rackdc in dc rack; do var="CASSANDRA_${rackdc^^}" val="${!var}" if [ "$val" ]; then _sed-in-place "/etc/cassandra/cassandra-rackdc.properties" \ -r 's/^('"$rackdc"'=).*/\1 '"$val"'/' fi done fi
exec "$@"
I changed _sed-in-place "$CASSANDRA_CONF/cassandra.yaml" -r 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' to _sed-in-place "cassandra.yaml" -r 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' This is our custome configuration in /app workdir. After building image and deploying cassandra I checked pod to see if my has configs in cassandra.yaml has been added. Exec into pod then use cqlsh to connect to cassandra thenuse query SELECT * FROM system_views.settings ; to see all configs.