Service Mesh: 基于 Istio 的落地实践(一)
Last updated
$ curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.2.2 sh -
$ cd istio-1.2.2
$ export PATH=$PWD/bin:$PATH$ for i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl apply -f $i; done
$ kubectl get crd | grep istio
adapters.config.istio.io 2019-06-29T04:49:22Z
attributemanifests.config.istio.io 2019-06-29T04:49:22Z
authorizationpolicies.rbac.istio.io 2019-06-29T04:49:22Z
clusterrbacconfigs.rbac.istio.io 2019-06-29T04:49:22Z
destinationrules.networking.istio.io 2019-06-29T04:49:21Z
envoyfilters.networking.istio.io 2019-06-29T04:49:22Z
gateways.networking.istio.io 2019-06-29T04:49:22Z
handlers.config.istio.io 2019-06-29T04:49:22Z
httpapispecbindings.config.istio.io 2019-06-29T04:49:22Z
httpapispecs.config.istio.io 2019-06-29T04:49:22Z
instances.config.istio.io 2019-06-29T04:49:22Z
meshpolicies.authentication.istio.io 2019-06-29T04:49:22Z
policies.authentication.istio.io 2019-06-29T04:49:22Z
quotaspecbindings.config.istio.io 2019-06-29T04:49:22Z
quotaspecs.config.istio.io 2019-06-29T04:49:22Z
rbacconfigs.rbac.istio.io 2019-06-29T04:49:22Z
rules.config.istio.io 2019-06-29T04:49:22Z
serviceentries.networking.istio.io 2019-06-29T04:49:22Z
servicerolebindings.rbac.istio.io 2019-06-29T04:49:22Z
serviceroles.rbac.istio.io 2019-06-29T04:49:22Z
sidecars.networking.istio.io 2019-06-29T04:49:22Z
templates.config.istio.io 2019-06-29T04:49:22Z
virtualservices.networking.istio.io 2019-06-29T04:49:21Z$ kubectl apply -f install/kubernetes/istio-demo.yaml$ kubectl get svc -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
grafana ClusterIP 10.254.33.222 <none> 3000/TCP 97s
istio-citadel ClusterIP 10.254.211.95 <none> 8060/TCP,15014/TCP 97s
istio-egressgateway ClusterIP 10.254.42.123 <none> 80/TCP,443/TCP,15443/TCP 97s
istio-galley ClusterIP 10.254.229.63 <none> 443/TCP,15014/TCP,9901/TCP 98s
istio-ingressgateway LoadBalancer 10.254.145.221 <pending> 15020:14115/TCP,80:31380/TCP,443:31390/TCP,31400:31400/TCP,15029:14870/TCP,15030:9447/TCP,15031:14863/TCP,15032:10432/TCP,15443:15781/TCP 97s
istio-pilot ClusterIP 10.254.92.10 <none> 15010/TCP,15011/TCP,8080/TCP,15014/TCP 97s
istio-policy ClusterIP 10.254.106.5 <none> 9091/TCP,15004/TCP,15014/TCP 97s
istio-sidecar-injector ClusterIP 10.254.35.98 <none> 443/TCP 97s
istio-telemetry ClusterIP 10.254.119.223 <none> 9091/TCP,15004/TCP,15014/TCP,42422/TCP 97s
jaeger-agent ClusterIP None <none> 5775/UDP,6831/UDP,6832/UDP 97s
jaeger-collector ClusterIP 10.254.167.118 <none> 14267/TCP,14268/TCP 97s
jaeger-query ClusterIP 10.254.10.189 <none> 16686/TCP 97s
kiali ClusterIP 10.254.19.166 <none> 20001/TCP 97s
prometheus ClusterIP 10.254.177.180 <none> 9090/TCP 97s
tracing ClusterIP 10.254.237.37 <none> 80/TCP 97s
zipkin ClusterIP 10.254.188.138 <none> 9411/TCP 97s$ kubectl get pods -n istio-system
NAME READY STATUS RESTARTS AGE
grafana-97fb6966d-7n2dn 1/1 Running 0 4m43s
istio-citadel-7c7c5f5c99-9ctwx 1/1 Running 0 4m43s
istio-cleanup-secrets-1.2.2-qnd5p 0/1 Completed 0 4m44s
istio-egressgateway-f7b8cc667-lfwx4 0/1 Running 0 4m43s
istio-galley-585fc86678-pkhzn 1/1 Running 0 4m43s
istio-grafana-post-install-1.2.2-76sgq 1/1 Running 1 4m44s
istio-ingressgateway-cfbf989b7-b8rx7 1/1 Running 0 4m43s
istio-pilot-68f587df5d-qjmf4 2/2 Running 0 4m43s
istio-policy-76cbcc4774-dlrvt 2/2 Running 6 4m43s
istio-security-post-install-1.2.2-t75bl 1/1 Running 1 4m44s
istio-sidecar-injector-97f9878bc-mfbvf 1/1 Running 0 4m42s
istio-telemetry-5f4575974c-gr8qw 2/2 Running 2 4m43s
istio-tracing-595796cf54-q5z9d 1/1 Running 0 4m42s
kiali-55fcfc86cc-8wr9t 1/1 Running 0 4m43s
prometheus-5679cb4dcd-jxn2x 1/1 Running 0 4m43s$ kubectl create namespace bookinfo
$ kubectl label namespace bookinfo istio-injection=enabled
$ kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml -n bookinfo$ kubectl get services -n bookinfo
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
details ClusterIP 10.254.254.166 <none> 9080/TCP 114s
productpage ClusterIP 10.254.59.59 <none> 9080/TCP 114s
ratings ClusterIP 10.254.245.84 <none> 9080/TCP 114s
reviews ClusterIP 10.254.37.253 <none> 9080/TCP 114s
$ kubectl get pods -n bookinfo
NAME READY STATUS RESTARTS AGE
details-v1-7964b4bb49-rzrs4 2/2 Running 0 45s
productpage-v1-6c668694dc-v6685 2/2 Running 0 45s
ratings-v1-7bb4dbd557-d44d5 2/2 Running 0 45s
reviews-v1-597f899bf6-fg6hh 2/2 Running 0 45s
reviews-v2-664994896d-694tw 2/2 Running 0 45s
reviews-v3-fc984656d-mx48l 2/2 Running 0 45s$ kubectl exec -it $(kubectl get pod -n bookinfo -l app=ratings -o jsonpath='{.items[0].metadata.name}') -n bookinfo -c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>$ kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml -n bookinfo$ kubectl get gateway -n bookinfo
NAME AGE
bookinfo-gateway 47s$ kubectl get svc istio-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.254.145.221 <pending> 15020:14115/TCP,80:31380/TCP,443:31390/TCP,31400:31400/TCP,15029:14870/TCP,15030:9447/TCP,15031:14863/TCP,15032:10432/TCP,15443:15781/TCP 60m$ export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
$ export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')
$ export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o 'jsonpath={.items[0].status.hostIP}')
$ export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT$ curl -s http://${GATEWAY_URL}/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>$ kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml -n bookinfokubectl get destinationrules -o yaml$ curl -o /dev/null -s -w "%{http_code}\n" http://${GATEWAY_URL}/productpage
200$ kubectl -n istio-system port-forward --address 0.0.0.0 $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 &$ kubectl -n istio-system get svc prometheus
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
prometheus ClusterIP 10.254.177.180 <none> 9090/TCP 3d2h
$ kubectl -n istio-system get svc grafana
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
grafana ClusterIP 10.254.33.222 <none> 3000/TCP 3d2h$ kubectl -n istio-system port-forward --address 0.0.0.0 $(kubectl -n istio-system get pod -l app=grafana -o jsonpath='{.items[0].metadata.name}') 3000:3000 &$ kubectl -n istio-system port-forward --address 0.0.0.0 $(kubectl -n istio-system get pod -l app=jaeger -o jsonpath='{.items[0].metadata.name}') 15032:16686$ kubectl -n istio-system get svc kiali
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kiali ClusterIP 10.254.19.166 <none> 20001/TCP 3d3h$ kubectl -n istio-system port-forward --address 0.0.0.0 $(kubectl -n istio-system get pod -l app=kiali -o jsonpath='{.items[0].metadata.name}') 20001:20001 &$ kubectl get virtualservices #-- there should be no virtual services
$ kubectl get destinationrules #-- there should be no destination rules
$ kubectl get gateway #-- there should be no gateway
$ kubectl get pods #-- the Bookinfo pods should be deleted$ kubectl delete gateway httpbin-gateway
$ kubectl delete virtualservice httpbin
$ kubectl delete --ignore-not-found=true -f samples/httpbin/httpbin.yamlfor i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl delete -f $i -n bookinfo ; donefor i in $(docker image ls | grep 1.2.0 | cut -f 1 -d " "); do docker rmi $i:1.2.0 ;done