I have created 2 services and for each of the service there is a corresponding deployment. All these are in the same PC. After applying the YAML, the services and deployments are running properly.
sudo npm kubectl apply -f deployment.yaml
Now, if I try to curl to the ingress IP address, then I get 404 page not found as the response.
sudo kubectl get ingress -o wide
sudo curl <IP address of ingress>
If I try to curl to the IP address of the employee service or employee deployment, it gives that the connection was refused after waiting for sometime. Which ever port I mentioned for the employee service and deployment I try, I always get error instead of the proper response.
Can someone from the community please assist. I need to call the /emplist endpoint of myshop pod from employee pod.
myshop.js
const express = require('express')
const app = express()
const port = 3000
app.get('/emplist', (req, res) => {
res.status(200).send( empListObj )
});
app.listen(port, '0.0.0.0', () => {
console.log(`Listening on port ${port}`)
})
employee.js
const axios = require('axios').default;
const express = require('express')
const app = express()
const port = 3001
app.get('/', (req, res) => {
axios({
method: 'get',
url: 'http://myshopservice/emplist'
})
.then(function (response) {
res.status(200).send(response.data.empList)
})
.catch(function (error) {
res.status(200).send(`Error because ${error}`);
})
})
app.listen(port, '0.0.0.0', () => {
console.log(`Listening on port ${port}`)
})
Now the corresponding deployment.yaml is:
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myshop-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: myshop.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: myshopservice
port:
number: 4000
---
apiVersion: v1
kind: Service
metadata:
name: myshopservice
spec:
selector:
app: myshop
ports:
- protocol: "TCP"
port: 4000
targetPort: 3000
nodePort: 30000
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: myshop
spec:
replicas: 1
selector:
matchLabels:
app: myshop
template:
metadata:
labels:
app: myshop
spec:
containers:
- name: myshop
image: mydockerhubid/myshop:1
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: employeeservice
spec:
selector:
app: employee
ports:
- protocol: "TCP"
port: 4001
targetPort: 3001
nodePort: 30001
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: employee
spec:
replicas: 1
selector:
matchLabels:
app: employee
template:
metadata:
labels:
app: employee
spec:
containers:
- name: hud
image: mydockerhubid/employee:1
ports:
- containerPort: 3001
---