<p>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.</p>

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

<pre>
apiVersion: v1
kind: Service
metadata:
  name: cassandra
spec:
  externalTrafficPolicy: Local
  ports:
  - nodePort: 30000
    port: 30000
    protocol: TCP
    targetPort: 9042
  selector:
    app: cassandra
  type: NodePort
</pre>

<pre>
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
</pre>

<p>I appreciate any help on this.</p>

Manish Kumar
<p>The headless service created for the stateful set is not meant to be accessed by the users of the service. Its main intent, as per my understanding, was for the intra sts communication between the pods of the given STS (to form the cluster among themselves). For instances, if you have  3 node mongodb cluster (as an STS), mongodb-0 would want to exchange clustering info/data with mongodb-1 and mongodb-2.</p>

<p>If you want to access this service as a user, you are not interested in (or care about) mongodb-0/1/2 but more so as a service. The typical approach is to create a headful service  (possibly with a nodeport if required) and access it.</p>

<p>Basically create two services, one would be a headless service (and use it with STS) and other would be a regular service. The pod selectors can be the same for both the services. </p>
