外部流量是否可以访问我在 Minikube 中的部署?

Is it possible for outside traffic to access my deployment inside Minikube?

这里是 Kubernetes 新手。只是想让我的基本理解正确。 Minikube 以本地开发而闻名,外部连接(不仅仅是集群外部)是否可以访问我在 minikube 中部署的 pods?

我是 运行 我在 ec2 实例中的 minikube,所以我用命令 minikube start --vm-driver=none 启动了我的 minikube,这意味着 运行 带有 Docker 的 minikube,没有配置 VM。我的最终目标是允许外部连接到达我在集群内的 pods 并通过 pod 执行 POST 请求(例如使用 Postman)。

If yes, I also have my service resource applied using kubectl apply -f into my minikube using NodePort in yaml file. Also, I also wish to understand port, nodePort, and targetPort correctly. port is the port number assigned to that particular service, nodePort is the port number on the node (in my case is my ec2 instance private IP), targetPort is the port number equivalent to the containerPort I've assigned in yaml of my deployment. Correct me if I am wrong in this statement.

谢谢。

是的,你可以做到

因为你已经启动了 minikube:

minikube start --vm-driver=none

nodePort 是集群外的客户端将 "see" 的端口。 nodePort 通过 kube-proxy 在集群中的每个节点上打开。您可以使用 nodePort 从外界访问应用程序。喜欢https://loadbalancerIP:NodePort

port 是您的服务在集群内侦听的端口。让我们举个例子:

apiVersion: v1
kind: Service
metadata:
  name: test-service
spec:
  ports:
  - port: 8080
    targetPort: 8070
    nodePort: 31222
    protocol: TCP 
  selector:
    component: test-service-app

从 k8s 集群内部可以通过 http://test-service.default.svc.cluster.local:8080(集群内部的服务到服务通信)访问此服务,到达那里的任何请求都将转发到 targetPort 8070 上的 运行 pod。

如果没有另外指定,

tagetPort 也默认与端口值相同。