kubernetes- 负载均衡器外部端点始终是本地主机

kubernetes- load balancer external endpoint is always localhost

我正在使用 minikube,当我创建一个负载均衡器时,它总是会在外部端点给我一个不同的 ip,并且我能够访问我的应用程序。

但现在,我改为 docker kubernetes,当我创建负载均衡器时,它总是在外部端点添加 localhost:8181

这是我的 yaml:

apiVersion: v1
kind: Service
metadata:
  name: app1
  labels:
    app: app1
spec:
  #externalIPs:
  #  - 172.29.0.0
  ports:
  - protocol: TCP
    name: http
    port: 8181
    targetPort: 8181
  type: LoadBalancer
  selector:
    app: app1

与 : kubectl expose deployment app1 --port=8181 --target-port=8181 --name=app1 --type=LoadBalancer

相同

如您所见,我尝试添加外部 IP,当我这样做时,本地主机和外部 IP 都出现在仪表板中,但是使用外部 IP 不起作用...

我希望它在我创建负载均衡器时生成一个 ip,这样我就可以从那里访问我的应用程序,就像我对 minikube 所做的那样。

感谢您抽出时间。

Official documentation 表示:

Type values and their behaviors are: LoadBalancer: Exposes the Service externally using a cloud provider's load balancer. NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created.

这就是为什么使用 Kubernetes 必须启用云提供商(否则不会提供外部 IP):

$ kubectl get svc
NAME                     TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
app1                     LoadBalancer   10.0.2.46     <pending>     8181:30257/TCP   18s

虽然在 minikube 中它是为你配置的 minikube service <service_name>:

$ kubectl get svc
NAME         TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
app1         LoadBalancer   10.103.51.13   <pending>     8181:30129/TCP   68s

$ minikube service app1
|-----------|------|-------------|-----------------------------|
| NAMESPACE | NAME | TARGET PORT |             URL             |
|-----------|------|-------------|-----------------------------|
| default   | app1 | http/8181   | http://192.168.99.100:30129 |
|-----------|------|-------------|-----------------------------|

I would like it to generate an ip when I create a loadbalancer so I can access my app from there, like I did with minikube.

Ales Nosek 的主题是 awesome post

简而言之:

In order to be able to create a service of type LoadBalancer, a cloud provider has to be enabled in the configuration of the Kubernetes cluster. As of version 1.6, Kubernetes can provision load balancers on AWS, Azure, CloudStack, GCE and OpenStack.

这在很大程度上取决于您想要实现的目标,但我相信您可能对 Ingress.

感兴趣