Service a static website using Kubernetes and Ambassador

1/25/2019

I have a static website bundle I want to serve on my cluster. The bundle is stored in a google cloud storage bucket, which makes me think I may not actually need a separate "server" to return the files.

I have been able to get Python-Flask to reference the files from the bucket, but I can't seem to figure out how to get Ambassador to do the same. I could do something like add the bundle to an nginx instance, but I don't want to build the JS bundle into any docker image so I can do rapid updates.

I can't figure out how to set up an ambassador route to do the following:

If a user goes to

https://my-website.com/

They get the index.html served from my Google Bucket my-bucket/index.html

and when the index.html references a file internally (/static/js/main.js), Ambassador serves up the file found at my-bucket/static/js/main.js

I have tried setting up a service like so:

apiVersion: v1
kind: Service
metadata:
  annotations:
    getambassador.io/config: |
      ---
      apiVersion: ambassador/v0
      kind: Mapping
      name: website_mapping
      prefix: /website/
      service: https://my-bucket-url/index.html
  name: website-service
  labels:
    app: website-service
spec:
  ports:
    - port: 80
      targetPort: 80
      name: http-website
  selector:
    app: website

But navigating to my-website.com/website/ only gets me a 503 error with the console complaining "the character of the encoding of the plain text document was not declared"

I feel like I'm going about this wrong. Can I serve straight from the bucket like this using Ambassador, or do I really need something like nginx?

-- mstorkson
envoyproxy
google-cloud-storage
javascript
kubernetes

1 Answer

3/27/2019

Ambassador is actually not a web server (as Laszlo Valko points out). It needs to proxy your request to some other web server for this to work -- that can certainly be Flask (in fact, the Ambassador diagnostic service is a Flask application started at boot time inside the Ambassador pod), but it needs to be running somewhere. :)

-- Flynn
Source: StackOverflow