x4k3p
x4k3p

Reputation: 1769

Access service on subdomain in Kubernetes

I have following setup:

As I read extensions such like Web UI (kube-ui) can be added as Add-On - which I have added (only kube-ui).

Now if I run a test such like simple-nginx I get following output:

creating pods:

$ kubectl run my-nginx --image=nginx --replicas=2 --port=80

creating service:

$ kubectl expose rc my-nginx --port=80 --type=LoadBalancer          
NAME       LABELS         SELECTOR       IP(S)     PORT(S)
my-nginx   run=my-nginx   run=my-nginx             80/TCP

get service info:

$ kubectl describe service my-nginx                                                                                                
Name:           my-nginx
Namespace:      default
Labels:         run=my-nginx
Selector:       run=my-nginx
Type:           LoadBalancer
IP:             10.100.161.90
Port:           <unnamed>   80/TCP
NodePort:       <unnamed>   31170/TCP
Endpoints:      10.244.19.2:80,10.244.44.3:80
Session Affinity:   None
No events.

I can access my service from every(!) external IP of the nodes.

My question now is as follows:

How can access any started service ether with a subdomain and therefore how can I set this configuration (for example I have domain.com as example) or could it be printed out on which node-IP I have to access my service (although I have only two replicas(?!))?

To describe my thoughts more understandable I mean following:

Upvotes: 2

Views: 1500

Answers (1)

briangrant
briangrant

Reputation: 845

Does your OpenStack cloud provider implementation support services of type LoadBalancer?

If so, the service controller should assign an ingress IP or hostname to the service, which should eventually show up in kubectl describe svc output. You could then set up external DNS for it.

If not, just use type=NodePort, and you'll still get a NodePort on each node. You can then follow the advice in the comment to create an Ingress resource, which can do the port and host remapping.

Upvotes: 0

Related Questions