apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: cassandra
  name: cassandra
spec:
  replicas: 3
  selector:
    matchLabels:
      app: cassandra
  serviceName: cassandra
  template:
    metadata:
      labels:
        app: cassandra
    spec:
      containers:
      - 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: K8Demo
        - name: CASSANDRA_DC
          value: DC1-K8Demo
        - name: CASSANDRA_RACK
          value: Rack1-K8Demo
        - name: CASSANDRA_SEED_PROVIDER
          value: io.k8s.cassandra.KubernetesSeedProvider
        - name: POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        image: gcr.io/google-samples/cassandra:v14
        imagePullPolicy: Always
        lifecycle:
          preStop:
            exec:
              command:
              - /bin/sh
              - -c
              - nodetool drain
        name: cassandra
        ports:
        - containerPort: 7000
          name: intra-node
        - containerPort: 7001
          name: tls-intra-node
        - containerPort: 7199
          name: jmx
        - containerPort: 9042
          name: cql
        readinessProbe:
          exec:
            command:
            - /bin/bash
            - -c
            - /ready-probe.sh
          initialDelaySeconds: 15
          timeoutSeconds: 5
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 500m
            memory: 1Gi
        securityContext:
          capabilities:
            add:
            - IPC_LOCK
        volumeMounts:
        - mountPath: /var/lib/cassandra
          name: cassandra-data
      terminationGracePeriodSeconds: 1800
  volumeClaimTemplates:
  - metadata:
      annotations:
        volume.beta.kubernetes.io/storage-class: fast
      name: cassandra-data
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
