Kubernetes Services Architecture

4/6/2018

I'm trying to connect have NGINX direct traffic to different parts of my app through the config file, but I can't figure it out for the life of me. Here is my current setup:

  http-service (loadbalancer)
  NGINX (port 80)
  website-service (10.27.246.107, port 8000, targetPort 8000, selector 'run: website')
  website (label 'run: website', containerPort 8000)

  NGINX Conf
  upstream website{
    server 10.27.246.107:8000
  }

This is a normal nginx pod using containerPort 80 at the moment.

Am I going about this the right way?

-- ThatCampbellKid
google-kubernetes-engine
kubernetes
kubernetes-service
nginx

1 Answer

4/6/2018

The best way to rout traffic to different part of your application is using Ingress. In Ingress, you can describe all your paths into all parts of your application. It will look like:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /foo
        backend:
          serviceName: website1
          servicePort: 80
      - path: /bar
        backend:
          serviceName: website2
          servicePort: 3368

Actually, Ingress-controller is based on Nginx, but anyway you can choose another engine, for example, HAproxy. Ingress was designed for using in Kubernetes and it has more features in Kubernetes. For example, your website upstream should be described as a service in Kubernetes:

kind: Service
apiVersion: v1
metadata:
  name: website1
spec:
  selector:
    app: python-web-site
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080

Anyway, you can route traffic by Nginx and expose it to the world, but the best practice is to uses Ingress in Kubernetes.

-- Nick Rak
Source: StackOverflow