首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VirtualService主机和迷你库

VirtualService主机和迷你库
EN

Stack Overflow用户
提问于 2021-02-25 12:01:33
回答 1查看 2.6K关注 0票数 1

项目中,假设我将主机的值设置为hello

代码语言:javascript
复制
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: hello-k8s
spec:
  hosts:
    - ???
  http:
    - name: hello-k8s
      match:
        - uri:
            prefix: /
      route:
        - destination:
            host: hello               # <--------------
            port:
              number: 8080

在将项目部署到本地minikube之后:

  • 我应该把我的请求发送给哪个域名?hello.local
代码语言:javascript
复制
$ curl what.should.be.here:8080
  • 有什么方法可以用kubectl和内省来找出吗?

更新1:

我把主机改成了hello.local

然后我验证了istio是在minikube中启用的。

代码语言:javascript
复制
➜ minikube addons list
|-----------------------------|----------|--------------|
|         ADDON NAME          | PROFILE  |    STATUS    |
|-----------------------------|----------|--------------|
| ambassador                  | minikube | disabled     |
| csi-hostpath-driver         | minikube | disabled     |
| dashboard                   | minikube | disabled     |
| default-storageclass        | minikube | enabled ✓    |
| efk                         | minikube | disabled     |
| freshpod                    | minikube | disabled     |
| gcp-auth                    | minikube | disabled     |
| gvisor                      | minikube | disabled     |
| helm-tiller                 | minikube | disabled     |
| ingress                     | minikube | disabled     |
| ingress-dns                 | minikube | disabled     |
| istio                       | minikube | enabled ✓    |
| istio-provisioner           | minikube | enabled ✓    |
| kubevirt                    | minikube | disabled     |
| logviewer                   | minikube | disabled     |
| metallb                     | minikube | disabled     |
| metrics-server              | minikube | disabled     |
| nvidia-driver-installer     | minikube | disabled     |
| nvidia-gpu-device-plugin    | minikube | disabled     |
| olm                         | minikube | disabled     |
| pod-security-policy         | minikube | disabled     |
| registry                    | minikube | disabled     |
| registry-aliases            | minikube | disabled     |
| registry-creds              | minikube | disabled     |
| storage-provisioner         | minikube | enabled ✓    |
| storage-provisioner-gluster | minikube | disabled     |
| volumesnapshots             | minikube | disabled     |
|-----------------------------|----------|--------------|

我部署了这个应用程序,并验证了一切正常运行:

代码语言:javascript
复制
➜ kubectl apply -k base/
service/hello-k8s unchanged
deployment.apps/hello-k8s unchanged
virtualservice.networking.istio.io/hello-k8s configured

➜ kubectl get deployments/hello-k8s
NAME        READY   UP-TO-DATE   AVAILABLE   AGE
hello-k8s   1/1     1            1           20h

➜ kubectl get pods
NAME                         READY   STATUS    RESTARTS   AGE
hello-k8s-6d9cc7d655-plzs8   1/1     Running   0          20h

➜ kubectl get service/hello-k8s
NAME        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
hello-k8s   ClusterIP   10.98.144.226   <none>        8080/TCP   21h

➜ kubectl get virtualservice/hello-k8s
NAME        GATEWAYS   HOSTS             AGE
hello-k8s              ["hello.local"]   20h

➜ kubectl get pods -n istio-system
NAME                                    READY   STATUS    RESTARTS   AGE
istio-ingressgateway-8577c95547-6c9sk   1/1     Running   0          21h
istiod-6ccd677dc7-7cvr2                 1/1     Running   0          21h
prometheus-7767dfd55-x2pv6              2/2     Running   0          21h

不知道我为什么要这么做,但显然应该这样做:

代码语言:javascript
复制
➜ kubectl label namespace default istio-injection=enabled --overwrite
namespace/default labeled

