% mkdir k8s-react-multidomain && cd k8s-react-multidomain
% npx create-react-app k8s-react-multidomain
...
We suggest that you begin by typing:
cd k8s-react-multidomain
npm start
Happy hacking!
function App() {
const url = window.location.href;
const subdomain = url.split(".")[0].split("//")[1];
return (
<div className="App">
<span>{subdomain}</span>
</div>
);
}
export default App;
npm-debug.log
.dockerignore
**/.git
**/.DS_Store
**/node_modules
# Стянуть последний alpine linux
FROM node:alpine AS builder
# Выставить env
ENV NODE_ENV production
# Любая директория для приложения
WORKDIR /app
# Установить npm зависимости
COPY ./package.json ./
RUN npm install
# Скопировать файлы
COPY . .
# Собрать приложение
RUN npm run build
# Стянуть последний nginx
FROM nginx
# Скопировать что собрали
COPY --from=builder /app/build /usr/share/nginx/html
# Скопировать nginx.com (см в репе)
COPY nginx.conf /etc/nginx/conf.d/default.conf
docker build -t myreact:1.0 .
docker run -d -p 3000:80 --name react myreact:1.0
curl http://127.0.0.1:3000
...
<title>React App</title><script defer="defer" src="/static/js/main.753507f7.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript>
docker tag 9428b361d428 spl3k/myreact:1.0
docker push spl3k/myreact:1.0
$ kubectl apply -f 00-react.yaml
$ kubectl apply -f 01-ingress.yaml