Why cant nextjs see k8s hostname applied to pod / container

I’m currently having fun with k8s AKS on azure with DevOps etc. and I’m creating a NextJs app or rather two that are connected via their zone system where you in next.config.js can add rewrite and it automatically sets proxy op to run on the other service.

But I have run into the problem is that I cant apply the hostname or call the hostname in the NextJs config from the pod / container env.
I am running node server for NextJs and not standalone, which I have read it serialised the config on build rather than load them on start.

I have tried checking by executing a kubectl command to printenv and I can see they are there even from my own secrets I have created and applied to the deployment.

So question is – why doesn’t it want to take the hostname from k8s have given the pod so the multiple containers can talk together.

Is there a better way to do this – should I split them up into multiple pods on the deploy meant and do some port service or ?

Deploy-definition

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>apiVersion: apps/v1
kind: Deployment
metadata:
name: project-home-dev-deploy
namespace: project-dev
labels:
environment: development
name: project-home-dev-deploy
app: project-home-dev-deploy
spec:
replicas: 1
selector:
matchLabels:
app: project-home-dev-pod
template:
metadata:
name: project-home-dev-pod
namespace: project-dev
labels:
environment: development
app: project-home-dev-pod
name: project-home-dev-pod
spec:
nodeSelector:
kubernetes.io/os: linux
containers:
- name: project-home-dev-container
image: Contain registry where img is stored.
envFrom:
- secretRef:
name: project-dev-secrets-env
ports:
- containerPort: 3000
- name: project-admin-dev-container
image: Contain registry where img is stored.
envFrom:
- secretRef:
name: project-dev-secrets-env
ports:
- containerPort: 3001
</code>
<code>apiVersion: apps/v1 kind: Deployment metadata: name: project-home-dev-deploy namespace: project-dev labels: environment: development name: project-home-dev-deploy app: project-home-dev-deploy spec: replicas: 1 selector: matchLabels: app: project-home-dev-pod template: metadata: name: project-home-dev-pod namespace: project-dev labels: environment: development app: project-home-dev-pod name: project-home-dev-pod spec: nodeSelector: kubernetes.io/os: linux containers: - name: project-home-dev-container image: Contain registry where img is stored. envFrom: - secretRef: name: project-dev-secrets-env ports: - containerPort: 3000 - name: project-admin-dev-container image: Contain registry where img is stored. envFrom: - secretRef: name: project-dev-secrets-env ports: - containerPort: 3001 </code>
apiVersion: apps/v1
kind: Deployment
metadata:
  name: project-home-dev-deploy
  namespace: project-dev
  labels:
    environment: development
    name: project-home-dev-deploy
    app: project-home-dev-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: project-home-dev-pod
  template:
    metadata:
      name: project-home-dev-pod
      namespace: project-dev
      labels:
        environment: development
        app: project-home-dev-pod
        name: project-home-dev-pod
    spec:
      nodeSelector:
        kubernetes.io/os: linux
      containers:
      - name: project-home-dev-container
        image: Contain registry where img is stored.
        envFrom:
        - secretRef:
            name: project-dev-secrets-env
        ports:
        - containerPort: 3000

      - name: project-admin-dev-container
        image: Contain registry where img is stored.
        envFrom:
        - secretRef:
            name: project-dev-secrets-env
        ports:
        - containerPort: 3001

