无法从任何地方访问 Minikube 服务

Minikube Service Not Reachable From Anywhere

所以我在 Whosebug 上阅读了很多类似的 questions/issues 并且我理解得足够多但不确定我错过了什么。

deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: dev-namespace
  labels:
    web: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      web: nginx
  template:
    metadata:
      labels:
        web: nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 8080

service.yml

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: NodePort
  selector:
    web: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

这是我的 minikube ip:

$ minikube ip
192.168.49.2

这是服务

$ kubectl get service
NAME            TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
nginx-service   NodePort   10.104.139.228   <none>        80:30360/TCP   14

这是部署

$ kubectl get deployments.apps
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   2/2     2            2           14h

这是pods

$ kubectl get pods -o wide
NAME                                READY   STATUS    RESTARTS   AGE   IP           NODE       NOMINATED NODE   READINESS GATES
nginx-deployment-5b78696cc8-9fpmr   1/1     Running   0          14h   172.17.0.6   minikube   <none>           <none>
nginx-deployment-5b78696cc8-h4m72   1/1     Running   0          14h   172.17.0.4   minikube   <none>           <none>

这是端点

$ kubectl get endpoints
NAME            ENDPOINTS                         AGE
nginx-service   172.17.0.4:8080,172.17.0.6:8080   14h

但是当我尝试 curl 10.104.139.228:30360 它只是挂起。当我尝试 curl 192.168.49.2:30360 我得到 Connection refused

我确定使用 NodePort 意味着我需要使用 node ip,那将是服务器的本地 IP,因为我是使用 minikubecontrol planeworker 在同一台服务器上。

我在这里错过了什么?请帮助,这让我发疯。我应该提到我能够 kubectl exec -ti pod-name -- /bin/bash 并且如果我执行 curl localhost 我确实得到了著名的回应“欢迎使用 NGINX”

没关系:/我觉得很愚蠢,我看到错误是容器端口:/我的 nginx pods 正在侦听端口 80 而不是端口 8080

对于那里的任何人,我将我的配置文件更新为:

service.yml

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: busy-qa
spec:
  type: NodePort
  selector:
    web: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: busy-qa
  labels:
    web: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      web: nginx
  template:
    metadata:
      labels:
        web: nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80

现在,当我 curl 时,我得到了 NGINX 响应

$ curl 192.168.49.2:31168
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>