提问者:小点点

如何访问部署在minikube k8s集群中的应用程序


我已经安装了minikube,部署了hello-minikube应用程序并打开了端口。基本上我已经按照https://kubernetes.io/docs/setup/learning-environment/minikube/#quickstart.的入门教程

当我想打开部署的应用程序正在运行的URL时,问题就开始了。

我得到了http://172.17.0.7:31198,URI无法打开,因为IP在本地不存在。将其更改为http://localhost:31198也不起作用(所以我想在host文件中添加一个条目是不起作用的)。

应用程序正在运行,我可以通过http://127.0.0.1:50501/api/v1/namespaces/default/services/hello-minikube查询集群并获取信息:

{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "hello-minikube",
    "namespace": "default",
    "selfLink": "/api/v1/namespaces/default/services/hello-minikube",
    "uid": "56845ce6-bbba-45e5-a1b6-d094949438cf",
    "resourceVersion": "1578",
    "creationTimestamp": "2020-03-10T10:33:41Z",
    "labels": {
      "app": "hello-minikube"
    }
  },
  "spec": {
    "ports": [
      {
        "protocol": "TCP",
        "port": 8080,
        "targetPort": 8080,
        "nodePort": 31198
      }
    ],
    "selector": {
      "app": "hello-minikube"
    },
    "clusterIP": "10.108.152.177",
    "type": "NodePort",
    "sessionAffinity": "None",
    "externalTrafficPolicy": "Cluster"
  },
  "status": {
    "loadBalancer": {

    }
  }
}
λ kubectl get services
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
hello-minikube   NodePort    10.108.152.177   <none>        8080:31198/TCP   4h34m
kubernetes       ClusterIP   10.96.0.1        <none>        443/TCP          4h42m

如何在localhost?上访问部署在minikube k8s集群中的应用程序此外,minikube在机器上作为docker容器运行,暴露了以下端口32770:2376 32769:8443 32771:22。


共1个答案

匿名用户

在另一个线程中找到了解决方案-端口转发

kubectl port-forward svc/hello-minikube 31191:8080

第一个端口是您将在机器上(在浏览器中)使用的端口,8080是运行服务时定义的端口。