root@k8s-master:~# istioctl kube-inject -f demo.yaml | kubectl apply -f -
gateway.networking.istio.io/site-gw created
virtualservice.networking.istio.io/site-svc-vs created
destinationrule.networking.istio.io/site created
service/site created
deployment.apps/site-v10 created
deployment.apps/site-v11 created
root@k8s-master:~# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/site-v10-8bc8d8dd6-h2fbl 2/2 Running 0 23s
pod/site-v11-86b97859cf-2qsdd 2/2 Running 0 23s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 25h
service/site ClusterIP 10.99.233.144 <none> 8080/TCP 23s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/site-v10 1/1 1 1 23s
deployment.apps/site-v11 1/1 1 1 23s
NAME DESIRED CURRENT READY AGE
replicaset.apps/site-v10-8bc8d8dd6 1 1 1 23s
replicaset.apps/site-v11-86b97859cf 1 1 1 23s
root@k8s-master:~# kubectl get gateways.networking.istio.io
NAME AGE
site-gw 32s
root@k8s-master:~# kubectl get virtualservices.networking.istio.io
NAME GATEWAYS HOSTS AGE
site-svc-vs ["default/site-gw"] ["site.kb.cx"] 35s
root@k8s-master:~# kubectl get destinationrules.networking.istio.io
NAME HOST AGE
site site 40s
istion-info...
root@k8s-master:~# kubectl get -n istio-system all
NAME READY STATUS RESTARTS AGE
pod/istio-egressgateway-579dc4df64-dtwms 1/1 Running 0 25h
pod/istio-ingressgateway-679bf9454b-np67f 1/1 Running 0 7m53s
pod/istiod-8675d9c57b-jwswg 1/1 Running 0 25h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/istio-egressgateway ClusterIP 10.100.182.135 <none> 80/TCP,443/TCP 25h
service/istio-ingressgateway NodePort 10.96.242.187 <none> 15021:30455/TCP,80:30999/TCP,443:32324/TCP,31400:32261/TCP,15443:32152/TCP 25h
service/istiod ClusterIP 10.102.235.99 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP 25h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/istio-egressgateway 1/1 1 1 25h
deployment.apps/istio-ingressgateway 1/1 1 1 25h
deployment.apps/istiod 1/1 1 1 25h
NAME DESIRED CURRENT READY AGE
replicaset.apps/istio-egressgateway-579dc4df64 1 1 1 25h
replicaset.apps/istio-ingressgateway-679bf9454b 1 1 1 25h
replicaset.apps/istiod-8675d9c57b 1 1 1 25h
示例
访问普通流量
v1...
root@k8s-master:~# curl -vvv -H "Host: site.kb.cx" --resolve site.kb.cx:30999:127.0.0.1 http://site.kb.cx:30999
* Added site.kb.cx:30999:127.0.0.1 to DNS cache
* Hostname site.kb.cx was found in DNS cache
* Trying 127.0.0.1:30999...
* TCP_NODELAY set
* Connected to site.kb.cx (127.0.0.1) port 30999 (#0)
> GET / HTTP/1.1
> Host: site.kb.cx
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< date: Wed, 31 Aug 2022 12:54:20 GMT
< content-type: text/html
< accept-ranges: bytes
< last-modified: Wed, 31 Aug 2022 12:52:32 GMT
< etag: "630f5990-15"
< content-length: 21
< x-envoy-upstream-service-time: 2
< server: istio-envoy
< version: v10
<
welcome to site v1.0
* Connection #0 to host site.kb.cx left intact
金丝雀流量
canary-v11...
root@k8s-master:~# curl -vvv -H "Host: site.kb.cx" -H "x-canary: true" --resolve site.kb.cx:30999:127.0.0.1 http://site.kb.cx:30999
* Added site.kb.cx:30999:127.0.0.1 to DNS cache
* Hostname site.kb.cx was found in DNS cache
* Trying 127.0.0.1:30999...
* TCP_NODELAY set
* Connected to site.kb.cx (127.0.0.1) port 30999 (#0)
> GET / HTTP/1.1
> Host: site.kb.cx
> User-Agent: curl/7.68.0
> Accept: */*
> x-canary: true
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< date: Wed, 31 Aug 2022 12:55:05 GMT
< content-type: text/html
< accept-ranges: bytes
< last-modified: Wed, 31 Aug 2022 12:52:15 GMT
< etag: "630f597f-15"
< content-length: 21
< x-envoy-upstream-service-time: 34
< server: istio-envoy
< x-canary: true
<
welcome to site v1.1
* Connection #0 to host site.kb.cx left intact
批量打流
$ for i in {1..100}; do curl -H "x-canary: true" --resolve site.kb.cx:30999:127.0.0.1 http://site.kb.cx:30999;done
welcome to site v1.1
...