Home > Blockchain >  Accessing an Endpoint in a Kubernetes Pod but get connection error
Accessing an Endpoint in a Kubernetes Pod but get connection error

Time:05-22

I'm learning microservice with docker and k8s. This project is a simple node.js express app and I tried to add a reverse proxy in it. I already pushed the image (both the express app as well as the reverse proxy) to my docker hub.

Now I encounter a problem when I tried to access an endpoint in my pods. My pod is running, and when I tried the endpoint:

curl:curl http://my-app-2-svc:8080/api/health

I get connection refused, I'm wondering what' wrong with that?

It seems that there are some problem with the liveness probe.. When I describe the pods: it shows:

Liveness probe failed: Get "http://192.168.55.232:8080/health": dial tcp 192.168.55.232:8080: connect: connection refused

enter image description here

Here is my github link for this project: https://github.com/floatingstarlight/Microservice

Can anyone helps me with that? Thanks!

CodePudding user response:

...
livenessProbe:
  httpGet:
    path: /health
    port: 8080
...

If you asked for liveness probe, you need to implement it or your pod will be seen as a failure and restart every now and then. You can update your server.js to the minimum as follow to get up and running:

const express = require('express')
const app = express()
const port = 8080

app.get('/health', (req, res) => {
  res.send('ok')
})

app.listen(port, () => {
  console.log(`Listening on port ${port}`)
})
  • Related