Next.js Discord

Discord Forum

NextJS env in K8

Unanswered
keerthieaaswar_25 posted this in #help-forum
Open in Discord
I have a nextjs app hosted in kubernetes with env variables added in the kubernetes server but not as a env file so my nextjs app is unable to read the env values though they start with NEXT_PUBLIC any thoughts here

3 Replies

as you may know, Next.js generates static pages when creating a Docker image, so NEXT_PUBLIC are backed in JS files when creating the image. only dynamic pages can grab env variables via k8s yaml files when spinning up.
@tafutada777 any way to over come this? i tried addind the runtimeconfig to the nextjs-congif and try accessing is in in the file even that didnt work
basically, statically generated files are static, supposed to be cached on CDN edge servers across countries. in general, cached files need to be purged to update them. i use GCP k8s, docker images need to be copied and run immediately to minimize cold start time, then update load balancer routing to switch traffic.
say, suppose that if we have NEXT_PUBLIC_XXX to point to GraphQL server, we could get the endpoint dynamically via an API, like www.nextjs.server/getGraphQLURL in useEffect(). i guess.