apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: cassandra
  labels:
    app: cassandra
spec:
  serviceName: cassandra
  replicas: 1
  selector:
    matchLabels:
      app: cassandra
  template:
    metadata:
      labels:
        app: cassandra
    spec:
      terminationGracePeriodSeconds: 1800
      containers:
        - name: cassandra
          image: lodotek/cassandra:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 7000
              name: intra-node
            - containerPort: 7001
              name: tls-intra-node
            - containerPort: 7199
              name: jmx
            - containerPort: 9042
              name: cql
          lifecycle:
            preStop:
              exec:
                command:
                  - /bin/sh
                  - -c
                  - nodetool drain
          env:
            - name: MAX_HEAP_SIZE
              value: 512M
            - name: HEAP_NEWSIZE
              value: 100M
            - name: CASSANDRA_SEEDS
              value: "cassandra-0.cassandra.default.svc.cluster.local"
            - name: CASSANDRA_CLUSTER_NAME
              value: "webapp-cluster"
            - name: CASSANDRA_DC
              value: "webapp-datacenter"
            - name: CASSANDRA_RACK
              value: "webapp-rack"
            - name: CASSANDRA_ENDPOINT_SNITCH
              value: "GossipingPropertyFileSnitch"
            - name: CASSANDRA_KEYSPACE
              value: "webapp"
          readinessProbe:
            exec:
              command:
                - /opt/cassandra/bin/cqlsh
                - -u
                - cassandra
                - -p
                - cassandra
                - -e
                - describe keyspace webapp
            initialDelaySeconds: 15
            timeoutSeconds: 5
