online
online

Reputation: 5507

How to connect to an headless service in Kubernetes from outside?

I created an headless service:

apiVersion: v1
kind: Service
metadata:
  name: myapp-service-headless
spec:
  ports:
    - port: 80
  selector:
    app: myapp
  clusterIP: None

From Kubernetes dashboard I can see its Internal endpoints:

myapp-service-headless:80 TCP
myapp-service-headless:0 TCP

In this application, I also set internal endpoint to:

http://myapp-service-headless

But from outside, how can I access its IP to connect API?

For example, my Kubernetes' IP is 192.168.99.100, then connect to 192.168.99.100 is okay?

Now the service status from Kubernetes dashboard

Services

enter image description here

Service Details

enter image description here

Upvotes: 6

Views: 10448

Answers (1)

sfgroups
sfgroups

Reputation: 19099

There is two option to expose the service outside, you can use the ingress controller to connect to the server.

The simple method is change your service type to NodePort, then you should be able access server using NodeIP and service external port number.

here is the more info.

https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport

Upvotes: 6

Related Questions