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

时间:2019-04-01 19:58:27

标签: kubernetes load-balancing minikube

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

---
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

我希望能够在本地计算机

上使用此服务
http://192.168.64.2:30002

按照命令minikube service exampleservice --url,但是当我尝试从浏览器访问此文件时,无法访问网站。

一些有助于调试的信息:

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。

2 个答案:

答案 0 :(得分:2)

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

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

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

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

访问您的应用程序

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

    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

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

删除它 kubectl delete 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

答案 1 :(得分:0)

注意::Minikube不支持LoadBalancer服务(直到今天我发表评论),因此该服务将永远不会获得外部IP。但是您仍然可以通过其外部端口访问该服务。

您可以获取IP和端口,通过该IP和端口 可以通过运行

来访问服务

minikube service kubia-http#打开具有IP和端口的浏览器

OR

minikube service kubia --url#获取终端的IP和端口

相关问题