Kubernetes LoadBalancer Service returning empty response Kubernetes LoadBalancer Service returning empty response kubernetes kubernetes

Kubernetes LoadBalancer Service returning empty response


There are some potential sources of errors here.

First potential problem is that your Docker image does not work as expected. You can try this: Use nginx:latest as your image and try if this works. If this works the Kubernetes parts are working correctly and you can do further investigation on your Docker image.

Your code snippet does not contain any code that outputs some data as far as I can see.

You can experiment with your image by using the docker run command as indicated in the comments above.

If it still does not work with the Nginx image then you have to further investigate the Kubernetes side.

Although a LoadBalancer is a standard Kubernetes service type, its implementation is different for different cloud providers and on-premise installations.

You must consult your Kubernetes or cloud provider's documentation on how to find out if the LoadBalancer is configured correctly.

To see if the service can reach the pods you can use the command kubectl get endpoints.

To do some more debugging you can use the kubectl port-forward command to create a tunnel to either one of the pods or to the service and try the curl command on the established tunnel.

Also you can use the kubectl logs command to see any log output of your pods.


Check any error while creating image ,check if pods were successfully deployed after deployment i.e. they should be in running state and check for service too.if these are conditions are correct than I hardly see any error in you steps.Here is a simple example for nodejs application deployment .

index.js

var http = require('http');var server = http.createServer(function(request, response) {    response.writeHead(200, {"Content-Type": "text/plain"});    response.end("Hello World!");});var port = 80;server.listen(port);console.log("Server running at http://localhost:%d", port);

Docker File:

FROM node:0.10.40RUN mkdir -p /usr/src/appWORKDIR /usr/src/appCOPY ./nodejs-docs-hello-world ./RUN npm installCMD ["node", "index.js"]

web-deployement:

apiVersion: v1kind: ReplicationControllermetadata:  labels:    name: web  name: web-controllerspec:  replicas: 2  template:    metadata:      labels:        name: web    spec:      containers:      - image: imagename        name: web        ports:        - containerPort: 80          name: http-server

web-service:

apiVersion: v1kind: Servicemetadata:  name: web  labels:    name: webspec:  type: LoadBalancer  ports:    - port: 80      targetPort: 80      protocol: TCP  selector:    name: web