Illustration Image

Access stateful headless kubernetes externally?

I have created Cassandra stateful/headless cluster on AWS and it's working fine inside the cluster. The only problem is I am not able to access it from outside cluster. I tried most of the things on the Kubernetes documentation or StackOverflow references, but still not able to solve it.

I have a working security group from AWS. Here are my service and statefulset yaml files.

apiVersion: v1
kind: Service
metadata:
  name: cassandra
spec:
  externalTrafficPolicy: Local
  ports:
  - nodePort: 30000
    port: 30000
    protocol: TCP
    targetPort: 9042
  selector:
    app: cassandra
  type: NodePort
apiVersion: "apps/v1"
kind: StatefulSet
metadata:
  name: cassandra
spec:
  serviceName: cassandra
  replicas: 2
  selector:
    matchLabels:
      app: cassandra
  template:
    metadata:
      labels:
        role: cassandra
        app: cassandra
    spec:
      terminationGracePeriodSeconds: 10
      containers:
        - env:
            - name: MAX_HEAP_SIZE
              value: 1024M
            - name: HEAP_NEWSIZE
              value: 1024M
            - name: CASSANDRA_SEEDS
              value: "cassandra-0.cassandra.default.svc.cluster.local"
            - name: CASSANDRA_CLUSTER_NAME
              value: "SetuCassandra"
            - name: CASSANDRA_DC
              value: "DC1-SetuCassandra"
            - name: CASSANDRA_RACK
              value: "Rack1-SetuCassandra"
            - name: CASSANDRA_SEED_PROVIDER
              value: io.k8s.cassandra.KubernetesSeedProvider
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
          image: library/cassandra:3.11
          name: cassandra
          volumeMounts:
            - mountPath: /cassandra-storage
              name: cassandra-storage
          ports:
            - containerPort: 9042
              name: cql
  volumeClaimTemplates:
  - metadata:
      name: cassandra-storage
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 320Gi
Become part of our
growing community!
Welcome to Planet Cassandra, a community for Apache Cassandra®! We're a passionate and dedicated group of users, developers, and enthusiasts who are working together to make Cassandra the best it can be. Whether you're just getting started with Cassandra or you're an experienced user, there's a place for you in our community.
A dinosaur
Planet Cassandra is a service for the Apache Cassandra® user community to share with each other. From tutorials and guides, to discussions and updates, we're here to help you get the most out of Cassandra. Connect with us and become part of our growing community today.
© 2009-2023 The Apache Software Foundation under the terms of the Apache License 2.0. Apache, the Apache feather logo, Apache Cassandra, Cassandra, and the Cassandra logo, are either registered trademarks or trademarks of The Apache Software Foundation. Sponsored by Anant Corporation and Datastax, and Developed by Anant Corporation.

Get Involved with Planet Cassandra!

We believe that the power of the Planet Cassandra community lies in the contributions of its members. Do you have content, articles, videos, or use cases you want to share with the world?