Kubernetes Cluster APP DNS

3/4/2017

If I have a domain name www.domain.com registered and I have fresh kubernetes cluster up and running. I have successfully lauched Deployments and Services to expose the requirements.

The service is creating a LoadBalancer on my GCE cluster and when I try to access my APP through the the external IP its working.

But this is what I wanted to achieve ideally :

To route all the traffic for my apps as www.app.domain.com , www.app2.domain.com. Upon research I have found that I need an Ingress Controller preferably NGINX server, I have been try to do this and failing miserably.

This is the service exposing JSON for my deployments:

{
    "kind": "Service",
    "apiVersion": "v1",
    "metadata": {
        "name": 'node-js-srv'
    },

    "spec": {
        "type": 'LoadBalancer',
        "label": {
            'app': 'node-js-srv'
        },

        "ports": [
        {
            "targetPort": 8080,
            "protocol": "TCP",
            "port": 80,
            "name": "http"
        },
        {
            "protocol": "TCP",
            "port": 443,
            "name": "https",
            "targetPort": 8080
        }
        ],
        "selector": {
            "app": 'node-js'
        },
    }
}
-- kt14
google-compute-engine
kubernetes
nginx

1 Answer

3/5/2017

GCE/GKE have already a Ingress Controller and you could use that one.

You must specify your service as type NodePortand create a ressource from type Ingress See: https://kubernetes.io/docs/user-guide/ingress/

You find a example for GCE here https://github.com/kubernetes/ingress/tree/master/examples/deployment/gce

Service:

{
    "kind": "Service",
    "apiVersion": "v1",
    "metadata": {
        "name": 'node-js-srv'
    },

    "spec": {
        "type": 'NodePort',
        "label": {
            'app': 'node-js-srv'
        },

        "ports": [
        {
            "targetPort": 8080,
            "protocol": "TCP",
            "port": 80,
            "name": "http"
        },
        {
            "protocol": "TCP",
            "port": 443,
            "name": "https",
            "targetPort": 8080
        }
        ],
        "selector": {
            "app": 'node-js'
        },
    }
}

Ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test
spec:
  rules:
  - host: www.app.domain.com
    http:
      paths:
      - backend:
          serviceName: node-js-srv
          servicePort: 80
  - host: www.app2.domain.com
    http:
      paths:
      - backend:
          serviceName: xyz
          servicePort: 80
-- Sebastian
Source: StackOverflow