0

I am trying to deploy this configuration on a k8s cluster:

apiVersion: v1
kind: ConfigMap
metadata:
  name: simulations-test
  labels: 
    mock-services: "true"
data:
  simulations-test.json: |
    {
      "data":{
          "pairs":[
            {
                "request":{
                  "path":[
                      {
                        "matcher":"glob",
                        "value":"*/b2io60000082"
                      }
                  ]
                },
                "response":{
                  "status":200,
                  "body":"...",
                  "encodedBody":false,
                  "headers":{
                      "Content-Type":[
                        "application/json"
                      ]
                  }
                },
                "templated":false
            },
            {
                "request":{
                  "path":[
                      {
                        "matcher":"glob",
                        "value":"*/b2io60000080"
                      }
                  ]
                },
                "response":{
                  "status":404,
                  "body":"",
                  "encodedBody":false,
                  "headers":{
                      "Content-Type":[
                        "text/plain"
                      ]
                  }
                },
                "templated":false
            }
          ]
      },
      "meta":{
          "schemaVersion":"v5",
          "hoverflyVersion":"v1.0.0"
      }
    }

---

apiVersion: v1
kind: Pod
metadata:
  name: test-mock
  labels:
    mock-services: "test"
spec:
  containers:
  - name: test-mock
    image: spectolabs/hoverfly:latest
    volumeMounts:
    - mountPath: /simulations/
      name: simulations-test
    command: ["hoverfly", "-webserver", "-import", "/simulations/simulations-test.json"]
  volumes:
  - name: simulations-test
    configMap:
      name: simulations-test

---

apiVersion: v1
kind: Service
metadata:
  labels:
  name: test-mock-service
spec:
  ports:
    - name: "admin"
      port: 8888
      protocol: TCP
      targetPort: 8888
    - name: "proxy"
      protocol: TCP
      port: 8500
      targetPort: 8500
  selector:
    mock-service: "test"

When I run this:

kubectl apply -f mock-service.yaml -n mock

Result:

configmap/simulations-test created
pod/test-mock created
service/test-mock-service created

But when I try to access the service with http://test-mock-service.mock.svc.cluster.local:8500/b2io60000082, EVEN INSIDE THE POD, I got connection refused!

Inside the pod I ran:

/ # netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:8500          0.0.0.0:*               LISTEN      1/hoverfly
tcp        0      0 127.0.0.1:8888          0.0.0.0:*               LISTEN      1/hoverfly

I tried also to put in a deployment and I had the same result.

TKS!

UPDATE #1

When I try to do a port-forward, it works:

k port-forward test-mock 8888:8888 8500:8500 -n mock

Result:

Forwarding from 127.0.0.1:8888 -> 8888
Forwarding from [::1]:8888 -> 8888
Forwarding from 127.0.0.1:8500 -> 8500
Forwarding from [::1]:8500 -> 8500
Handling connection for 8500
Handling connection for 8500
  • The `netstat` output suggests the program in the container is only listening on the container-private localhost interface. Generally programs running in containers need to listen on 0.0.0.0 "all interfaces". Does the container run outside of Kubernetes in plain Docker? Can you show the application code that sets up the listener? – David Maze Jun 12 '20 at 20:52

1 Answers1

2

Since you have targetPort: 8500 in the service the container inside the pod need to listen on port 8500.

The label in service is mock-service: test but in pod mock-services: true. They need to match.

apiVersion: v1
kind: Pod
metadata:
  name: test-mock
  labels:
    mock-services: "test"
spec:
  containers:
  - name: test-mock
    image: spectolabs/hoverfly:latest
    ports:
    - containerPort: 8500
    volumeMounts:
    - mountPath: /simulations/
      name: simulations-test
    command: ["hoverfly", "-webserver", "-import", "/simulations/simulations-test.json"]
  volumes:
  - name: simulations-test
    configMap:
      name: simulations-test

Also make sure the app is listening on 0.0.0.0. instead of 127.0.0.1

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
  • The configuration was like you described. I should put the wrong configuration. So, I am getting the same result. Any other sugestion? – Leonardo Guerra Jun 12 '20 at 17:58
  • 1
    make sure the app is listening on 0.0.0.0. instead of 127.0.0.1 – Arghya Sadhu Jun 13 '20 at 03:02
  • It worked!! Tks @ArghyaSadhu! I overwrote the default command on the hoverfly: the default is **/bin/hoverfly -listen-on-host=0.0.0.0** , and I put **/bin/hoverfly -webserver -import /simulations/simulations-test.json**, I forgot the **-listen-on-host=0.0.0.0**. So the final command: **/bin/hoverfly -webserver -import /simulations/simulations-test.json -listen-on-host=0.0.0.0**. Tks again!!! – Leonardo Guerra Jun 13 '20 at 09:02