k8s搭建链路监控:skywalking

skywalking架构及简介

官网:https://github.com/apache/skywalking

k8s搭建链路监控:skywalking_第1张图片

简介

Java, .NET Core, NodeJS, PHP, and Python auto-instrument agents.
Go and C++ SDKs.
LUA agent especially for Nginx, OpenResty and Apache APISIX.
Browser agent.
Service Mesh Observability. Control panel and data panel.
Metrics system, including Prometheus, OpenTelemetry, Spring Sleuth(Micrometer), Zabbix.
Logs.
Zipkin v1/v2 trace.(No Analysis)

编写OAP和UI资源文件

其中,使用的镜像:

apache/skywalking-oap-server:8.6.0-es7
apache/skywalking-ui:8.6.0
apiVersion: v1
kind: Service
metadata:
  name: ui
  namespace: skywalking
  labels:
    service: ui
spec:
  ports:
  - port: 8080
    name: page
    nodePort: 30123
  selector:
    app: ui
  type: NodePort

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ui-deployment
  namespace: skywalking
  labels:
    app: ui
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ui
  template:
    metadata:
      labels:
        app: ui
    spec:
      containers:
      - name: ui
        image: 192.168.117.160/apache/skywalking-ui:8.6.0
        imagePullPolicy: IfNotPresent
        ports:
          - name: page
            containerPort: 8080
        env:
          - name: SW_OAP_ADDRESS
            value: oap:12800

部署OAP和UI

创建名称空间:kubectl create ns skywalking
查看名称空间:kubectl get ns
应用资源文件:kubectl apply -f .
看名称空间下所有资源:kubectl get all -n skywalking
k8s搭建链路监控:skywalking_第2张图片
可以看日志是否正常(端口是否ok):kubectl logs pod/oap-9d459674b-8vndj -n skywalking

使用skywalking agent

这里,我们不修改服务镜像,通过共享volumes的方式,使agent能被服务镜像访问并使用

下载镜像:skywalking-agent-sidecar:v1.0

推送到本地镜像仓库

资源yaml文件中,添加初始化容器

      initContainers:
      - image: 192.168.117.160/skywalking/skywalking-agent-sidecar:v1.0
        name: sw-agent-sidecar
        imagePullPolicy: IfNotPresent
        command: ["sh"]
        args:
          [
            "-c",
            "mkdir -p /skywalking/agent && cp -r /usr/skywalking/agent/* /skywalking/agent",
          ]
        volumeMounts:
        - mountPath: /skywalking/agent
          name: sw-agent

资源yaml文件中,服务容器添加环境变量和volumeMounts

 env:
        - name: JAVA_OPTS
          value: -javaagent:/usr/skywalking/agent/skywalking-agent.jar

volumeMounts:
        - mountPath: /usr/skywalking/agent
          name: sw-agent

部署服务,这样,服务启动的时候,就会加上上面的变量

进入容器:kubectl exec -it product-78fcbdfd6b-mv2hl -n mm -- sh

可以看到,服务容器的目录下有skywalking-agent.jar

top查看进程

访问

http://192.168.117.162:30123/
k8s搭建链路监控:skywalking_第3张图片

k8s搭建链路监控:skywalking_第4张图片

skywalking更多使用

详见:https://www.cnblogs.com/uncleyong/p/15752370.html

【性能项目实战:jmeter+k8s+微服务+skywalking+efk】汇总

详见:https://www.cnblogs.com/uncleyong/p/15475614.html

你可能感兴趣的:(kubernetes,skywalking,容器,云原生)