如何在Minikube / Windows上的Istio中通过网关或Ingress访问Hello World Java微服务?我被困了几个小时/几天/几周

时间:2019-01-03 05:57:58

标签: istio

Minikube版本:v0.25.2

操作系统:Windows 10 Enterprise

Kubectl version
Client Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.1", GitCommit:"4ed3216f3ec431b140b1d899130a69fc671678f4", GitTreeState:"clean", BuildDate:"2018-10-05T16:46:06Z", GoVersion:"go1.10.4", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-04-10T12:46:31Z", GoVersion:"go1.9.4", Compiler:"gc", Platform:"linux/amd64"}

Kubectl cluster-info
Kubernetes master is running at https://192.168.99.100:8443

istioctl version
Version: 1.0.4
GitRevision: d5cb99f479ad9da88eebb8bb3637b17c323bc50b
User: root@8c2feba0b568
Hub: docker.io/istio
GolangVersion: go1.10.4
BuildStatus: Clean

试图在上述环境中通过Istio运行简单的hello-world应用程序。

kubectl get services
springbootapplication   NodePort    10.103.103.141   <none>        80:30456/TCP   3d

kubectl get pods
springbootapplication-v1-6b5bdff8cd-2qhnn   2/2     Running   5          3d

之后,我在helloworld.yaml文件下面创建一个文件,然后运行命令kubectl apply -f helloworld.yaml。它运行成功。

apiVersion: v1
kind: Service
metadata:
  name: springbootapplication
  labels:
    app: springbootapplication
spec:
  type: NodePort
  ports:
  - port: 80
    name: http
  selector:
    app: springbootapplication
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: springbootapplication-v1
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: springbootapplication
        version: v1
    spec:
      containers:
      - name: springbootapplication
        image: springbootapplication:v1
        imagePullPolicy: Never
        ports:
        - containerPort: 80
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: springbootapplication-gateway
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: springbootapplication
spec:
  hosts:
  - "*"
  gateways:
  - springbootapplication-gateway
  http:
  - match:
    - uri:
        exact: /home
    route:
    - destination:
        host: springbootapplication
        port:
          number: 80
      weight: 100
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: springbootapplication
spec:
  host: springbootapplication
  subsets:
  - name: v1
    labels:
      version: v1

问题:我现在不知道如何访问此Spring Boot应用程序?如何获取网关IP和入口?

1 个答案:

答案 0 :(得分:0)

您已经将此服务公开为http服务,因此在您的kubernetes集群中,检查“ istio-ingressgateway”服务(它应该是负载平衡器),并检查在端口80公开的端点。

或者通过命令行尝试这些。

kubectl -n istio-system获取服务istio-ingressgateway -o jsonpath ='{。spec.ports [?(@。name ==“ http2”)]。nodePort}'->应该为您提供入口端口

minikube ip->应该为您提供IP。