部署httpbin Web示例:
cd istio-1.4.2/samples/httpbin
kubectl apply -f httpbin-nodeport.yaml
访问,根据svc生成的端口,
[root@master httpbin]# kubectl get svc|grep httpbin
httpbin NodePort 10.0.0.172 <none> 8000:31118/TCP 23d
我们访问界面:http://192.168.25.137:31118/
将该应用接入到istio中,在应用上面装上一个Sidecar
手动注入
kubectl apply -f <(istioctl kube-inject -f httpbin-nodeport.yaml)
或者
istioctl kube-inject -f httpbin-nodeport.yaml |kubectl apply -f
我们通过 istioctl kube-inject -f httpbin-nodeport.yaml |more
可以得知,我们加了一个叫做proxy的容器。
image: docker.io/istio/proxyv2:1.4.2
imagePullPolicy: IfNotPresent
name: istio-init
resources:
此时可以看到该pod下面多了一个容器,
[root@master ~]# kubectl get pod|grep httpbin
httpbin-5c8ff7878b-c5mcc 2/2 Running 2 21h
自动注入
针对命名空间进行自动注入
kubectl label namespace default istio-injection=enabled
部署完毕后,因为sidecar会接管流量所以可以用istio的网关服务来访问。
部署网关:
kubectl apply -f httpbin-gateway.yaml
我们要在外部访问依赖的是 istio-ingressgateway,查看ingressgateway的svc对外端口。
因为LoadBalancer对应的是公有云服务,我们没有创建lb所以会是pending状态,但是还是会对外的nodeport端口
[root@master httpbin]# kubectl get svc -n istio-system|grep istio-ingressgateway
istio-ingressgateway LoadBalancer 10.0.0.102 <pending> 15020:35582/TCP,80:31513/TCP,443:48478/TCP,15029:44880/TCP,15030:45669/TCP,15031:48045/TCP,15032:30890/TCP,15443:32749/TCP 35d
此时我们访问:http://192.168.25.137:31513/
同时观察istio-ingressgateway pod的流量也可以证明流量是经过了istio-ingressgateway
kubectl logs -f istio-ingressgateway-6d759478d8-r9f24 -n istio-system
[2021-04-11T15:02:56.117Z] “GET /static/favicon.ico HTTP/1.1” 200 - “-” “-” 0 22382 7 6 “192.168.25.137” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36” “c757b3d1-a0ab-9512-9312-f6c99e57d505” “192.168.25.137:31513” “172.17.154.80:80” outbound|8000||httpbin.default.svc.cluster.local - 172.17.134.110:80 192.168.25.137:64639 - -
整体流程如下: