- node.js express server bound to port 8080
server.listen(8080, () => {
logger.log({
level: 'info',
message: 'Listening on port ' + port
})
})
- Docker image with node.js code + npm modules with port 8080 exposed
FROM node:10-alpine
...
# Expose port
EXPOSE 8080
- Kubernetes deployment of Docker image with containerPort 8080 configured
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment
spec:
selector:
matchLabels:
app: deployment
replicas: 2
template:
metadata:
labels:
app: deployment
spec:
containers:
- name: job-id-20
image: redacted/redacted
command: ["node", "backend/services.js"]
ports:
- name: http-port
containerPort: 8080
imagePullSecrets:
- name: docker-hub-credentials
dnsConfig:
options:
- name: ndots
value: "0"
- Kubernetes service with matching selector to app with targetPort of 8080 and type LoadBalancer
apiVersion: v1
kind: Service
metadata:
name: service
spec:
ports:
- protocol: TCP
targetPort: 8080
port: 8080
selector:
app: deployment
type: LoadBalancer
- Verify load balancer has external IP (I scrubbed it)
$ kubectl --kubeconfig="k8s-1-13-4-do-0-nyc1-1552761372568-kubeconfig.yaml" get service/service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service LoadBalancer 10.245.239.60 1x4.2x9.1x8.x2 8080:30626/TCP 113s
- curl fails with empty response
$ curl --verbose http://1x4.2x9.1x8.x2:8080/
* Trying 1x4.2x9.1x8.x2...
* TCP_NODELAY set
* Connected to 1x4.2x9.1x8.x2 (1x4.2x9.1x8.x2) port 8080 (#0)
> GET / HTTP/1.1
> Host: 1x4.2x9.1x8.x2:8080
> User-Agent: curl/7.54.0
> Accept: */*
>
* Empty reply from server
* Connection #0 to host 1x4.2x9.1x8.x2 left intact
curl: (52) Empty reply from server
I'd expect the traffic to route through to the service to one of the pods/replicas in the deployment. What am I doing wrong?
NodePortand try curling the node ip & port? - dijksterhuisdocker runto run the same image outside of Kubernetes, is it reachable? - David Mazek describe svc servicesee endpoints are attached. Next step,k exec deployment/deployment-somepodhash shto check whetherhttp://localhost:8080is working or not. If none of them are working then it is a network setup issue. Final step, doiptables -t nat -L KUBE-SERVICESto figure out services attached. - Barath