我已经阅读了很多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/

10-16 05:51