Multiple IPs for a single container

5/31/2016

I'm not sure if this is preferred/correct way of setting up kubernetes, but I have two websites "x.com" and "y.com" each with their own separate IPs. Currently, they running off separate ec2 instances, but I'm in the process of moving our architecture to using docker/kubernetes on aws. What I'd like to do is have a single nginx container that hands of the requests to the appropriate backend services. However, I'm currently stuck on trying to figure out how to point two IPs at the same container.

My k8s setup is like so:

  • Replication controller/pod for x.com
  • Replication controller/pod for y.com
  • Service for x.com
  • Service for y.com
  • Replication controller for nginx, specifying a single replica
  • Service for nginx specifying that I need port 80 and 443.

Is there a way for me to specify that I want two IPs pointing to the single nginx container, or is there a preferred k8s way of solving this problem?

-- Richard
amazon-web-services
kubernetes

2 Answers

6/1/2016

You could use the ingress routing for this:

Also to not use ingress you could setup services type LoadBalancer and then create CNAMEs to the ELB matching the domains you want to route.

-- Steve Sloka
Source: StackOverflow

6/15/2016

I ended up using two separate services/load balancers that point to the same nginx pod but using different ports.

apiVersion: v1
kind: Service
metadata: 
    name: nginx-service1
spec:
    type: LoadBalancer
    ports:
    - name: http
      port: 80
      targetPort: 880
      protocol: TCP
    - name: https
      port: 443
      targetPort: 8443
      protocol: TCP
    selector:
        app: nginx
---
apiVersion: v1
kind: Service
metadata: 
    name: nginx-service2
spec:
    type: LoadBalancer
    ports:
    - name: http
      port: 80
      targetPort: 980
      protocol: TCP
    - name: https
      port: 443
      targetPort: 9443
      protocol: TCP
    selector:
        app: nginx
-- Richard
Source: StackOverflow