PostStart hook seems to not work even though there is no failure

12/14/2017

I have a pod running a cassandra container. I want to create a keyspace once the container starts. I tried using the postStart hook. For some reason it does not fail but the keyspace does not get created. But I tried the same command in the readinessProbe as a hack and it worked fine. Can someone help me understand what's wrong with my configuration. Thanks in advance

apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-cass-volume-1
  labels:
    type: local
    app: test
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /tmp/data/cass-volume-1
---
apiVersion: v1
kind: Service
metadata:
  name: test-cassandra
  labels:
    app: test
spec:
  ports:
    - port: 9042
  selector:
    app: test
    tier: cass
  clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: cass-pv-claim
  labels:
    app: test
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: test-cassandra
  labels:
    app: test
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: test
        tier: cass
    spec:
      containers:
      - image: cassandra:latest
        name: cassandra
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9042
          name: cass-port
        volumeMounts:
        - name: cass-persistent-storage
          mountPath: /var/lib/cassandra
        readinessProbe:
          exec:
            command: ["cqlsh", "-e", "CREATE KEYSPACE IF NOT EXISTS     test1234 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}  AND durable_writes = true;"]
          initialDelaySeconds: 30
          periodSeconds: 30
          timeoutSeconds: 10
          failureThreshold: 5
        lifecycle:
          postStart:
            exec:
              command: ["/bin/bash", "-c", "until echo 
#x27;CREATE KEYSPACE IF NOT EXISTS test908 WITH replication = {\'class\': \'SimpleStrategy\', \'replication_factor\': \'1\'} AND durable_writes = true;' | cqlsh ; do echo boo; sleep 2; done"
] volumes: - name: cass-persistent-storage persistentVolumeClaim: claimName: cass-pv-claim
-- dakrpssngr
kubernetes

0 Answers