使用 Kubernetes 中的入口通过以太网远程访问 JupyterHub 为零
Remote access Zero to JupyterHub over Ethernet with ingress in Kubernetes
上下文
我在一台裸机服务器(4 个节点)上安装了 Kubernetes 并向其部署了 Zero to JupyterHub。
这很好用;我可以从主节点正确访问集线器。
现在我想通过以太网从外部计算机访问服务器上的集线器。因此,我遵循 official instructions and installed MetalLB 以便为我的 proxy-public-服务(正确设置)提供外部 IP。
此外,我安装了 nginx-ingress-controller 以便能够进行入口,它也成功获得了外部 IP(小提示:使用 Helm-chart;我不能'应用其他推荐步骤时无法获得服务 运行。
由于我在弄清楚如何执行此入口时遇到了一些麻烦,这里有一个示例:
kubectl apply -f ingress.yaml --namespace jhub
#ingress.yaml:
#apiVersion: networking.k8s.io/v1beta1
#kind: Ingress
#metadata:
# name: jupyterhub-ingress
# annotations:
# nginx.ingress.kubernetes.io/rewrite-target: /
#spec:
# rules:
# - host: jupyterhub.cluster
# http:
# paths:
# - path: /
# backend:
# serviceName: proxy-public
# servicePort: 80
无论如何,我无法打开 proxy-public 提供的外部 IP(意味着我在浏览器中插入外部 IP)。
问题
如何通过外部 IP 远程访问我的 JupyterHub;我错过了什么?
我错过了这可以通过与 Kubernetes-Dashboard 相同的方式实现:您必须建立一个开放的 ssh 连接(因此,打开一个隧道 -> 来自外部计算机的隧道)。
当然,这不是我想要的 "exernal" 访问权限,而是适用于我的测试环境(也许还有您的)的有效且快速的解决方案。
如何建立这个ssh-connect
首先,获取您的 proxy-public:
的外部 IP 地址
$: kubectl get services --namespace jhub
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hub ClusterIP 10.99.241.72 <none> 8081/TCP 95m
proxy-api ClusterIP 10.107.175.27 <none> 8001/TCP 95m
proxy-public LoadBalancer 10.102.171.162 192.168.1.240 80:31976/TCP,443:32568/TCP 95m
注意:外部IP的范围在我的MetalLB-config中的layer2
中定义。
使用此信息(假设您使用的是 Linux),打开终端并使用以下命令:
$ ssh pi@10.10.10.2 -L 8000:192.168.1.240:80
# -L opens a localhost-connection
# pi@10.10.10.2 logs me into my second node with user pi
Note1: localhost:8000
配置为 proxy-public 的 targetPort 和 http 也可以在您描述服务并查看相应端口的规格时看到(您也可以在那里获取 https 的设置):
kind: Service
apiVersion: v1
metadata:
name: proxy-public
namespace: jhub
...
spec:
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8000
nodePort: 31976
- name: https
...
最后,在您的浏览器中输入 http://localhost:8000/
- 瞧,您将进入 JupyterHub 登录页面!
上下文
我在一台裸机服务器(4 个节点)上安装了 Kubernetes 并向其部署了 Zero to JupyterHub。 这很好用;我可以从主节点正确访问集线器。
现在我想通过以太网从外部计算机访问服务器上的集线器。因此,我遵循 official instructions and installed MetalLB 以便为我的 proxy-public-服务(正确设置)提供外部 IP。
此外,我安装了 nginx-ingress-controller 以便能够进行入口,它也成功获得了外部 IP(小提示:使用 Helm-chart;我不能'应用其他推荐步骤时无法获得服务 运行。
由于我在弄清楚如何执行此入口时遇到了一些麻烦,这里有一个示例:
kubectl apply -f ingress.yaml --namespace jhub
#ingress.yaml:
#apiVersion: networking.k8s.io/v1beta1
#kind: Ingress
#metadata:
# name: jupyterhub-ingress
# annotations:
# nginx.ingress.kubernetes.io/rewrite-target: /
#spec:
# rules:
# - host: jupyterhub.cluster
# http:
# paths:
# - path: /
# backend:
# serviceName: proxy-public
# servicePort: 80
无论如何,我无法打开 proxy-public 提供的外部 IP(意味着我在浏览器中插入外部 IP)。
问题
如何通过外部 IP 远程访问我的 JupyterHub;我错过了什么?
我错过了这可以通过与 Kubernetes-Dashboard 相同的方式实现:您必须建立一个开放的 ssh 连接(因此,打开一个隧道 -> 来自外部计算机的隧道)。
当然,这不是我想要的 "exernal" 访问权限,而是适用于我的测试环境(也许还有您的)的有效且快速的解决方案。
如何建立这个ssh-connect
首先,获取您的 proxy-public:
的外部 IP 地址$: kubectl get services --namespace jhub
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hub ClusterIP 10.99.241.72 <none> 8081/TCP 95m
proxy-api ClusterIP 10.107.175.27 <none> 8001/TCP 95m
proxy-public LoadBalancer 10.102.171.162 192.168.1.240 80:31976/TCP,443:32568/TCP 95m
注意:外部IP的范围在我的MetalLB-config中的layer2
中定义。
使用此信息(假设您使用的是 Linux),打开终端并使用以下命令:
$ ssh pi@10.10.10.2 -L 8000:192.168.1.240:80
# -L opens a localhost-connection
# pi@10.10.10.2 logs me into my second node with user pi
Note1: localhost:8000
配置为 proxy-public 的 targetPort 和 http 也可以在您描述服务并查看相应端口的规格时看到(您也可以在那里获取 https 的设置):
kind: Service
apiVersion: v1
metadata:
name: proxy-public
namespace: jhub
...
spec:
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8000
nodePort: 31976
- name: https
...
最后,在您的浏览器中输入 http://localhost:8000/
- 瞧,您将进入 JupyterHub 登录页面!