目标

目标

我是 k8s/minikube 的新手(某种程度上,也熟悉 unix 网络),所以如果我问了一些似乎没有意义的问题,我会很乐意澄清!

目标

我想要配置基于端口的 TCP 入口,如nginx-ingress 文档。特别是我想使用webpack-dev-server来自内部的minikube

错误

当按照我的最佳理解进行设置时,我Failed to load resource: net::ERR_CONNECTION_REFUSED在请求时仍然会得到结果local.web:3001/client.js。也就是说,在浏览器中导航到“local.web/”会显示页面,但没有要webpack生成的包。该请求失败。

配置

从主机迁移到 minikube pod,我已经

在 /etc/hosts 中:

在我的开发机器上,我设置local.web为 minikube IP

$ echo "$(minikube ip) local.web" | sudo tee -a /etc/hosts

入口:

{
  "kind": "Ingress",
  "apiVersion": "extensions/v1beta1",
  "metadata": {
    "name": "dev-web-ingress",
    "namespace": "dev",
    "selfLink": "/apis/extensions/v1beta1/namespaces/dev/ingresses/dev-web-ingress",
    "uid": "64ebfc93-612e-11e9-8df7-0800270e7244",
    "resourceVersion": "280750",
    "generation": 3,
    "creationTimestamp": "2019-04-17T16:32:30Z",
    "labels": {
      "platform": "advocate",
      "tier": "frontend"
    },
    "annotations": {
      "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"extensions/v1beta1\",\"kind\":\"Ingress\",\"metadata\":{\"annotations\":{\"kubernetes.io/ingress.class\":\"nginx\"},\"labels\":{\"platform\":\"advocate\",\"tier\":\"frontend\"},\"name\":\"dev-web-ingress\",\"namespace\":\"dev\"},\"spec\":{\"rules\":[{\"host\":\"local.web\",\"http\":{\"paths\":[{\"backend\":{\"serviceName\":\"dev-adv-web-service\",\"servicePort\":\"http\"},\"path\":\"/\"}]}}]}}\n",
      "kubernetes.io/ingress.class": "nginx"
    }
  },
  "spec": {
    "rules": [
      {
        "host": "local.web",
        "http": {
          "paths": [
            {
              "path": "/",
              "backend": {
                "serviceName": "dev-adv-web-service",
                "servicePort": "http"
              }
            }
          ]
        }
      }
    ]
  },
  "status": {
    "loadBalancer": {
      "ingress": [
        {
          "ip": "10.0.2.15"
        }
      ]
    }
  }
}

TCP 服务

{
  "kind": "ConfigMap",
  "apiVersion": "v1",
  "metadata": {
    "name": "tcp-services",
    "namespace": "dev",
    "selfLink": "/api/v1/namespaces/dev/configmaps/tcp-services",
    "uid": "5e456f3e-622e-11e9-bcf8-0800270e7244",
    "resourceVersion": "295220",
    "creationTimestamp": "2019-04-18T23:04:50Z",
    "annotations": {
      "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"data\":{\"3001\":\"dev/dev-adv-web-service:3001\",\"9290\":\"dev/dev-echoserver:8080\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"tcp-services\",\"namespace\":\"dev\"}}\n"
    }
  },
  "data": {
    "3001": "dev/dev-adv-web-service:3001",
  }
}

服务:

{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "dev-adv-web-service",
    "namespace": "dev",
    "selfLink": "/api/v1/namespaces/dev/services/dev-adv-web-service",
    "uid": "64e3c65d-612e-11e9-8df7-0800270e7244",
    "resourceVersion": "280675",
    "creationTimestamp": "2019-04-17T16:32:30Z",
    "labels": {
      "app": "adv-web",
      "tier": "frontend"
    },
    "annotations": [... edited for clarity]
  },
  "spec": {
    "ports": [
      {
        "name": "http",
        "protocol": "TCP",
        "port": 80,
        "targetPort": 3000,
        "nodePort": 31246
      },
      {
        "name": "http2",
        "protocol": "TCP",
        "port": 3001,
        "targetPort": 3001,
        "nodePort": 31392
      }
    ],
    "selector": {
      "app": "frontend-container",
      "tier": "frontend"
    },
    "clusterIP": "10.108.24.80",
    "type": "LoadBalancer",
    "sessionAffinity": "None",
    "externalTrafficPolicy": "Cluster"
  },
  "status": {
    "loadBalancer": {}
  }
}

