docker - 无法连接到主机中的minikube服务

标签 docker kubernetes minikube

我已经阅读了很多stackoverflow帖子,但都没有工作...所以这是我的问题:
我在端口0.0.0.0上的广播5000上运行了一个简单的节点应用程序,在/处有一个简单的单个端点。
我有两个k8s对象,这是我的Deployment对象:


### pf deployment
apiVersion: apps/v1
kind: Deployment
metadata:
    # Unique key of the Deployment instance
    name: pf-deployment
spec:
    # 3 Pods should exist at all times.
    replicas: 1
    selector:
        matchLabels:
            app: public-facing
    template:
        metadata:
            labels:
                # Apply this label to pods and default
                # the Deployment label selector to this value
                app: public-facing
        spec:
            containers:
                - name: public-facing
                  # Run this image
                  image: pf:ale8k
                  ports:
                    - containerPort: 5000
接下来,这是我的Service对象:
### pf service
apiVersion: v1
kind: Service
metadata:
  name: pf-service
  labels:
    run: pf-service-label
spec:
  type: NodePort ### may be ommited as it is a default type
  selector:
    name: public-facing ### should match your labels defined for your angular pods
  ports:
    - protocol: TCP
      targetPort: 5000 ### port your app listens on
      port: 5000 ### port on which you want to expose it within your cluster
最后,一个非常简单的dockerfile:
### generic docker file
FROM node:12

WORKDIR /usr/src/app

COPY . .

RUN npm i

EXPOSE 5000

CMD ["npm", "run", "start"]
我的镜像在minikubes本地docker注册表中,所以这不是问题...
当我尝试时:curl $(minikube service pf-service --url)我得到:curl: (7) Failed to connect to 192.168.99.101 port 31753: Connection refused当我尝试时:minikube service pf-service我得到一些进一步的输出:
Most likely you need to configure your SUID sandbox correctly
我正在运行hello-minikube图像,这工作得很好。所以我想这不是我的鼻涕吗?
我对kubernetes非常陌生,因此如果很简单,请提前道歉。
谢谢!

最佳答案

服务具有选择器name: public-facing,但pod具有标签app: public-facing。对于要使用Pod IP填充的服务的Endpoints,它们必须相同。
如果执行以下命令

kubectl describe svc pf-service
您会看到Endpoints没有IP,这是connection refused错误的原因。
如下更改服务中的选择器以使其起作用。
### pf service
apiVersion: v1
kind: Service
metadata:
  name: pf-service
  labels:
    run: pf-service-label
spec:
  type: NodePort ### may be ommited as it is a default type
  selector:
    app: public-facing ### should match your labels defined for your angular pods
  ports:
    - protocol: TCP
      targetPort: 5000 ### port your app listens on
      port: 5000 ### port on which you want to expose it within your cluster

关于docker - 无法连接到主机中的minikube服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63341648/

相关文章:

kubernetes - 如何连接到Kubernetes集群中的kafka实例?

macos - 在Mac OS X和Tiller上安装Helm 2.9

docker - 无法从群集内通过Pod IP访问Pod,从而导致事件/就绪探针失败

node.js - Docker 和 Nginx 解析错误的 IP 地址

docker - 在 grafana 中配置多个数据源

ssh - 有没有办法从我的本地开发环境访问远程服务器上正在运行的docker容器(Sublime)

mysql - 我无法用 solr 索引我的数据库。我总是得到 `Indexing failed. Rolled back all changes.`

kubernetes - Prometheus 的 http_request 自定义指标在 Kubernetes 中不起作用

Kubernetes Dashboard v1.8.3 部署

kubernetes - 根据环境调整 Kubernetes 配置