Question

How to redirect main domain to the DO App site CDN and specific paths to the k8s ingress controller?

Posted December 2, 2021 190 views
NginxKubernetesDigitalOcean Managed KubernetesDigitalOcean App Platform

My website is located in the DO App and besides this, I have a lot of things in the k8s cluster. I don’t wanna put my website to the k8s, cuz my experience is quite a bit, and especially when DO App provides Global CDN / CI CD / HTTPS by default, so the question is there any way to redirect my users to the website CDN when they try to reach out to domain.com and on domain.com/somethingSpecific redirect them to the k8s LoadBalancer ingress controller?

Maybe I should tell DNS to point domain.com to the k8s ingress and there somehow point “/” path to the DO CDN and specific routes point to the k8s services?
I know that I can tell DNS to point subdomains, e.g. api.domain.com. to the k8s, but I wanna freely pass the cookies in the requests from the main domain.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

One way you can implement this logic is directly in your DO App. I don’t know what framework you’re using, but it probably has some kind of routing functionality such that when someone visits domain.com/somethingSpecific you can either:

  • Return a 302 redirect to the location in Kubernetes
  • Reverse proxy to the Kubernetes backend to transparently serve data from Kubernetes through your DO App.

Would something like this work?

  • Unfortunately, no this will not work, cuz I have just a static site built on the Vue framework. So, these are just static files that DigitalOcean serves over a CDN.
    Again, I just want the site static files (Vue build files) to live in the DO app because the CI CD / CDN / etc. out of the box, and other things like APIs, additional servers, etc. live in the k8s cluster. And the most important is that the main domain should point to the DO App site CDN and /specificRoute to the k8s cluster.

    Guess that I can solve this issue by using CloudFlare as CDN and DNS manager (instead DO App). Just point main domain to the DO App (via CNAME record) and create a rule for /specificRoute to redirect to the k8s ingress LoadBalancer IP. Is it a good solution or are there any better options?

    • I’m not familiar with DO’s CDN, but if there’s no way to do it there, then your cloudflare option makes sense.

      But that that point, why not serve your static content directly on cloudflare?