目录

kubernetes监控-Skywalking9.x部署

部署 Skywalking9.x ,对服务进行链路追踪.

动机

新公司业务部门一直对服务没有有效的链路监控措施,服务响应出现问题,需要排查的时候无从下手,于是打算给他们部署一套skywalking,对服务进行链路追踪。

部署es

es 我们采用单节点部署,es单节点部署

修改配置

git clone https://github.com/apache/skywalking-helm.git

修改 value.yaml 几个关键字段

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 修改 es 分片数量,节省磁盘,修改lb地址类型
oap:
...
  env: 
    SW_STORAGE_ES_SUPER_DATASET_INDEX_SHARDS_FACTOR: 1
  ...
  service:
    type: LoadBalancer
    annotations: 
      networking.gke.io/load-balancer-type: "Internal"
      networking.gke.io/internal-load-balancer-allow-global-access: "true"
...

# 修改es配置
elasticsearch:
  enabled: false
  config: 
    port:
      http: 9200
    host: 10.xx.xx.xx
    user: "elastic"
    password: "xxx"
...

# 启用satellite做负载
satellite:
  name: satellite
  replicas: 1
  enabled: true
...

部署skywalking

部署

helm install skywalking oci://registry-1.docker.io/apache/skywalking-helm --version 4.5.0 -n skywalking -f values.yaml

升级

helm upgrade skywalking oci://registry-1.docker.io/apache/skywalking-helm --version 4.5.0 -n skywalking -f values.yaml

demo

我们懒得去改基础镜像了,这里是通过 sidecar 的方式把 agent 打进去的。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: your-demo
  name: your-demo
  namespace: yixiu-dev
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: your-demo
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: your-demo
    spec:
      affinity: {}
      containers:
        - env:
            - name: APP_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.labels['app']
            - name: GROUP_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: SW_AGENT_NAME
              value: ${GROUP_NAME}::${APP_NAME}
            - name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
              value: skywalking-skywalking-helm-satellite.skywalking.svc:11800
            - name: SKYWALKING_OPTS
              value: '-javaagent:/opt/tools/sw-agent/skywalking-agent.jar'
          image: >-
            192.168.2.221:80/center/your-demo:base-3.21.1.0-dev-20241017030932            
          imagePullPolicy: Always
          volumeMounts:
            - mountPath: /opt/tools/sw-agent
              name: skywalking-agent
          name: your-demo
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      initContainers:
        - args:
            - '-c'
            - cp -R /skywalking/agent/* /opt/tools/sw-agent/
          command:
            - /bin/sh
          image: 192.168.2.221:80/devops/skywalking-java-agent:9.3.0-alpine
          imagePullPolicy: IfNotPresent
          name: agent-container
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /opt/tools/sw-agent
              name: skywalking-agent
      volumes:
        - emptyDir: {}
          name: skywalking-agent
      imagePullSecrets:
        - name: registry-pull-secret
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 60
--- 
apiVersion: v1
kind: Service
metadata:
  name: your-demo-svc
  namespace: yixiu-dev
spec:
  externalTrafficPolicy: Cluster
  internalTrafficPolicy: Cluster
  ipFamilies:
    - IPv4
  ipFamilyPolicy: SingleStack
  ports:
    - name: http-8080
      port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    app: your-demo
  sessionAffinity: None
  type: NodePort