This is my eks cluster details: kubectl get all
NAME READY STATUS RESTARTS AGE
pod/feed-4fqdrrf-fwcc3 1/1 Running 0 64m
pod/gst-7adn3njl-fg43 1/1 Running 0 71m
pod/ingress-nginx-controller-f567efvef-f653dc 1/1 Running 0 9d
pod/app-24dfs2d-m2fdqw 1/1 Running 0 66m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/feed NodePort 10.100.24.643 <none> 8082:30002/TCP 64m
service/gst NodePort 10.100.54.543 <none> 8081:30004/TCP 71m
service/ingress-nginx-controller LoadBalancer 10.100.643.256 ******************.<region>.elb.amazonaws.com 80:30622/TCP,443:30721/TCP 9d
service/ingress-nginx-controller-admission ClusterIP 10.100.654.542 <none> 443/TCP 9d
service/kubernetes ClusterIP 10.100.0.7 <none> 443/TCP 14d
service/app NodePort 10.100.456.34 <none> 3001:30003/TCP 66m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/feed 1/1 1 1 64m
deployment.apps/gst 1/1 1 1 71m
deployment.apps/ingress-nginx-controller 1/1 1 1 9d
deployment.apps/app 1/1 1 1 66m
NAME DESIRED CURRENT READY AGE
replicaset.apps/feed-4fqdrrf 1 1 1 64m
replicaset.apps/gst-7adn3njl 1 1 1 71m
replicaset.apps/ingress-nginx-controller-f567efvef 1 1 1 9d
replicaset.apps/app-m2fdqw 1 1 1 66m
kubectl logs feed-4fqdrrf-fwcc3
helloworld: listening on port 8082
~ % kubectl logs gst-7adn3njl-fg43
helloworld: listening on port 8081
~ % kubectl logs app-24dfs2d-m2fdqw
helloworld: listening on port 3001
these are my deployment and service yamls:
apiVersion: apps/v1
kind: Deployment
metadata:
name: feed
labels:
app: feed
spec:
selector:
matchLabels:
app: feed
template:
metadata:
labels:
app: feed
spec:
containers:
- name: feed-container
image: **************.dkr.ecr.******.amazonaws.com/feed:latest
ports:
- containerPort: 8082
---
apiVersion: v1
kind: Service
metadata:
name: feed
spec:
ports:
- port: 8082
protocol: TCP
targetPort: 8082
selector:
app: feed
type: NodePort
Similar for other 2 services and this is my ingress yaml:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/enable-websocket: "true"
nginx.org/websocket-services: app
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /feed
pathType: Prefix
backend:
service:
name: expertfeed
port:
number: 8082
- path: /app
pathType: Prefix
backend:
service:
name: wehealapp
port:
number: 3001
- path: /socket.io/app
pathType: Prefix
backend:
service:
name: app
port:
number: 3001
- path: /gst
pathType: Prefix
backend:
service:
name: gst
port:
number: 8001
I have multiple get request in all 3 services and I have exposed them like this:
app.get('/getrequest1', jsonParser, async (request, response) => {
//my code
)}
app.get('/getrequest2', jsonParser, async (request, response) => {
//my code
)}
.
.
.
const port = process.env.PORT || 8082;
app.listen(port, () => {
console.log(`helloworld: listening on port ${port}`);
});
Similar pattern in all 3 node services.
I am getting 404 Not Found nginx when I hit:
******************.elb.amazonaws.com
and when I hit:
******************.elb.amazonaws.com/feed getting this error:Cannot GET /
If I use this url ******************.elb.amazonaws.com/feed/getreqest1 still getting same error
2
Answers
I found one way to do it that I add my nginx load balancer EXTERNAL-IP to my DNS records and add a CNAME record to it. Here is the YAML below:
Because you have set
rewrite-target
annotation on Ingress which forwards the traffics to the roots/
of the applications which do not exist.