Service Mesh 的中文译为“服务网格”,是一个用于处理服务和服务之间通信的基础设施层,它负责为构建复杂的云原生应用传递可靠的网络请求,并为服务通信实现了微服务所需的基本组件功能,例如服务发现、负载均衡、监控、流量管理、访问控制等。在实践中,服务网格通常实现为一组和应用程序部署在一起的轻量级的网络代理,但对应用程序来说是透明的。
wgethttps://github.com/istio/istio/releases/download/1.4.2/istio-1.4.2-linux.tar.gztarzxvfistio-1.4.2-linux.tar.gzcdistio-1.4.2mvbin/istioctl/usr/binistioctlprofilelististioctlmanifestapply--setprofile=demoistioctlmanifestgenerate--setprofile=demo#获取yamlistioctlmanifestgenerate--setprofile=demo|kubectldelete-f-#卸载查看运行成功# kubectl get pod -n istio-systemNAMEREADYSTATUSRESTARTSAGEgrafana-6b65874977-crbm91/1Running04m13sistio-citadel-86dcf4c6b-6qg8f1/1Running04m17sistio-egressgateway-68f754ccdd-vgnnt1/1Running04m20sistio-galley-5fc6d6c45b-ckqhs1/1Running04m13sistio-ingressgateway-6d759478d8-w29kh1/1Running04m17sistio-pilot-5c4995d687-phbtd1/1Running04m21sistio-policy-57b99968f-mbxjg1/1Running54m24sistio-sidecar-injector-746f7c7bbb-f4jmv1/1Running04m13sistio-telemetry-854d8556d5-s59481/1Running44m18sistio-tracing-c66d67cd9-2btc91/1Running04m18skiali-8559969566-npcrl1/1Running04m22sprometheus-66c5887c86-wbftc1/1Running04m17s
Sidercar 注入
部署httpbin Web示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 手动注入
kubectl apply -f <(istioctl kube-inject -f httpbin-nodeport.yaml)
或者
istioctl kube-inject -f httpbin-nodeport.yaml|kubectl apply -f -
# 自动注入
kubectl label namespace default istio-injection=enabled
kubectl apply -f httpbin-gateway.yaml
# kubectl get pod
NAME READY STATUS RESTARTS AGE
httpbin-5c8ff7878b-jtp8d 2/2 Running 0 4m44s
# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
httpbin NodePort 10.0.0.8 <none> 8000:31378/TCP 23m
NodePort访问地址:http://192.168.0.134:31378
1
2
3
4
5
6
7
8
9
10
11
[root@k8s-master httpbin]# kubectl apply -f httpbin-gateway.yaml
gateway.networking.istio.io/httpbin-gateway created
virtualservice.networking.istio.io/httpbin created
[root@k8s-master httpbin]# kubectl get gateway
NAME AGE
httpbin-gateway 46s
[root@k8s-master httpbin]# kubectl get virtualservice
NAME GATEWAYS HOSTS AGE
httpbin [httpbin-gateway] [*] 73s
[root@k8s-master httpbin]# kubectl get svc -n istio-system |grep ingress
istio-ingressgateway LoadBalancer 10.0.0.159 <pending> 15020:30192/TCP,80:31025/TCP,443:30335/TCP,15029:31780/TCP,15030:30496/TCP,15031:30126/TCP,15032:32066/TCP,15443:32306/TCP 142m