DockerFile

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>FROM node:22.3-alpine AS base
FROM base AS builder
RUN apk update
RUN apk add --no-cache libc6-compat
WORKDIR /app
RUN npm -g i turbo
COPY . .
RUN turbo prune project-home --docker
FROM base AS installer
RUN apk update
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/package-lock.json ./package-lock.json
RUN npm install
COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json
RUN npm run build
FROM base AS runner
WORKDIR /app
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs
COPY --from=installer /app/apps/home/next.config.js .
COPY --from=installer /app/apps/home/package.json .
COPY --from=installer --chown=nextjs:nodejs /app/apps/home/src ./src
COPY --from=installer --chown=nextjs:nodejs /app/apps/home/.next ./.next
COPY --from=installer --chown=nextjs:nodejs /app/apps/home/publi[c] ./public
COPY --from=installer --chown=nextjs:nodejs /app/node_modules ./node_modules
EXPOSE 3000
ENV PORT 3000
CMD ["npm", "run", "start"]
</code>
<code>FROM node:22.3-alpine AS base FROM base AS builder RUN apk update RUN apk add --no-cache libc6-compat WORKDIR /app RUN npm -g i turbo COPY . . RUN turbo prune project-home --docker FROM base AS installer RUN apk update RUN apk add --no-cache libc6-compat WORKDIR /app COPY .gitignore .gitignore COPY --from=builder /app/out/json/ . COPY --from=builder /app/out/package-lock.json ./package-lock.json RUN npm install COPY --from=builder /app/out/full/ . COPY turbo.json turbo.json RUN npm run build FROM base AS runner WORKDIR /app RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs USER nextjs COPY --from=installer /app/apps/home/next.config.js . COPY --from=installer /app/apps/home/package.json . COPY --from=installer --chown=nextjs:nodejs /app/apps/home/src ./src COPY --from=installer --chown=nextjs:nodejs /app/apps/home/.next ./.next COPY --from=installer --chown=nextjs:nodejs /app/apps/home/publi[c] ./public COPY --from=installer --chown=nextjs:nodejs /app/node_modules ./node_modules EXPOSE 3000 ENV PORT 3000 CMD ["npm", "run", "start"] </code>
FROM node:22.3-alpine AS base

FROM base AS builder
RUN apk update
RUN apk add --no-cache libc6-compat
WORKDIR /app
RUN npm -g i turbo
COPY . .
RUN turbo prune project-home --docker

FROM base AS installer
RUN apk update
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/package-lock.json ./package-lock.json
RUN npm install

COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json
RUN npm run build

FROM base AS runner
WORKDIR /app

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs

COPY --from=installer /app/apps/home/next.config.js .
COPY --from=installer /app/apps/home/package.json .
COPY --from=installer --chown=nextjs:nodejs /app/apps/home/src ./src
COPY --from=installer --chown=nextjs:nodejs /app/apps/home/.next ./.next
COPY --from=installer --chown=nextjs:nodejs /app/apps/home/publi[c] ./public
COPY --from=installer --chown=nextjs:nodejs /app/node_modules ./node_modules

EXPOSE 3000
ENV PORT 3000

CMD ["npm", "run", "start"]

next.config.js

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const path = require('path')
const hostname = process.env.HOSTNAME || 'localhost';
const adminPort = process.env.ADMIN_PORT || '3001';
const envAdminUrl = `http://${hostname}:${adminPort}`;
/** @type {import('next').NextConfig} */
module.exports = {
transpilePackages: ['@repo/database'],
eslint: {
ignoreDuringBuilds: true
},
experimental: {
outputFileTracingRoot: path.join(__dirname, '../../'),
},
poweredByHeader: false,
async rewrites() {
return [
{
source: "/:path*",
destination: `/:path*`,
},
{
source: "/admin",
destination: `${envAdminUrl}/admin`,
},
{
source: "/admin/:path*",
destination: `${envAdminUrl}/admin/:path*`,
},
];
},
};
</code>
<code>const path = require('path') const hostname = process.env.HOSTNAME || 'localhost'; const adminPort = process.env.ADMIN_PORT || '3001'; const envAdminUrl = `http://${hostname}:${adminPort}`; /** @type {import('next').NextConfig} */ module.exports = { transpilePackages: ['@repo/database'], eslint: { ignoreDuringBuilds: true }, experimental: { outputFileTracingRoot: path.join(__dirname, '../../'), }, poweredByHeader: false, async rewrites() { return [ { source: "/:path*", destination: `/:path*`, }, { source: "/admin", destination: `${envAdminUrl}/admin`, }, { source: "/admin/:path*", destination: `${envAdminUrl}/admin/:path*`, }, ]; }, }; </code>
const path = require('path')

const hostname = process.env.HOSTNAME || 'localhost';
const adminPort = process.env.ADMIN_PORT || '3001';
const envAdminUrl = `http://${hostname}:${adminPort}`;

/** @type {import('next').NextConfig} */
module.exports = {
  transpilePackages: ['@repo/database'],
  eslint: {
    ignoreDuringBuilds: true
  },
  experimental: {
    outputFileTracingRoot: path.join(__dirname, '../../'),
  },
  poweredByHeader: false,
  async rewrites() {
    return [
      {
        source: "/:path*",
        destination: `/:path*`,
      },
      {
        source: "/admin",
        destination: `${envAdminUrl}/admin`,
      },
      {
        source: "/admin/:path*",
        destination: `${envAdminUrl}/admin/:path*`,
      },
    ];
  },
};

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật