【问题标题】:No access to k8s pod by internal IP from the envtest来自 envtest 的内部 IP 无法访问 k8s pod
【发布时间】:2021-01-15 16:29:08
【问题描述】:

我使用 envtest 和本地 Minikube 集群为我的 Kubernetes 操作员编写了一个集成测试。

我正在测试的控制器正在通过 IP 地址向其中一个 pod 发出 http 请求。 我得到的地址是这样的:

endpoints := &corev1.Endpoints{}
client.Get(context.TODO(), types.NamespacedName{Namespace: "ns", Name: "cluster"}, endpoints)
url = fmt.Sprintf("%s:%s", endpoints.Subsets[0].Addresses[0].IP, "8081")

如果我将 operator 部署到 Kubernetes 集群,则此代码有效。

但是在运行测试时出现错误:

Post \"http://172.17.0.3:8081": dial tcp 172.17.0.3:8081: connect: no route to host

这是因为之前 http 调用是从 pod 与 operator 进行的,但现在是从 envtest 进行的?

如何正确编写控制器测试?

【问题讨论】:

    标签: testing kubernetes devops kubernetes-operator kubernetes-networking


    【解决方案1】:

    我的解决方法:

    我使用 this 示例将端口转发到目标 pod。

    要让代码转到localhost,我会稍微修补一下。

    【讨论】:

      猜你喜欢
      • 2018-02-26
      • 1970-01-01
      • 2019-09-16
      • 2020-11-16
      • 2020-05-30
      • 2020-03-08
      • 2021-07-01
      • 2019-05-11
      • 2021-11-19
      相关资源
      最近更新 更多