【问题标题】:Running minikube on digital ocean and trying to access from outside在数字海洋上运行 minikube 并尝试从外部访问
【发布时间】:2020-07-29 03:29:15
【问题描述】:

我在数字海洋上安装了 minikube,现在尝试从外部访问我的应用程序。但不知何故它不起作用。

我的服务 yaml 文件:

apiVersion: v1
kind: Service
metadata:
  name: python-data-service
spec:
  selector:
   app: python-web-selector
   tier: backend
  ports:
      - port: 5000
        targetPort: 80
        protocol: TCP
  externalIPs:
      - 64.225.117.89
  type: LoadBalancer

64.225.117.89 是我的 droplet ip。

developer@Kubernetes:~/yaml_Files$ minikube service python-data-service
|-----------|---------------------|-------------|-------------------------|
| NAMESPACE |        NAME         | TARGET PORT |           URL           |
|-----------|---------------------|-------------|-------------------------|
| default   | python-data-service |        5000 | http://172.17.0.3:30718 |
|-----------|---------------------|-------------|-------------------------|
????  Opening service default/python-data-service in default browser...

developer@Kubernetes:~/yaml_Files$ kubectl get services
NAME                  TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)          AGE
kubernetes            ClusterIP      10.96.0.1      <none>          443/TCP          57s
python-data-service   LoadBalancer   10.111.0.153   64.225.117.89   5000:30718/TCP   16s
sql-python-service    ClusterIP      None           <none>          3306/TCP         15s

developer@Kubernetes:~/yaml_Files$ curl http://172.17.0.3:31306
<html>
  <body>
    <form  method="POST" action="/postdata">
      <input type="text" name="student_name">
      <input type="text" name="student_id">
      <input type="text" name="student_email">
      <input type="text" name="student_phone">
      <input type="text" name="student_class">
      <input type="submit" value="Add">
    </form>
  </body>

developer@Kubernetes:~/yaml_Files$ curl http://localhost:5000
curl: (7) Failed to connect to localhost port 5000: Connection refused

我更改了数字海洋中的防火墙设置,但没有运气,任何指针?

【问题讨论】:

  • 在 droplet 上你有开放的端口 5000?尝试在 LB IP 64.225.117.89 和端口 5000 上发送请求
  • 用端口 5000 试过了,还是不行。
  • 检查防火墙和端口?
  • 是的,在端口 5000 上打开了入站和出站

标签: docker kubernetes digital-ocean kubectl minikube


【解决方案1】:

在 minikube 中访问应用程序有两种选择——通过 NodePort 或通过 LoadBalancer。

LoadBalancer 类型的服务可以通过minikube tunnel 命令公开。它作为一个进程运行,使用集群的 IP 地址作为网关,在主机上创建到集群的服务 CIDR 的网络路由。隧道命令将外部 IP 直接暴露给在主机操作系统上运行的任何程序。该命令当前作为单独的守护进程运行,并创建到 minikube VM 的网络路由。 It will assign externalIP 到您的服务,然后可以从您的主机访问它。

如果您想使用NodePort 服务类型访问它,您必须获取minikube ip 和节点端口,例如使用minikube service $SERVICE_NAME --url

要访问localhost:node_port,您必须从 minikube (minikube ssh) 内部访问它。

【讨论】:

    猜你喜欢
    • 2021-01-08
    • 2015-03-14
    • 1970-01-01
    • 2021-10-24
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 2021-04-02
    相关资源
    最近更新 更多