Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I expose a StatefulSet service with ClusterIP None on Google Cloud Platform?

How can I expose a StatefulSet service (cassandra, mysql, etc...) with ClusterIP=None on Kubernetes in Google Cloud Platform?

I need to change the ClusterIP config? Or I need to configure Google Cloud NAT? Or I need to change other things?

Thanks

EDIT: I want to connect to cassandra from an external IP, from anyplace on the internet

EDIT2: I guess that the solution is to use LoadBalance instead of ClusterIP, but when I use LoadBalance, the Cassandra nodes can't find the seed node. Then I sill using ClusterIP=None to Cassandra cluster, and I created another POD with type=LoadBalance to connect to Cassandra and to have connections to exterior. And now it's working :)

like image 821
Rui Martins Avatar asked Dec 13 '25 01:12

Rui Martins


2 Answers

If by "expose" you mean ability to reach your service endpoints without cluster IP , then just use selector in your headless service, i.e.

apiVersion: v1
kind: Service
metadata:
  name: cassandra
spec:
  clusterIP: None
  selector:
    app: cassandra
  ports:
  - port: 80
    targetPort: 80

For more details refer to documentation

Otherwise, if you want to expose your deployments outside of the cluster, you won't be able to do it with headless service.

like image 139
A_Suh Avatar answered Dec 15 '25 18:12

A_Suh


ClusterIP services are not exposed outside of the Kubernetes cluster. Perhaps you mean to use a NodePort or LoadBalancer service instead?

like image 38
coderanger Avatar answered Dec 15 '25 18:12

coderanger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!