Docker POD+;库伯内特服务悬停蝇

Docker POD+;库伯内特服务悬停蝇,docker,kubernetes,hoverfly,Docker,Kubernetes,Hoverfly,我正在尝试在k8s群集上部署此配置: apiVersion: v1 kind: ConfigMap metadata: name: simulations-test labels: mock-services: "true" data: simulations-test.json: | { "data":{ "pairs":[ { "request":{

我正在尝试在k8s群集上部署此配置:

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"
当我运行此命令时:

kubectl apply -f mock-service.yaml -n mock
结果:

configmap/simulations-test created
pod/test-mock created
service/test-mock-service created
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
但是,当我试图访问服务,甚至在吊舱内,我得到连接拒绝

在吊舱里,我跑:

/ # 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
我还尝试进行部署,结果也是一样的

TKS

更新#1

当我尝试进行端口转发时,它会起作用:

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

configmap/simulations-test created
pod/test-mock created
service/test-mock-service created
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

由于您在服务中有
targetPort:8500
,pod内的容器需要监听端口
8500

服务中的标签是
mock service:test
,但pod中的标签是
mock services:true
。他们需要匹配

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

还要确保应用程序正在0.0.0.0上监听。而不是127.0.0.1

因为服务中有
targetPort:8500
,所以吊舱内的容器需要监听端口
8500

服务中的标签是
mock service:test
,但pod中的标签是
mock services:true
。他们需要匹配

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

还要确保应用程序正在0.0.0.0上监听。而不是127.0.0.1

配置与您描述的相同。我应该设置错误的配置。所以,我得到了同样的结果。任何其他建议?确保应用程序正在0.0.0.0上侦听。而不是127.0.0.1它工作了!!Tks@ArghyaSadhu!我在hoverfly上重写了默认命令:默认命令是/bin/hoverfly-listenon-host=0.0.0.0,我把/bin/hoverfly-webserver-import/simulations/simulations-test.json放在主机上,忘记了-listen-on-host=0.0.0.0。最后一个命令是:/bin/hoverfly-webserver-import/simulations/simulations-test.json-listenonhost=0.0.0。又来了!!!配置与您描述的一样。我应该设置错误的配置。所以,我得到了同样的结果。任何其他建议?确保应用程序正在0.0.0.0上侦听。而不是127.0.0.1它工作了!!Tks@ArghyaSadhu!我在hoverfly上重写了默认命令:默认命令是/bin/hoverfly-listenon-host=0.0.0.0,我把/bin/hoverfly-webserver-import/simulations/simulations-test.json放在主机上,忘记了-listen-on-host=0.0.0.0。最后一个命令是:/bin/hoverfly-webserver-import/simulations/simulations-test.json-listenonhost=0.0.0。又来了!!!
netstat
输出表明容器中的程序仅在侦听容器专用localhost接口。通常,在容器中运行的程序需要监听0.0.0.0“所有接口”。容器是否在普通Docker中的Kubernetes外部运行?能否显示设置侦听器的应用程序代码?
netstat
输出表明容器中的程序仅在容器专用localhost接口上侦听。通常,在容器中运行的程序需要监听0.0.0.0“所有接口”。容器是否在普通Docker中的Kubernetes外部运行?您能否显示设置侦听器的应用程序代码?