暴露kiali服务



前提工作:

给istio的ingressgateway配置EXTERNAL-IP:

        默认情况下在本地搭建的k8s服务没有外网IP,istio安装后istio-ingressgateway也是获取不到EXTERNAL-IP的,现在手动配置一个IP作为外网IP。

cp ifcfg-eth0 ifcfg-eth0:1

临时修改:

ip addr add 192.168.0.88/24 dev eth0 label eth0:1

永久修改:修改IP和设备名DEVICE,修改后重启主机,仅重启网卡有点问题。

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0:1 # 修改网卡别名
ONBOOT=yes
IPADDR=192.168.0.88 # 修改IP地址
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=114.114.114.114

修改配置:

kubectl edit svc -n istio-system istio-ingressgateway
spec:
  externalIPs:
  - 192.168.199.88
  ports:
  - name: http-kiali
    nodePort: 32159
    port: 20001
    protocol: TCP
    targetPort: 20001

效果如下:有EXTERNAL-IP即可

]# kubectl get svc -n istio-system | grep istio-ingressgateway
NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)
istio-ingressgateway   LoadBalancer   10.103.23.83     192.168.0.88  ........


注意下面几个命令的使用:

istioctl proxy-status
istioctl proxy-config listeners # 查看端口
istioctl proxy-config routes # 查看路由信息
istioctl proxy-config clusters # 查看集群信息
istioctl proxy-config endpoints # 端点信息


暴露服务:

gateway文件:这里演示的kiali暴露方式是指定的端口,如果用80端口看下面暴露grafana服务的流程。

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata: 
  name: kiali-gateway
  namespace: istio-system
spec:
  selector:
    app: istio-ingressgateway # 后端服务的标签
  servers:
  - port:
      number: 20001
      name: http-kiali # 这样的格式代表七层http代理,否者是四层代理
      protocol: HTTP # 跟上面的意义一样
    hosts:
    - "kiali.ops.net"

查看配置是否下发:

在istio-ingressgateway这个条目中没有出现 非SYNCED 的状态,说明已经下发成功。

~]# istioctl proxy-status
NAME                                                   CDS        LDS        EDS        RDS          ISTIOD                      VERSION
istio-egressgateway-c9cbbd99f-7c6px.istio-system       SYNCED     SYNCED     SYNCED     NOT SENT     istiod-765596f7ff-vk6b5     1.12.2
istio-ingressgateway-7c8bc47b49-2xcpt.istio-system     SYNCED     SYNCED     SYNCED     SYNCED       istiod-765596f7ff-vk6b5     1.12.2

查看监听的端口:

~]# istioctl proxy-config listeners istio-ingressgateway-7c8bc47b49-2xcpt -n istio-system
ADDRESS PORT  MATCH DESTINATION
0.0.0.0 20001 ALL   Route: http.20001
0.0.0.0 15021 ALL   Inline Route: /healthz/ready*
0.0.0.0 15090 ALL   Inline Route: /stats/prometheus*

查看路由信息:

