0

I am thinking of setting up multiple chatbots as in a containerized platform lets say docker or Kubernetes, and I would want to be able to access these chatbots through a reverse proxy such as Nginx. any help is appreciated.

My example scenario

I have a multiple chatbots, lets call them Bravo, Charlie, Delta

  • Bravo's IP address and port is 10.0.0.2:8080
  • Charlie's IP : 10.0.0.3:8080
  • Delta's IP :10.0.0.4:8080

All of these bots are living in containers behind a nginx proxy. Now if I want to access these chatbots, I am able to get to the browser with 10.0.0.2:8080 and use the chatbots,

If I could setup a domain (alpha,org) and want to access these chatbots as alpha,com/bravo , or alpha,com/charlie and alpha,com/delta how would I be able to achieve this.?

The Proxy pass directive works only for the index_html and the chatbot application seems to have some kind of base url path that I am unable to figure out. nginx returns a blank page if I inspect the traffic. Help me debug this.

1 Answer 1

2

You can use nginx-ingress controller with this ingress definition: (But first you need to deploy nginx-ingress controller on your cluster, you can use this link)

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: alpha-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: alpha.com
    http:
      paths:
      - path: /bravo
        backend:
          serviceName: BravoService
          servicePort: 80
      - path: /charlie
        backend:
          serviceName: CharlieService
          servicePort: 80
      - path: /delta
        backend:
          serviceName: DeltaService
          servicePort: 80 # You could also use named ports if you already named the port in the service like bravo-http-port

This expects that you have already defined and deployed your services with associated deployments. for Ex:

apiVersion: v1
kind: Service
metadata:
  name: BravoService
  labels:
    app: bravo
spec:
  type: NodePort
  selector:
    app: bravo
  ports:
    - name: bravo-http-port
      protocol: TCP
      port: 80
      targetPort: bravo-port
      nodePort: 8080

---

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: bravo-deployment
  labels:
    app: bravo
spec:
  # init with 3 replicas
  replicas: 1
  selector:
    matchLabels:
      app: bravo
  template:
    metadata:
      labels:
        app: bravo
    spec:
      containers:
      - name: bravo-container
        image: my-docker-repo/project:1.0
        ports:
        - name: bravo-port
          containerPort: 8080

If you have more questions on this please don't hesitate.

2
  • Thanks for the response @alireza-david , I have tried this path based routing as you have mentioned. But when I do this, I am unable to get the contents for the webpage. like the css files, the JS scripts for the frontend is not loading. I get a 404 in the url path alpha.com/bravo/css . It would be great if you could help in stripping the URI to forward the requests to the containers as how it gets to 10.0.0.2:8080/css Nov 27, 2019 at 9:38
  • Oh, I had to mentioned that you can use this rewrite annotaion. I've updated the answer aswell. annotations: nginx.ingress.kubernetes.io/rewrite-target: / Nov 27, 2019 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.