➜ kubectl get namespace -L istio-injection
NAME              STATUS   AGE   ISTIO-INJECTION
default           Active   21h   enabled
istio-operator    Active   21h
istio-system      Active   21h   disabled
kube-node-lease   Active   21h
kube-public       Active   21h
kube-system       Active   21h
playground        Active   21h

我检查了minikube的ip,并为hello.local添加了/etc/主机条目

代码语言:javascript
复制
➜  minikube ip
192.168.49.2

➜ tail -n 3  /etc/hosts

# Minikube
192.168.49.2    hello.local

然后,我询问了istio-ingressgateway的端口,根据这篇博客文章

代码语言:javascript
复制
➜ kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}'
30616

最后,我向hello.local:30616发送了一个请求,但是请求并没有到达我的应用程序:

代码语言:javascript
复制
➜ curl -iv hello.local:30616/hello
*   Trying 192.168.49.2:30616...
* TCP_NODELAY set
* Connected to hello.local (192.168.49.2) port 30616 (#0)
> GET /hello HTTP/1.1
> Host: hello.local:30616
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
< date: Thu, 25 Feb 2021 14:51:18 GMT
date: Thu, 25 Feb 2021 14:51:18 GMT
< server: istio-envoy
server: istio-envoy
< content-length: 0
content-length: 0

<
* Connection #0 to host hello.local left intact
EN

回答 1

Stack Overflow用户

发布于 2021-02-25 14:11:28

我应该把我的请求发送给哪个域名?hello.local**?**?

答案是,您可以使用任何您想要的域,但是您需要在/etc/hosts中添加这个域。然后/etc/hosts域将是istio网关负载平衡器的ip地址。感谢它,您将能够使用该域而不是入口网关ip。

继续前进--虚拟服务中的主机/主机有两件事要考虑:

如果您将虚拟服务hosts值设置为hello,那么按照文档,Istio将根据规则的命名空间而不是服务来解释短名称。default命名空间中带有主机hello的规则将被解释为hello.default.svc.cluster.local

您还可以在主机中沿域引用服务。

因此,为了避免潜在的错误配置,建议始终使用完全限定的域名而不是短名称.

现在就在destination.host旁边

服务注册表中的服务名称。服务名称从平台的服务注册表中查找(例如,Kubernetes服务、领事服务等)以及由ServiceEntry声明的主机。转发到两个目的地中都找不到的通信量将被删除。

这也是一个好鼓膜如何配置金属作为负载平衡器和istio在迷你库。拥有metallb将使您的服务自动配置为负载平衡器。

在进一步检查您的情况后,我想这个问题可能与您的网关根本没有被使用有关:

代码语言:javascript
复制
➜ kubectl get virtualservice/hello-k8s
NAME        GATEWAYS   HOSTS             AGE
hello-k8s              ["hello.local"]   20h ## Gateway describes a load balancer operating at the edge of the mesh receiving incoming or outgoing HTTP/TCP connections.

“网关描述了在网格边缘运行的负载均衡器,接收传入或传出的HTTP/TCP连接。使用Istio配置,您可以通过virtualservice.spec.gateways将virtualservice.spec.gateways绑定到特定的网关(允许istio服务网格内的外部流量或内部通信)”,保留字mesh用于暗示网格中的所有侧节点。当省略此字段时,默认网关(网格)将使用“https://istio.io/latest/docs/reference/config/networking/virtual-service/#VirtualService”。

确保配置GatewayVirtualService

代码语言:javascript
复制
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: my-gateway
spec:
  selector:
    istio: ingressgateway  ### this should be verified with istio ingress gateway pod labels
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"   ### for specific hosts it can be f.e. hello.local
代码语言:javascript
复制
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: hello-k8s
spec:
  hosts:
    - hello.local
  gateways:
  - my-gateway
  http:
    - match:
        - uri:
            prefix: /
      route:
        - destination:
            host: hello-k8s.default.svc.cluster.local 
            port:
              number: 8080
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66368096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档