This is my first time using Docker, Kubernetes, Ingress and Skaffold. I'm following along with a online course, but I'm stuck.
When I call just the home path /
it returns a response, but any other path that I try returns 404.
The first step I took was to add a custom local development url in /etc/hosts/ so in that file I've added 127.0.0.1 ticketing.com
.
Then I have my ingress file. I set host
to match ticketing.com and the path uses a regex to match any path after /api/users
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: ticketing.com
http:
paths:
- path: /api/users/?(.*)
pathType: Prefix
backend:
service:
name: auth-srv
port:
number: 3000
This is the file that has the deploy and service yaml for what is going to be an authentication service. In the second part, it looks like the metadata: name
matches auth-srv
correctly and port 3000
correctly.
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-depl
spec:
replicas: 1
selector:
matchLabels:
app: auth
template:
metadata:
labels:
app: auth
spec:
containers:
- name: auth
image: lmsankey/auth
---
apiVersion: v1
kind: Service
metadata:
name: auth-srv
spec:
selector:
app: auth
ports:
- name: auth
protocol: TCP
port: 3000
targetPort: 3000
If this helps, here is index.ts with the route.
import express from "express";
import { json } from "body-parser";
const app = express();
app.use(json());
app.get("/api/users/currentuser", (req, res) => {
res.send("Hi there!");
});
app.listen(3000, () => {
console.log("Listening on port 3000!!!!!!!!");
});
I tried following this answer https://stackoverflow.com/a/52029100/3692615 but honestly I'm not sure I understood entirely, or if that's what I need.
Basically it says to add this line to annotations. nginx.ingress.kubernetes.io/rewrite-target: /
Maybe someone more experienced can spot whats going on or point me in the right direction?
Thanks.