ASM不仅支持向阿里云链路追踪服务导出链路追踪数据,同样也支持向您自建的兼容Zipkin协议的系统导出追踪数据,本文介绍如何对ASM进行配置,将追踪数据导出至您的自建系统。
前提条件
- 该自建系统支持标准Zipkin协议,并通过标准Zipkin端口9411监听。若您使用Jaeger,则需要部署Zipkin Collector。
- 该自建系统部署于数据面集群内。
- 已创建一个ACK实例并添加到ASM实例中,请参见添加集群到ASM实例。
- ASM实例部署了入口网关,请参见添加入口网关服务。
步骤一:为集群启用链路追踪
- 登录ASM控制台。
- 在左侧导航栏,选择。
- 在网格管理页面,找到待配置的实例,单击实例的名称或在操作列中单击管理。
- 在网格详情页面左侧导航栏选择,然后在右侧页面单击功能设置。
- 在功能设置更新的面板中,选中启用链路追踪,并选择自行搭建Zipkin。
- 单击确定。
步骤二:在数据面集群部署Zipkin
- 将下面的YAML保存为文件zipkin-server.yaml。
apiVersion: apps/v1
kind: Deployment
metadata:
name: zipkin-server
namespace: istio-system
spec:
replicas: 1
selector:
matchLabels:
app: zipkin-server
component: zipkin
template:
metadata:
labels:
app: zipkin-server
component: zipkin
spec:
containers:
- name: zipkin-server
image: openzipkin/zipkin
imagePullPolicy: IfNotPresent
readinessProbe:
httpGet:
path: /health
port: 9411
initialDelaySeconds: 5
periodSeconds: 5
说明 如果您需要使用自行准备的追踪系统YAML文件部署,请确保Deployment处在istio-system namespace下。
- 执行以下命令,将该配置应用到数据面集群。
kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} apply -f zipkin-server.yaml
注意 本文中的${DATA_PLANE_KUBECONFIG}应当替换为数据面集群的Kubeconfig文件路径,${ASM_KUBECONFIG}应当替换为网格实例的Kubeconfig文件路径。
- 部署完毕后确认ZipkinServer Pod正常启动。
步骤三:创建Service暴露ZipkinServer
您需要在istio-system namespace下创建名为zipkin的服务,来接收ASM的链路追踪信息或访问该服务。若需要将Zipkin暴露于公网,请使用zipkin-svc-expose-public.yaml;若不希望暴露于公网,请使用zipkin-svc.yaml。为了便于查看追踪数据,本示例使用zipkin-svc-expose-public.yaml将Zipkin
Server暴露于公网端口。
- 将下面的内容保存为YAML文件。
- 若需要将Zipkin暴露于公网,请使用zipkin-svc-expose-public.yaml,文件内容如下:
apiVersion: v1
kind: Service
metadata:
labels:
app: tracing
component: zipkin
name: zipkin
namespace: istio-system
spec:
ports:
- name: zipkin
port: 9411
protocol: TCP
targetPort: 9411
selector:
app: zipkin-server
component: zipkin
type: LoadBalancer
- 若不希望暴露于公网,请使用zipkin-svc.yaml,文件内容如下:
apiVersion: v1
kind: Service
metadata:
labels:
app: tracing
component: zipkin
name: zipkin
namespace: istio-system
spec:
ports:
- name: zipkin
port: 9411
protocol: TCP
targetPort: 9411
selector:
app: zipkin-server
component: zipkin
type: ClusterIP
说明 如果您需要使用自行准备的YAML文件部署Service,请确保Service处在istio-system namespace下。
- 执行以下命令将Zipkin Service应用到数据面集群。
#部署内网zipkin。
kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} apply -f zipkin-svc.yaml
#部署公网可以访问的zipkin。
kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} apply -f zipkin-svc-expose-public.yaml
步骤四:部署测试应用BookInfo
- 通过Kubectl执行以下命令,将Bookinfo应用部署到数据面集群中。
kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} apply -f bookinfo.yaml
bookinfo.yaml文件内容如下:
apiVersion: v1
kind: Service
metadata:
name: details
labels:
app: details
service: details
spec:
ports:
- port: 9080
name: http
selector:
app: details
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: bookinfo-details
labels:
account: details
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: details-v1
labels:
app: details
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: details
version: v1
template:
metadata:
labels:
app: details
version: v1
spec:
serviceAccountName: bookinfo-details
containers:
- name: details
image: docker.io/istio/examples-bookinfo-details-v1:1.16.2
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9080
---
##################################################################################################
# Ratings service
##################################################################################################
apiVersion: v1
kind: Service
metadata:
name: ratings
labels:
app: ratings
service: ratings
spec:
ports:
- port: 9080
name: http
selector:
app: ratings
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: bookinfo-ratings
labels:
account: ratings
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ratings-v1
labels:
app: ratings
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: ratings
version: v1
template:
metadata:
labels:
app: ratings
version: v1
spec:
serviceAccountName: bookinfo-ratings
containers:
- name: ratings
image: docker.io/istio/examples-bookinfo-ratings-v1:1.16.2
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9080
---
##################################################################################################
# Reviews service
##################################################################################################
apiVersion: v1
kind: Service
metadata:
name: reviews
labels:
app: reviews
service: reviews
spec:
ports:
- port: 9080
name: http
selector:
app: reviews
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: bookinfo-reviews
labels:
account: reviews
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: reviews-v1
labels:
app: reviews
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: reviews
version: v1
template:
metadata:
labels:
app: reviews
version: v1
spec:
serviceAccountName: bookinfo-reviews
containers:
- name: reviews
image: docker.io/istio/examples-bookinfo-reviews-v1:1.16.2
imagePullPolicy: IfNotPresent
env:
- name: LOG_DIR
value: "/tmp/logs"
ports:
- containerPort: 9080
volumeMounts:
- name: tmp
mountPath: /tmp
- name: wlp-output
mountPath: /opt/ibm/wlp/output
volumes:
- name: wlp-output
emptyDir: {}
- name: tmp
emptyDir: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: reviews-v2
labels:
app: reviews
version: v2
spec:
replicas: 1
selector:
matchLabels:
app: reviews
version: v2
template:
metadata:
labels:
app: reviews
version: v2
spec:
serviceAccountName: bookinfo-reviews
containers:
- name: reviews
image: docker.io/istio/examples-bookinfo-reviews-v2:1.16.2
imagePullPolicy: IfNotPresent
env:
- name: LOG_DIR
value: "/tmp/logs"
ports:
- containerPort: 9080
volumeMounts:
- name: tmp
mountPath: /tmp
- name: wlp-output
mountPath: /opt/ibm/wlp/output
volumes:
- name: wlp-output
emptyDir: {}
- name: tmp
emptyDir: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: reviews-v3
labels:
app: reviews
version: v3
spec:
replicas: 1
selector:
matchLabels:
app: reviews
version: v3
template:
metadata:
labels:
app: reviews
version: v3
spec:
serviceAccountName: bookinfo-reviews
containers:
- name: reviews
image: docker.io/istio/examples-bookinfo-reviews-v3:1.16.2
imagePullPolicy: IfNotPresent
env:
- name: LOG_DIR
value: "/tmp/logs"
ports:
- containerPort: 9080
volumeMounts:
- name: tmp
mountPath: /tmp
- name: wlp-output
mountPath: /opt/ibm/wlp/output
volumes:
- name: wlp-output
emptyDir: {}
- name: tmp
emptyDir: {}
---
##################################################################################################
# Productpage services
##################################################################################################
apiVersion: v1
kind: Service
metadata:
name: productpage
labels:
app: productpage
service: productpage
spec:
ports:
- port: 9080
name: http
selector:
app: productpage
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: bookinfo-productpage
labels:
account: productpage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: productpage-v1
labels:
app: productpage
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: productpage
version: v1
template:
metadata:
labels:
app: productpage
version: v1
spec:
serviceAccountName: bookinfo-productpage
containers:
- name: productpage
image: docker.io/istio/examples-bookinfo-productpage-v1:1.16.2
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9080
volumeMounts:
- name: tmp
mountPath: /tmp
volumes:
- name: tmp
emptyDir: {}
---
- 通过Kubectl执行以下命令,部署Bookinfo应用的VirtualServices。
kubectl --kubeconfig=${ASM_KUBECONFIG} apply -f virtual-service-all-v1.yaml
virtual-service-all-v1.yaml文件内容如下:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: productpage
spec:
hosts:
- productpage
http:
- route:
- destination:
host: productpage
subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- route:
- destination:
host: reviews
subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ratings
spec:
hosts:
- ratings
http:
- route:
- destination:
host: ratings
subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: details
spec:
hosts:
- details
http:
- route:
- destination:
host: details
subset: v1
---
- 通过Kubectl执行以下命令,部署Bookinfo应用的DestinationRules。
kubectl --kubeconfig=${ASM_KUBECONFIG} apply -f destination-rule-all.yaml
destination-rule-all.yaml文件内容如下:
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: productpage
spec:
host: productpage
subsets:
- name: v1
labels:
version: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: reviews
spec:
host: reviews
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
- name: v3
labels:
version: v3
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: ratings
spec:
host: ratings
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
- name: v2-mysql
labels:
version: v2-mysql
- name: v2-mysql-vm
labels:
version: v2-mysql-vm
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: details
spec:
host: details
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
---
- 通过Kubectl执行以下命令,部署Bookinfo应用的Gateway。
kubectl --kubeconfig=${ASM_KUBECONFIG} apply -f bookinfo-gateway.yaml
bookinfo-gateway.yaml文件内容如下:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- "*"
gateways:
- bookinfo-gateway
http:
- match:
- uri:
exact: /productpage
- uri:
prefix: /static
- uri:
exact: /login
- uri:
exact: /logout
- uri:
prefix: /api/v1/products
route:
- destination:
host: productpage
port:
number: 9080
步骤五:产生追踪数据
- 执行以下命令,获得入口网关地址。
kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} get svc -n istio-system|grep ingressgateway|awk -F ' ' '{print $4}'
- 使用地址
入口网关地址/productpage
访问Bookinfo应用。
步骤六:查看链路追踪数据
- 执行下列命令获取Zipkin Service地址。
kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} get svc -n istio-system|grep zipkin|awk -F ' ' '{print $4}'
- 使用
Zipkin Service地址:9411
,访问Zipkin控制台,查看追踪数据。