简体   繁体   English

POD + 服务 Kubernetes Hoverfly

[英]POD + Service Kubernetes Hoverfly

I am trying to deploy this configuration on a k8s cluster:我正在尝试在 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"

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!但是,当我尝试使用http://test-mock-service.mock.svc.cluster.local:8500/b2io60000082访问该服务时,即使在 POD 内部,连接也被拒绝!

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! TKS!

UPDATE #1更新#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

Since you have targetPort: 8500 in the service the container inside the pod need to listen on port 8500 .由于您在服务中有targetPort: 8500 ,因此 pod 内的容器需要侦听端口8500

The label in service is mock-service: test but in pod mock-services: true .服务中的 label 是mock-service: test但在 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.还要确保应用程序正在监听 0.0.0.0。 instead of 127.0.0.1而不是 127.0.0.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kubernetes 中 NodePort 类型服务的 Pod 到 Pod 通信 - Pod to Pod communication for a NodePort type service in kubernetes Kubernetes env 引用一个 pod/service - Kubernetes env referencing a pod/service 在未就绪的状态下保持Kubernetes Pod处于服务状态 - Keep a Kubernetes Pod in service when in a state of not ready 通过 kubernetes 集群中的服务公开 kubernetes pod - Exposing a kubernetes pod via service in kind kubernetes cluster 如何通过 Kubernetes 中的另一个 pod 访问部署在一个 pod 上的服务? - How to access the service deployed on one pod via another pod in Kubernetes? Kubernetes pod 无法访问在另一个节点上运行的服务 - Kubernetes pod cannot access service which is running on another node 如何使用Azure容器服务将Kubernetes pod公开到公共Internet - How to expose the Kubernetes pod to the public internet using Azure container service Kubernetes POD参数未传递给服务,但是Docker参数正确传递 - Kubernetes POD arguments are not passing to service, however Docker arguments are passing correctly 无法使用 NodePort 服务连接到 kubernetes 中的 redis pod - Not able to connect to redis pod in kubernetes using NodePort service 使用kubernetes pod中的服务帐户从NFS挂载访问文件 - Access files from NFS mount with service account in kubernetes pod
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM