1. Ingress的基本概念
服务的访问入口,接收外部请求并转发到后端服务。在Istio里Ingress也是一个网关,是通过gateway这个方式去实现的。
2. 实验:创建Ingress网关
引入一个新服务httpbin,同时把服务通过Ingress暴露给外部使其可以访问
1. 部署httpbin服务
官方提供了配置清单,在安装目录下 samples/httpbin/httpbin.yaml
################################################################################################### httpbin service##################################################################################################apiVersion: v1kind: ServiceAccountmetadata:name: httpbin---apiVersion: v1kind: Servicemetadata:name: httpbinlabels:app: httpbinspec:ports:- name: httpport: 8000targetPort: 80selector:app: httpbin---apiVersion: apps/v1kind: Deploymentmetadata:name: httpbinspec:replicas: 1selector:matchLabels:app: httpbinversion: v1template:metadata:labels:app: httpbinversion: v1spec:serviceAccountName: httpbincontainers:- image: docker.io/kennethreitz/httpbinimagePullPolicy: IfNotPresentname: httpbinports:- containerPort: 80
kubectl apply -f samples/httpbin/httpbin.yaml
查看所有的pod
kubectl get pod
2. 定义Ingress gateway
gateway2.yaml清单如下
可以看到,依然使用的是gateway来部署Ingress,选择Istio默认的Ingressgateway作为selector,同时暴露80端口作为他的访问点。这里设置了一个host,希望请求是以这个方式进行访问
apiVersion: networking.istio.io/v1alpha3kind: Gatewaymetadata:name: httpbin-gatewayspec:selector:istio: ingressgatewayservers:- port:number: 80name: httpprotocol: HTTPhosts:- "httpbin.example.com"
kubectl apply -f linshi/gateway2.yaml
3. 定义对应的虚拟服务
还需要给gateway创建一个对应的虚拟服务,让他来对这个服务做一个简单的路由
虚拟服务的配置清单如下,vs.yaml
首先需要和gateway对应起来,
apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:name: httpbinspec:hosts:- "httpbin.example.com"gateways:- httpbin-gateway # 和gateway对应起来(绑定)http:- match:- uri:prefix: /status- uri:prefix: /delayroute:- destination:port:number: 8000host: httpbin
kubectl apply -f linshi/vs.yaml
查看目前虚拟服务信息
kubectl get vs
4. 测试
curl -I -HHost:httpbin.example.com http://localhost/status/200
