Kubernetes version: 1.16
Cloud being used: bare-metal
Installation method: Docker for Mac
Host OS: macOS 10.14.6
CNI and version: v0.7.5
CRI and version: v1.14.0
I’m kind of stumped as to how to expose the back-end to something like Postman. I just keep getting “Could not get any response” from localhost:5000
and about 20 other URLs I’ve tried in Postman, despite the deployment running when I check kubectl
.
docker run -p 5000:5000 exampleapp/server
Runs just fine in that the server responds with "Hello World!"
when I fetch localhost:5000
from Postman.
With k8s, not so much.
These are various configs:
ingress-service.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: localhost
http:
paths:
- path: /?(.*)
backend:
serviceName: server-cluster-ip-service
servicePort: 5000
server-cluster-ip-service.yaml
apiVersion: v1
kind: Service
metadata:
name: server-cluster-ip-service
spec:
type: ClusterIP
selector:
component: server
ports:
- port: 5000
targetPort: 5000
server-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: server-deployment
spec:
replicas: 3
selector:
matchLabels:
component: server
template:
metadata:
labels:
component: server
spec:
containers:
- name: server
image: exampleapp/server
ports:
- containerPort: 5000
Dockerfile
FROM node:12.10-alpine
WORKDIR "/app"
COPY ./package.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]
index.js
const express = require('express');
// Set the ExpressJS application
const app = express();
// Set the listening port
// Web front-end is running on port 3000
const port = 5000;
// Set root route
app.get('/', (req, res) => res.send('Hello World!'));
// Listen on the port
app.listen(port, () => console.log(`Example app listening on port ${port}`));