从另一台机器访问 minikube 托管的 k8s 服务

access k8s service hosted by minikube from another machine

我按照说明 (https://www.eclipse.org/che/docs/che-7/installation-guide/installing-che-on-minikube/) 从托管在远程 ubuntu VM 框上的 Minikube 安装 Eclipse:Che;

我安装成功了,

[![在此处输入图片描述][1]][1]

我可以从 ubuntu VM 控制台访问门户:

[![在此处输入图片描述][2]][2]

这里的172.17.0.3其实就是minikube IP;

如何启用对 https://che-che.172.17.0.3.nip.io/dashboard/ 的外部访问?

根据我的阅读和谷歌搜索,似乎 SSH 转发是正确的方法,但我正在努力使其正确。

谢谢!

======更新2020.11.27 =====

$ minikube start --addons=ingress  --memory=8192
$ chectl server:deploy --platform minikube --installer helm
$ kubectl expose deployment che --type=NodePort -n che --port 8080

$ kubectl get svc -n che
NAME               TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)             AGE
che                NodePort    10.109.226.80    <none>        8080:32540/TCP      16h
che-dashboard      ClusterIP   10.105.102.187   <none>        8080/TCP            17h
che-host           ClusterIP   10.106.2.155     <none>        8080/TCP,8087/TCP   17h
devfile-registry   ClusterIP   10.103.124.53    <none>        8080/TCP            17h
plugin-registry    ClusterIP   10.97.131.33     <none>        8080/TCP            17h

$ minikube service  -n che che
|-----------|------|-------------|-------------------------|
| NAMESPACE | NAME | TARGET PORT |           URL           |
|-----------|------|-------------|-------------------------|
| che       | che  |        8080 | http://172.17.0.4:32540 |
|-----------|------|-------------|-------------------------|
  Opening service che/che in default browser...
  http://172.17.0.4:32540

chaoshi@prd-sal-demo01:~$ kubectl port-forward -n che svc/che 9911:8080
Forwarding from 127.0.0.1:9911 -> 8080
Forwarding from [::1]:9911 -> 8080
Handling connection for 9911
Handling connection for 9911
Handling connection for 9911
Handling connection for 9911
Handling connection for 9911

$ curl http://localhost:9911
[![CircleCI](https://circleci.com/gh/eclipse/che-plugin-registry.svg?style=svg)](https://circleci.com/gh/eclipse/che-plugin-registry)
[![Master Build Status](https://ci.centos.org/buildStatus/icon?subject=master&job=devtools-che-plugin-registry-build-master/)](https://ci.centos.org/job/devtools-che-plugin-registry-build-master/)
[![Nightly Build Status](https://ci.centos.org/buildStatus/icon?subject=nightly&job=devtools-che-plugin-registry-nightly/)](https://ci.centos.org/job/devtools-che-plugin-registry-nightly/)
[![Release Build Status](https://ci.centos.org/buildStatus/icon?subject=release&job=devtools-che-plugin-registry-release/)](https://ci.centos.org/job/devtools-che-plugin-registry-release/)
[![Release Preview Build Status](https://ci.centos.org/buildStatus/icon?subject=release-preview&job=devtools-che-plugin-registry-release-preview/)](https://ci.centos.org/job/devtools-che-plugin-registry-release-preview/)


  [1]: https://i.stack.imgur.com/sVZVz.png
  [2]: https://i.stack.imgur.com/JsOOW.png
  [3]: https://i.stack.imgur.com/maoWv.png

首先,您应该创建一个 NodePort 类型的服务,然后该应用程序将在您的 Ubuntu VM 的 IP 和 NodePort 服务配置中提供的端口上可用

创建服务时端口应为8080。 nodePort 是随机分配的(或者您可以选择它 --nodePort )。对于您的配置,您可以在输出 172.17.0.4:31243 中看到它。所以端口是31243。 参考:https://minikube.sigs.k8s.io/docs/handbook/accessing/

对于部署 portforward 将不起作用,而是使用服务。尝试您服务的其他端口: 这里,第一个端口是主机端口,第二个端口是容器端口。

kubectl 端口转发 svc/che 8080:8080

一旦可以在 localhost:8080 上访问它,您就可以在 VM 外部使用 externalIPofVM:8080