1、k8s中安装部署 skywalking
skywalking集群情况下需要保证用同一数据源,这里我们存储方式改为es
1.1 部署elasticsearch
docker run -it -d -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -e "discovery.type=single-node" elasticsearch:7.14.2
1.2 创建skywalking-oap的yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: skywalking-oap
namespace: default
labels:app: skywalking-oap
spec:replicas:1selector:matchLabels:app: skywalking-oap
template:metadata:labels:app: skywalking-oap
spec:containers:-env:-name: SW_STORAGE
value: elasticsearch7 ##存储方式-name: SW_STORAGE_ES_CLUSTER_NODES
value: 10.0.24.5:9200##es地址name: skywalking-oap
image: apache/skywalking-oap-server:8.4.0-es7 ##镜像imagePullPolicy: IfNotPresent ##如果存在就不拉去取ports:-containerPort:11800name: grpc
-containerPort:12800name: rest
---apiVersion: v1
kind: Service
metadata:name: skywalking-oap
namespace: default
labels:service: skywalking-oap
spec:ports:-port:12800name: rest
-port:11800name: grpc
selector:app: skywalking-oap
1.3 创建skywalking-ui的yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: skywalking-ui
namespace: default
labels:app: skywalking-ui
spec:replicas:1selector:matchLabels:app: skywalking-ui
template:metadata:labels:app: skywalking-ui
spec:containers:-name: skywalking-ui
image: apache/skywalking-ui:8.4.0
ports:-containerPort:8080name: page
env:-name: SW_OAP_ADDRESS
value: skywalking-oap:12800##skywalking-oap监听端口---apiVersion: v1
kind: Service
metadata:name: skywalking-ui
namespace: default
labels:service: skywalking-ui
spec:ports:-port:8080name: page
nodePort:30200type: NodePort
selector:app: skywalking-ui
1.3 k8s中部署 skywalking-oap.yaml、skywalking-ui.yaml
kubectl create -f skywalking-oap.yaml
kubectl create -f skywalking-ui.yaml
1.4 查看skywalking-ui
2、部署项目使用skywalking进行链路追踪
2.1 下载 skywalking-agent
https://skywalking.apache.org/downloads/#Agents
2.2 idea 中使用skywalking-agent
2.2.1 创建项目server-order 并创建web控制层
@RestControllerpublicclassOrderController{@GetMapping("/getuuid")publicStringgetuuid(){String uuid = UUID.randomUUID().toString().replace("-","");return uuid;}}
2.2.2 创建项目web-monitor 并创建feign和monitor的控制层
@FeignClient(value ="server-order")@ComponentpublicinterfaceOrderService{@GetMapping("/getuuid")publicStringgetuuid();}
@RestControllerpublicclassMonitorController{@AutowiredprivateOrderService orderService;@GetMapping("send")publicStringsend(){String getuuid = orderService.getuuid();return getuuid;}}
2.2.3 增加环境变量
-javaagent:D:\opts\apache-skywalking-java-agent-8.8.0\skywalking-agent\skywalking-agent.jar
-Dskywalking.collector.backend_service=ip地址:端口
-Dskywalking.agent.service_name=服务名称
2.2.3 查看skywalking-ui链路
2.3 k8s 部署项目增加skywalking链路追踪
2.3.1 构建镜像
FROM java:8
WORKDIR /project
ENV JAVA_OPTS=""
ENV SKYWALKING_OPTS=""
CPOY skywalking-agent.jar skywalking-agent.jar
COPY web-monitor.jar web-monitor.jar
ENTRYPOINT ["sh","-c","java -jar ${JAVA_OPTS} web-monitor.jar ${SKYWALKING_OPTS} "]
2.3.2 创建k8s无状态服务
apiVersion: extensions/v1beta1 #版本kind: Deployment #资源类型metadata:labels:workload.user.cattle.io/workloadselector: deployment-cloud-web-monitor #标签,k8s对于资源控制主要是根据labels和selector进行的name: web-monitor #资源名称namespace: deafult #所属命名空间spec:progressDeadlineSeconds:600replicas:1#一个podrevisionHistoryLimit:10selector:matchLabels:workload.user.cattle.io/workloadselector: deployment-cloud-web-monitor
strategy:rollingUpdate:maxSurge:1maxUnavailable:0type: RollingUpdate #发布策略template:#创建模板metadata:labels:workload.user.cattle.io/workloadselector: deployment-cloud-web-monitor
spec:containers:-env:-name: JAVA_OPTS
value:-Xmx3550M -Xms3550M -Xmn2G -Xss256k
-name: SKYWALKING_OPTS
value:-javaagent:./skywalking-agent.jar -Dskywalking.agent.service_name=web-monitor -Dskywalking.collector.backend_service=skywalking-oap:11800image: 192.1.1.1/project/web-monitor:stable #镜像imagePullPolicy: Always #镜像拉取策略name: web-monitor #容器名称ports:-containerPort:8513#暴露端口name: 8513tcp02
protocol: TCP
resources:limits:memory: 4Gi
stdin:trueterminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
tty:truevolumeMounts:-mountPath: /log #容器内部挂载位置name: vol1
dnsPolicy: ClusterFirst
restartPolicy: Always #重启策略schedulerName: default-scheduler
securityContext:{}terminationGracePeriodSeconds:30volumes:-name: vol1
persistentVolumeClaim:#挂载的pvcclaimName: log-pvc
2.3.3 注意点
在上边的镜像中 将skywalking-agent.jar 拷贝到镜像里,这一步可以使用pv挂载,另外也可以将skywalking-agent用initc来做链路追踪
本文转载自: https://blog.csdn.net/weixin_47752736/article/details/129461888
版权归原作者 方圆师兄 所有, 如有侵权,请联系我们删除。
版权归原作者 方圆师兄 所有, 如有侵权,请联系我们删除。