Setting up multiple ingress, services, deployment resources and Cloud DNS

6/7/2016

I'm trying to figure out how to create multiple ingress resources that share an IP. Or, if that isn't possible, I'd like to know if there's some sort of forwarding rule I can use in conjunction with a Cloud DNS entry that ensures all traffic to an IP (which I can make static) goes to one kubernetes cluster.

Essentially I'd like to set up an ingress with each service that contains one or more subdomains and all those ingresses to point to the same cluster. Right now I get a different ephemeral IP with each ingress. Can I create some forwarding rule that points all traffic to a static IP go to a cluster and then perhaps create a wildcard DNS entry that points all subdomains to the static IP?

Here's an example config similar to what I'm using:

apiVersion: v1
kind: Service
metadata:
  name: api-service
  labels:
    name: api-service
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 3000
      protocol: TCP
  selector:
    name: api-deployment
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: api-deployment
  labels:
    name: api-deployment
spec:
  template:
    metadata:
      labels:
        name: api
    spec:
      containers:
        - image: us.gcr.io/[project]/hello-world:1.0.0
          name: api
          ports:
            - containerPort: 3000
          env:
            - name: NAME
              value: api
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: api-ingress
spec:
  backend:
    serviceName: api-service
    servicePort: 80
  rules:
  - host: api.example.com
    http:
      paths:
      - backend:
          serviceName: api-service
          servicePort: 80

I create these resources on a kube cluster like so:

$ kubectl create -f api.yml

And then see the ingress that's created like so:

$ kubectl get ing
NAME              RULE             BACKEND           ADDRESS          AGE
api-ingress       -                api-service:80    130.211.32.223   1h
                  api.example.com
                                   api-service:80

Now, imagine you copy that yaml above and change the service, deployment and ingress name to api-2 and create those. You'd end up with something like this:

$ kubectl get ing
NAME              RULE             BACKEND           ADDRESS          AGE
api-ingress       -                api-service:80    130.211.32.223   1h
                  api.example.com
                                   api-service:80
api-2-ingress     -                api-2-service:80  130.211.22.214   1h
                  api-2.example.com
                                   api-2-service:80

Which is fine... But I need to ensure all traffic to *.example.com goes to the cluster so the ingresses can do their magic and route the requests to the right services.

I know I could have a single ingress resource created and patch that one instead of creating a new one but I'm trying to avoid that and would prefer if I can create one per service.

Is this possible somehow?

Related: https://github.com/kubernetes/kubernetes/issues/26935

-- luisgo
google-compute-engine
google-kubernetes-engine
kubernetes

1 Answer

6/9/2016

Each ingress resource will have a separate IP. If you need to share a single IP between domains, then you will need to configure both domains in the same ingress resource. Try kubectl edit if you don't want to patch directly on the command line.

-- Robert Bailey
Source: StackOverflow