I'm trying to deploy a vue.js application on a k8s cluster using docker and docker-compose. I'm also using a nginx ingress controller.
I'm using a configmap to load my custom nginx conf, according to this :
https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
As a matter of fact my application loads properly, but refreshing a page other than the homepage results in a 404 error. And that's just the same if I try and access any given page by its URL.
What am I doing wrong ?
I'm using kubectl in command line to deploy.
Here's my Dockerfile :
# build environment
FROM node:12.2.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY ./[project folder]/ .
RUN npm config set unsafe-perm true
RUN npm install --silent
RUN npm install @vue/cli@3.7.0 -g
RUN npm run build
# production environment
FROM nginx:1.16.0-alpine
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
My ingress.yaml:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: foo-ingress-lb
annotations:
kubernetes.io/ingress.class: "nginx"
kubernetes.io/tls-acme: "true"
cert-manager.io/issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
tls:
- hosts:
- www.foo.com
# This assumes tls-secret exists and the SSL
# certificate contains a CN for foo.bar.com
secretName: tls-secret
rules:
- host: www.foo.com
http:
paths:
- path: /.*
pathType: Prefix
backend:
service:
name: my-service
port:
number: 80
My configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: vue-config
labels:
app: vue-config
data:
default.conf:
server {
listen 8080 default;
root /var/www/app;
location / {
try_files $uri $uri/ /index.html;
}
}
service.yaml
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
ports:
- port: 80
name: http-front
protocol: TCP
targetPort: 80
selector:
app: my-app
And finally my deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: "my-deployment"
spec:
replicas: 1
selector:
matchLabels:
app: "my-app"
template:
metadata:
labels:
app: "my-app"
spec:
containers:
- name: "vue-nginx"
image: XXX/nginx:alpine
volumeMounts:
- mountPath: /var/www/app
name: html-files
- mountPath: /etc/nginx/conf.d
name: config
ports:
- containerPort: 8080
imagePullPolicy: "Always"
- name: "vue"
image:XXX/my_image:latest
volumeMounts:
- mountPath: /var/www/app
name: html-files
ports:
- containerPort: 8080
imagePullPolicy: "Always"
imagePullSecrets:
- name: registry-secret
restartPolicy: Always
volumes:
- name: html-files
emptyDir: {}
- name: config
configMap:
name: vue-config
kubectl logs -n kube-system nginx-ingress-xxx
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET / HTTP/2.0" 200 3114 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 684 0.019 [default-maorie-service-front-80] [] 100.64.0.205:80 3114 0.016 200 eaa454a87cf4cee8929f15f3ecd75dcc
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /css/app.8b722d7e.css HTTP/2.0" 200 11488 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 85 0.001 [default-maorie-service-front-80] [] 100.64.0.205:80 11488 0.000 200 6cce6ff53f0b3b57807eef9df4ab1e2d
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /css/chunk-vendors.2072d5c4.css HTTP/2.0" 200 398846 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 36 0.005 [default-maorie-service-front-80] [] 100.64.0.205:80 398846 0.004 200 ea59b05209b2d7e910ac380ceda13b3f
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /js/app.147dc57f.js HTTP/2.0" 200 46213 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 38 0.002 [default-maorie-service-front-80] [] 100.64.0.205:80 46213 0.000 200 cc6b44751229b2ef4a279defae770da5
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /js/chunk-vendors.ed6dc4c7.js HTTP/2.0" 200 590498 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 36 0.004 [default-maorie-service-front-80] [] 100.64.0.205:80 590498 0.004 200 49e3731caaf832ec21e669affa6c722d
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /css/chunk-2678b26c.8577e149.css HTTP/2.0" 200 2478 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 38 0.002 [default-maorie-service-front-80] [] 100.64.0.205:80 2478 0.000 200 001a3ce8a18e6c9b8433f84ddd7a0412
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /css/chunk-2470e996.066be083.css HTTP/2.0" 200 72983 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 94 0.006 [default-maorie-service-front-80] [] 100.64.0.205:80 72983 0.008 200 092515d8d6804324d24fc3fabad87eba
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /css/chunk-30fff3f3.e2b55839.css HTTP/2.0" 200 20814 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 38 0.001 [default-maorie-service-front-80] [] 100.64.0.205:80 20814 0.000 200 f9f78eb5b9b1963a06d386a1c9421189
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /css/chunk-3db1ab7a.0a0e84c4.css HTTP/2.0" 200 3329 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 38 0.001 [default-maorie-service-front-80] [] 100.64.0.205:80 3329 0.000 200 d66e57d023158381d0eb7b4ce0fcf4c1
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /css/chunk-7ac8b24c.353e933b.css HTTP/2.0" 200 10170 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 38 0.003 [default-maorie-service-front-80] [] 100.64.0.205:80 10170 0.000 200 fcb3655b95599822f79587650ca0c017
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /js/chunk-2678b26c.e69fb49a.js HTTP/2.0" 200 103310 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 37 0.009 [default-maorie-service-front-80] [] 100.64.0.205:80 103310 0.008 200 3423ac43407db755c1a23bca65ca8a0e
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /js/canvg.a381dd7b.js HTTP/2.0" 200 143368 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 31 0.009 [default-maorie-service-front-80] [] 100.64.0.205:80 143368 0.008 200 61d6e047f66dc9b36c836c1b49d2452d
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /js/chunk-3db1ab7a.6fc5dc72.js HTTP/2.0" 200 8157 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 37 0.009 [default-maorie-service-front-80] [] 100.64.0.205:80 8157 0.008 200 90231ff6f00b168861f10511ab58ae29
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /js/chunk-6e83591c.163e5349.js HTTP/2.0" 200 22685 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 37 0.009 [default-maorie-service-front-80] [] 100.64.0.205:80 22685 0.008 200 7d56be2022473cc6055cf8101090fdb7
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /js/chunk-7ac8b24c.1a4727cd.js HTTP/2.0" 200 37637 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 37 0.009 [default-maorie-service-front-80] [] 100.64.0.205:80 37637 0.008 200 e38c234d67700b4f4e2ffe4125bed445
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /css/chunk-b09da666.b0ea57ae.css HTTP/2.0" 200 1414 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 38 0.009 [default-maorie-service-front-80] [] 100.64.0.205:80 1414 0.008 200 e8b8c016069e4c59c929b61e8ba5502b
195.154.69.132 - - [21/Jan/2021:09:23:06 +0000] "GET /js/chunk-b09da666.e5df996b.js HTTP/2.0" 200 1228 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 38 0.009 [default-maorie-service-front-80] [] 100.64.0.205:80 1228 0.008 200 4964cb095baf55cebed49bbcc3fe1af2
195.154.69.132 - - [21/Jan/2021:09:23:08 +0000] "GET /js/chunk-30fff3f3.f6defc09.js HTTP/2.0" 200 3386928 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 37 1.634 [default-maorie-service-front-80] [] 100.64.0.205:80 3386928 1.632 200 4ed3d78d4d72be629deaf579670168ff
195.154.69.132 - - [21/Jan/2021:09:23:08 +0000] "GET /img/logo.956610d4.png HTTP/2.0" 200 6620 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 75 0.355 [default-maorie-service-front-80] [] 100.64.0.205:80 6620 0.352 200 c16abf3b959c147ab469b73fd548dc95
195.154.69.132 - - [21/Jan/2021:09:23:13 +0000] "GET /img/icons/favicon-32x32.png HTTP/2.0" 200 1690 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 34 0.583 [default-maorie-service-front-80] [] 100.64.0.205:80 1690 0.584 200 f7c2c72bebd294c07f174fa91c4fd40f
195.154.69.132 - - [21/Jan/2021:09:23:15 +0000] "GET /js/pdfmake.b17ba0e4.js HTTP/2.0" 200 2127948 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 32 8.697 [default-maorie-service-front-80] [] 100.64.0.205:80 2127948 8.696 200 edb7e05dd9d87cfc91bc5986b80ff8a8
195.154.69.132 - - [21/Jan/2021:09:23:20 +0000] "GET /js/xlsx.a4e6cbf1.js HTTP/2.0" 200 924857 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 30 13.529 [default-maorie-service-front-80] [] 100.64.0.205:80 924857 13.528 200 8ffa5bb28d9d255e69021ccce35a4dfe
195.154.69.132 - - [21/Jan/2021:09:23:20 +0000] "GET /js/chunk-2470e996.bc9a0d30.js HTTP/2.0" 200 9615968 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 37 13.992 [default-maorie-service-front-80] [] 100.64.0.205:80 9615968 13.992 200 6e42aeb8a644afa385aa8a166fbb5860
195.154.69.132 - - [21/Jan/2021:09:23:31 +0000] "GET /js/chunk-2470e996.bc9a0d30.js HTTP/2.0" 200 9615968 "https://dev.maorie.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 36 10.464 [default-maorie-service-front-80] [] 100.64.0.205:80 9615968 10.464 200 f8eb813e1091ed422525611f61a17d68
195.154.69.132 - - [21/Jan/2021:09:35:01 +0000] "GET /service-worker.js HTTP/2.0" 200 1069 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" 919 0.004 [default-maorie-service-front-80] [] 100.64.0.205:80 1069 0.004 200 a03dd0f950c451a8016823c28a958dae
195.154.69.132 - - [21/Jan/2021:09:35:01 +0000] "GET /precache-manifest.2a722082efdadd279fa63223d8219496.js HTTP/2.0" 200 3232 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" 51 0.009 [default-maorie-service-front-80] [] 100.64.0.205:80 3232 0.008 200 e8cdcd5bc52b8a9a8777de4a1e680f1d
195.154.69.132 - - [21/Jan/2021:09:35:05 +0000] "GET /service-worker.js HTTP/2.0" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" 50 0.002 [default-maorie-service-front-80] [] 100.64.0.205:80 0 0.000 304 c0e319cf30abfffd9dc13da6bad8453c
193.32.164.26 - - [21/Jan/2021:10:06:33 +0000] "\x03\x00\x00/*\xE0\x00\x00\x00\x00\x00Cookie: mstshash=Administr" 400 150 "-" "-" 0 0.021 [] [] - - - - 5de24d60404270018011b04db4194bd4
193.32.164.26 - - [21/Jan/2021:10:06:33 +0000] "\x03\x00\x00/*\xE0\x00\x00\x00\x00\x00Cookie: mstshash=Administr" 400 150 "-" "-" 0 0.019 [] [] - - - - 860c19f03a627f6de82bd538fc0c68f1
195.154.69.132 - - [21/Jan/2021:10:20:14 +0000] "\xAA\xAA\xAA\xAAUUUUUUUU\xAA\xAA\xAA\xAAUUUU\xAA\xAA\xAA\xAAUUUU\xAA\xAA\xAA\xAAUUUU\xAA\xAA\xAA\xAAUUUU\xAA\xAA\xAA\xAAUUUU\xAA\xAA\xAA\xAAUUUU\xAA\xAA\xAA\xAA" 400 150 "-" "-" 0 0.015 [] [] - - - - a604c37ad900da39307e364e55f4db90
195.154.69.132 - - [21/Jan/2021:10:25:19 +0000] "GET /service-worker.js HTTP/2.0" 200 1069 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" 914 0.015 [default-maorie-service-front-80] [] 100.64.0.205:80 1069 0.016 200 5856773011e3f4887361fd864e7ca3cc
195.154.69.132 - - [21/Jan/2021:10:25:24 +0000] "GET /service-worker.js HTTP/2.0" 200 1069 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" 13 0.001 [default-maorie-service-front-80] [] 100.64.0.205:80 1069 0.000 200 a2157ea238ab87fa87f59262a4023076
5.188.210.227 - - [21/Jan/2021:10:30:35 +0000] "\x05\x01\x00" 400 150 "-" "-" 0 0.622 [] [] - - - - b42d10d3b0579c8c55d3febbebc1da59
5.188.210.227 - - [21/Jan/2021:10:31:47 +0000] "\x04\x01\x00P\x05\xBC\xD2\xE3\x00" 400 150 "-" "-" 0 0.380 [] [] - - - - 77536a3304f9d249198240df300dec18
195.154.69.132 - - [21/Jan/2021:10:44:04 +0000] "GET / HTTP/1.1" 200 3114 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0" 255 0.013 [default-maorie-service-front-80] [] 100.64.0.205:80 3114 0.012 200 2e568e4805e1bfd0ccdfd8e91e5807c3
157.245.176.143 - - [21/Jan/2021:10:54:31 +0000] "SSTP_DUPLEX_POST /sra_{BA195980-CD49-458b-9E23-C84EE0ADCD75}/ HTTP/1.1" 400 150 "-" "-" 192 0.000 [] [] - - - - e28b66acd059bf0d8c9264395c119aad
E0121 11:00:21.036598 6 leaderelection.go:357] Failed to update lock: etcdserver: request timed out
195.154.69.132 - - [21/Jan/2021:11:21:48 +0000] "GET / HTTP/1.1" 308 164 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0" 255 0.000 [default-maorie-service-front-80] [] - - - - 5cf25e7eba89ae4a9c06d81532951824
18.136.126.138 - - [21/Jan/2021:11:46:06 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03\x8F^\xE5@p\xB3\xA4\xA7H\xB1`\xF7\x9FZ\xF7=|\xA6\x82" 400 150 "-" "-" 0 0.494 [] [] - - - - 83a6709f7eaa820c4f9829979de617a4
195.154.69.132 - - [21/Jan/2021:12:56:23 +0000] "CONNECT ip.ws.126.net:443 HTTP/1.1" 400 150 "-" "-" 0 0.913 [] [] - - - - 1ddfb9204b6efa687d05a138f213bef2
222.186.136.150 - - [21/Jan/2021:13:15:16 +0000] "CONNECT ip.ws.126.net:443 HTTP/1.1" 400 150 "-" "-" 0 0.257 [] [] - - - - 87c08e487d0c9a7e786685c8dd1a589b
64.227.97.195 - - [21/Jan/2021:13:18:32 +0000] "\x00\x0E8\x97\xAB\xB2\xBB\xBA\xB1\x1D\x90\x00\x00\x00\x00\x00" 400 150 "-" "-" 0 0.152 [] [] - - - - 4d89d6868e909990414d125fe5e3862d
167.71.102.181 - - [21/Jan/2021:13:19:52 +0000] "\x00\x0E8f:d5\xBE\xC3\xBC_\x00\x00\x00\x00\x00" 400 150 "-" "-" 0 0.086 [] [] - - - - efbe674f606c5bf20e6903da0ae39855
I0121 14:15:35.862702 6 controller.go:144] "Configuration changes detected, backend reload required"
I0121 14:15:35.865621 6 event.go:282] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"maorie-ingress-lb", UID:"a5ad31d8-c913-4139-a721-2a5c0f7119d3", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"5627714245", FieldPath:""}): type: 'Normal' reason: 'Sync' Scheduled for sync
I0121 14:15:36.262759 6 controller.go:161] "Backend successfully reloaded"
I0121 14:15:36.265762 6 event.go:282] Event(v1.ObjectReference{Kind:"Pod", Namespace:"kube-system", Name:"nginx-ingress-29787", UID:"07845f40-87d4-40ce-83d1-01a3d37011c1", APIVersion:"v1", ResourceVersion:"4834374834", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
As said in the comments, I finally realised the nginx configmap was not needed, as the docker image embedded an nginx on its own.
Removing the configmap instructions in deployment.yaml did the trick !