~]# istioctl proxy-config routes istio-ingressgateway-7c8bc47b49-2xcpt.istio-system
NAME          DOMAINS     MATCH                  VIRTUAL SERVICE
http.20001    *           /*                     404 # 可以看到404,说明路由还未完成
              *           /stats/prometheus*     
              *           /healthz/ready*

部署virtualService:

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: kiali-virtualservice
  namespace: istio-system
spec:
  hosts:
  - "kiali.ops.net"
  gateways:
  - kiali-gateway # 如果和gateway资源不在同一个名称空间则使用<namespace>/<virtualService>格式
  http:
  - match:
    - port: 20001 # 这里用的是端口,一般用的是uri
    route:
    - destination:
        host: kiali # 如果有DestinationRule就路由到ds,没有就路由到svc
        port: 
          number: 20001

查看路由:可以看出404已经变成具体的服务了

]# istioctl proxy-config routes istio-ingressgateway-7c8bc47b49-2xcpt.istio-system
NAME           DOMAINS           MATCH                  VIRTUAL SERVICE
http.20001     kiali.ops.net     /*                     kiali-virtualservice.istio-system
               *                 /stats/prometheus*     
               *                 /healthz/ready*

查看vs:

]# kubectl get vs -n istio-system 
NAME                   GATEWAYS            HOSTS               AGE
kiali-virtualservice   ["kiali-gateway"]   ["kiali.ops.net"]   21m

查看clusters:可以看到outbound已经正常工作了

]# istioctl proxy-config clusters istio-ingressgateway-7c8bc47b49-2xcpt.istio-system | grep kiali
kiali.istio-system.svc.cluster.local                                   9090      -          outbound      EDS            
kiali.istio-system.svc.cluster.local                                   20001     -          outbound      EDS

然后访问 kiali.ops.net:20001 就可以访问kiali了。


其他方面:

DestionationRule:dr一般不需要配置,除非应用的服务中使用了一些高级路由

apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: kiali
  namespace: istio-system
spec:
  host: kiali
  trafficPolicy:
    tls:
      mode: DISABLE

查看规则:

]# kubectl get dr -n istio-system 
NAME    HOST    AGE
kiali   kiali   9s

查看集群规则:后面的 DESTINATION RULE 就多个个dr的规则。

]# istioctl proxy-config clusters istio-ingressgateway-7c8bc47b49-2xcpt.istio-system | grep kiali
kiali.istio-system.svc.cluster.local                                   9090      -          outbound      EDS            kiali.istio-system
kiali.istio-system.svc.cluster.local                                   20001     -          outbound      EDS            kiali.istio-system


查看Pod的listeners、clusters、routes、endpoints:只有跑了sidecar的服务才能看到。

istioctl proxy-config listeners httpbin-575d9fdcf-gbn6z.default
istioctl proxy-config clusters httpbin-575d9fdcf-gbn6z.default
istioctl proxy-config routes httpbin-575d9fdcf-gbn6z.default
istioctl proxy-config endpoints httpbin-575d9fdcf-gbn6z.default

查看端口:

]# istioctl proxy-config listeners httpbin-575d9fdcf-gbn6z.default --port 20001
ADDRESS PORT  MATCH                        DESTINATION
0.0.0.0 20001 Trans: raw_buffer; App: HTTP Route: 20001
0.0.0.0 20001 ALL                          PassthroughCluster



暴露grafana服务


配置文件对应关系如图:

image.png

gateway文件:

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: grafana-gateway
  namespace: istio-system
spec:
  selector:
    app: istio-ingressgateway
  servers:
  - port: 
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "grafana.ops.net"

查看监听端口:

]# istioctl proxy-config listeners istio-ingressgateway-7c8bc47b49-2xcpt.istio-system
ADDRESS PORT  MATCH DESTINATION
0.0.0.0 8080  ALL   Route: http.8080 # 这里使用的是8080,因为80端口有特殊作用
0.0.0.0 15021 ALL   Inline Route: /healthz/ready*
0.0.0.0 15090 ALL   Inline Route: /stats/prometheus*
0.0.0.0 20001 ALL   Route: http.20001

查看路由:可以看到8080的端口的VIRTUAL SERVICE是404,下面需要配置virtualService。

]# istioctl proxy-config routes istio-ingressgateway-7c8bc47b49-2xcpt.istio-system
NAME           DOMAINS           MATCH                  VIRTUAL SERVICE
http.20001     kiali.ops.net     /*                     kiali-virtualservice.istio-system
http.8080      *                 /*                     404
               *                 /stats/prometheus*     
               *                 /healthz/ready*

部署vs文件:

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: grafana-virtualservice
  namespace: istio-system
spec:
  hosts:
  - "grafana.ops.net"
  gateways:
  - grafana-gateway
  http:
  - match:
    - uri: # 此处用的是uri,上面用的是port
        prefix: /
    route:
    - destination:
        host: grafana
        port:
          number: 3000

查看路由:这时候VIRTUAL SERVICE 已近有vs的配置了

]# istioctl proxy-config routes istio-ingressgateway-7c8bc47b49-2xcpt.istio-system
NAME           DOMAINS             MATCH                  VIRTUAL SERVICE
http.20001     kiali.ops.net       /*                     kiali-virtualservice.istio-system
http.8080      grafana.ops.net     /*                     grafana-virtualservice.istio-system
               *                   /stats/prometheus*     
               *                   /healthz/ready*

查看集群:此时的集群是看不到 DESTINATION RULE 的信息的,因为还没有配置。

]# istioctl proxy-config clusters istio-ingressgateway-7c8bc47b49-2xcpt.istio-system
SERVICE FQDN                                                           PORT      SUBSET     DIRECTION     TYPE           DESTINATION RULE
BlackHoleCluster                                                       -         -          -             STATIC         
agent                                                                  -         -          -             STATIC         
grafana.istio-system.svc.cluster.local                                 3000      -          outbound      EDS

这时就已近可以访问了。