从主机访问Minikube负载均衡器服务

编程入门 行业动态 更新时间:2024-10-28 10:22:33
本文介绍了从主机访问Minikube负载均衡器服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试学习如何在Minikube中使用Kibernetes,并具有以下部署和服务:

I am trying to learn how to use Kibernetes with Minikube and have the following deployment and service:

--- kind: Service apiVersion: v1 metadata: name: exampleservice spec: selector: app: myapp ports: - protocol: "TCP" # Port accessible inside cluster port: 8081 # Port to forward to inside the pod targetPort: 8080 # Port accessible outside cluster nodePort: 30002 type: LoadBalancer --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: myappdeployment spec: replicas: 5 template: metadata: labels: app: myapp spec: containers: - name: myapp image: tutum/hello-world ports: - containerPort: 8080

我希望能够从本地计算机

I expect to be able to hit this service from my local machine at

192.168.64.2:30002

按照以下命令: minikube service exampleservice --url ,但是当我尝试从浏览器访问它时,我得到的网站无法访问.

As per the command: minikube service exampleservice --url but when I try to access this from the browser I get a site cannot be reached error.

一些有助于调试的信息:

Some information that may help debugging:

kubectl get services --all-namespaces :

NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default exampleservice LoadBalancer 10.104.248.158 <pending> 8081:30002/TCP 26m default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2h default user-service-service LoadBalancer 10.110.181.202 <pending> 8080:30001/TCP 42m kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 2h kube-system kubernetes-dashboard ClusterIP 10.110.65.24 <none> 80/TCP 2h

我正在OSX上运行minikube.

I am running minikube on OSX.

推荐答案

这是预期的.请注意,LoadBalancer是用于云的,用于在AWS中创建外部负载均衡器(例如ALP/NLP),并在GCP/Azure中创建类似的负载均衡器.

This is expected. Do note that LoadBalancer is for cloud to create external load balancer like ALP/NLP in AWS and something similar in GCP/Azure etc.

如此处所示更新服务.在这里,我假设 192.168.64.2 是您的minikube ip.如果没有,请使用minikube ip对其进行更新以使其正常工作.

Update the service as shown here. here i assume 192.168.64.2 is your minikube ip. if not, update it with minikube ip to make it work.

kind: Service apiVersion: v1 metadata: name: exampleservice spec: selector: app: myapp ports: - protocol: "TCP" # Port accessible inside cluster port: 8081 # Port to forward to inside the pod targetPort: 80 # Port accessible outside cluster nodePort: 30002 type: LoadBalancer externalIPs: - 192.168.64.2

现在,您可以通过 192.168.64.2:8081/

如果您需要通过30002访问该应用程序,则可以像这样使用它

If you need to access the application at 30002, you can use it like this

kind: Service apiVersion: v1 metadata: name: exampleservice spec: selector: app: myapp ports: - protocol: "TCP" # Port accessible inside cluster port: 8081 # Port to forward to inside the pod targetPort: 80 # Port accessible outside cluster nodePort: 30002 type: NodePort

您的部署文件对我来说似乎不正确.

Your deployment file does not look correct to me.

删除它 kubectl删除deploy/myappdeployment

使用它再次创建.

apiVersion: apps/v1beta1 kind: Deployment metadata: labels: app: myapp name: myappdeployment spec: replicas: 5 selector: matchLabels: app: myapp strategy: {} template: metadata: labels: app: myapp spec: containers: - image: tutum/hello-world name: myapp ports: - containerPort: 80

更多推荐

从主机访问Minikube负载均衡器服务

本文发布于:2023-11-23 23:44:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623211.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:均衡器   负载   主机   Minikube

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!