{
  "kind": "Pod",
  "apiVersion": "v1",
  "metadata": {
    "name": "dev-adv-web-768767454f-wxvnh",
    "generateName": "dev-adv-web-768767454f-",
    "namespace": "dev",
    "selfLink": "/api/v1/namespaces/dev/pods/dev-adv-web-768767454f-wxvnh",
    "uid": "65de844e-622c-11e9-bcf8-0800270e7244",
    "resourceVersion": "294073",
    "creationTimestamp": "2019-04-18T22:50:43Z",
    "labels": {
      "app": "frontend-container",
      "pod-template-hash": "768767454f",
      "tier": "frontend"
    },
    "ownerReferences": [
      {
        "apiVersion": "apps/v1",
        "kind": "ReplicaSet",
        "name": "dev-adv-web-768767454f",
        "uid": "4babd3e7-613d-11e9-8df7-0800270e7244",
        "controller": true,
        "blockOwnerDeletion": true
      }
    ]
  },
  "spec": {
    "volumes": [
      {
        "name": "frontend-repo",
        "hostPath": {
          "path": "/Users/me/Projects/code/frontend",
          "type": ""
        }
      },
      {
        "name": "default-token-7rfht",
        "secret": {
          "secretName": "default-token-7rfht",
          "defaultMode": 420
        }
      }
    ],
    "containers": [
      {
        "name": "adv-web-container",
        "image": "localhost:5000/react:dev",
        "command": [
          "npm",
          "run",
          "dev"
        ],
        "ports": [
          {
            "name": "http",
            "containerPort": 3000,
            "protocol": "TCP"
          },
          {
            "name": "http2",
            "containerPort": 3001,
            "protocol": "TCP"
          }
        ],
        "env": [
          {
            "name": "HOSTNAME_PUBLISHED",
            "valueFrom": {
              "configMapKeyRef": {
                "name": "dev-frontend-configmap",
                "key": "HOSTNAME_PUBLISHED"
              }
            }
          },
          {
            "name": "LOCAL_DOMAIN",
            "valueFrom": {
              "configMapKeyRef": {
                "name": "dev-frontend-configmap",
                "key": "LOCAL_DOMAIN"
              }
            }
          },
          {
            "name": "HOST",
            "valueFrom": {
              "configMapKeyRef": {
                "name": "dev-frontend-configmap",
                "key": "HOST"
              }
            }
          },
          {
            "name": "WEBPACK_PUBLISHED_PORT",
            "valueFrom": {
              "configMapKeyRef": {
                "name": "dev-frontend-configmap",
                "key": "WEBPACK_PUBLISHED_PORT"
              }
            }
          },
          {
            "name": "WEBPACK_LISTEN_PORT",
            "valueFrom": {
              "configMapKeyRef": {
                "name": "dev-frontend-configmap",
                "key": "WEBPACK_LISTEN_PORT"
              }
            }
          },
          {
            "name": "API_URL",
            "valueFrom": {
              "configMapKeyRef": {
                "name": "dev-frontend-configmap",
                "key": "API_URL"
              }
            }
          },
          {
            "name": "LOGIN_CALLBACK_URL",
            "valueFrom": {
              "configMapKeyRef": {
                "name": "dev-frontend-configmap",
                "key": "LOGIN_CALLBACK_URL"
              }
            }
          },
          {
            "name": "NPM_CONFIG_LOGLEVEL",
            "valueFrom": {
              "configMapKeyRef": {
                "name": "dev-frontend-configmap",
                "key": "NPM_CONFIG_LOGLEVEL"
              }
            }
          }
        ],
        "resources": {},
        "volumeMounts": [
          {
            "name": "frontend-repo",
            "mountPath": "/code"
          },
          {
            "name": "default-token-7rfht",
            "readOnly": true,
            "mountPath": "/var/run/secrets/kubernetes.io/serviceaccount"
          }
        ],
        "terminationMessagePath": "/dev/termination-log",
        "terminationMessagePolicy": "File",
        "imagePullPolicy": "Always"
      }
    ],
    "restartPolicy": "Always",
    "terminationGracePeriodSeconds": 30,
    "dnsPolicy": "ClusterFirst",
    "serviceAccountName": "default",
    "serviceAccount": "default",
    "nodeName": "minikube",
    "securityContext": {},
    "schedulerName": "default-scheduler",
    "tolerations": [
      {
        "key": "node.kubernetes.io/not-ready",
        "operator": "Exists",
        "effect": "NoExecute",
        "tolerationSeconds": 300
      },
      {
        "key": "node.kubernetes.io/unreachable",
        "operator": "Exists",
        "effect": "NoExecute",
        "tolerationSeconds": 300
      }
    ],
    "priority": 0,
    "enableServiceLinks": true
  },
  "status": {
    "phase": "Running",
    "conditions": [
      {
        "type": "Initialized",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2019-04-18T22:50:43Z"
      },
      {
        "type": "Ready",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2019-04-18T22:50:45Z"
      },
      {
        "type": "ContainersReady",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2019-04-18T22:50:45Z"
      },
      {
        "type": "PodScheduled",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2019-04-18T22:50:43Z"
      }
    ],
    "hostIP": "10.0.2.15",
    "podIP": "172.17.0.13",
    "startTime": "2019-04-18T22:50:43Z",
    "containerStatuses": [
      {
        "name": "adv-web-container",
        "state": {
          "running": {
            "startedAt": "2019-04-18T22:50:44Z"
          }
        },
        "lastState": {},
        "ready": true,
        "restartCount": 0,
        "image": "localhost:5000/react:dev",
        "imageID": "docker-pullable://localhost:5000/react@sha256:2bfe61ed134044bff4b23f5c057af2f9c480c3c1a1927a485f09f3410528903d",
        "containerID": "docker://57b9b6dafaf2aba8a21d5dd7db3543f4742c00331b49b48dc1561e3b5bd05315"
      }
    ],
    "qosClass": "BestEffort"
  }
}

假设

一个想法是 TCP 服务上的命名空间ConfigMap错误。从文档中我不清楚它应该放在哪里。我已在命名空间中尝试过dev,其中有入口、服务和部署/pod。我还尝试将data上述条目添加到tcp-services ConfigMapin 中kube-system

webpack pod 的日志没有显示任何错误,所以我不相信问题出在应用程序层面。

由于GET local.web/正在从 pod 返回数据,我确信该服务至少是部分正确的。

我愿意执行您建议的任何调试,并且不幻想我知道正在发生的事情——我会感激您提供的任何帮助。

相关内容