1. 结构采用, pod中植入 agent, 传输到 172.16.230.29:11800, es 使用docker部署,版本es7
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.5.2
2. 下载 skywaking
wget https://mirrors.tuna.tsinghua.edu.cn/apache/skywalking/7.0.0/apache-skywalking-apm-es7-7.0.0.tar.gz
3. 修改存储,使用 es7
4. 启动
#注意要在es启动后,在启动skywalking
[root@harbor apache-skywalking-apm-bin-es7]# bin/startup.sh
5. 客户端配置,通过 dockerfile 和 comfigmap 使用
[root@harbor jar]# cat Dockerfile FROM IMAGE MAINTAINER fengjian <fengjian@senyint.com.com> RUN mkdir /data/webserver -p ADD start.sh /data/webserver/ COPY agent /data/agent RUN chmod +x /data/webserver/start.sh && sed -i "s/Your_ApplicationName/jenkins/g" /data/agent/config/agent.config ADD jenkins.jar /data/webserver/ EXPOSE containerport ENTRYPOINT ["/data/webserver/start.sh"]
[root@harbor jar]# cat start.sh #!/bin/sh
# JAVA_HOME export JAVA_HOME=/data/jdk # 设置项目代码路径 export _EXECJAVA="$JAVA_HOME/bin/java" #jar包 名称 JAVANAME=`ls /data/webserver/*jar` # 启动 $_EXECJAVA ${JAVA_OPT} -jar $JAVANAME
k8s中部署应用 和 nacos, nacos的yaml为
[root@master1 senyint]# cat nacos-quick-start.yaml --- apiVersion: v1 kind: Service metadata: namespace: senyint name: nacos labels: app: nacos spec: type: NodePort ports: - port: 8848 name: server targetPort: 8848 selector: app: nacos --- apiVersion: v1 kind: ConfigMap metadata: namespace: senyint name: nacos-cm data: mysql.db.name: "nacos_devtest" mysql.port: "3306" mysql.user: "nacos" mysql.password: "nacos" --- apiVersion: apps/v1 kind: StatefulSet metadata: namespace: senyint name: nacos spec: serviceName: nacos replicas: 3 template: metadata: labels: app: nacos annotations: pod.alpha.kubernetes.io/initialized: "true" spec: initContainers: - name: sidecar image: 172.16.230.29/senyint/skywalking-agent:202004101053 imagePullPolicy: Always command: ["sh", "-c", "cp -r /data/agent /sidecar"] volumeMounts: - name: sidecar mountPath: /sidecar affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: "app" operator: In values: - nacos topologyKey: "kubernetes.io/hostname" containers: - name: k8snacos imagePullPolicy: Always image: nacos/nacos-server:latest resources: requests: memory: "2Gi" cpu: "500m" ports: - containerPort: 8848 name: client volumeMounts: - name: sidecar mountPath: /sidecar env: - name: JAVA_OPT value: -javaagent:/sidecar/agent/skywalking-agent.jar - name: NACOS_REPLICAS value: "3" - name: MYSQL_SERVICE_DB_NAME valueFrom: configMapKeyRef: name: nacos-cm key: mysql.db.name - name: MYSQL_SERVICE_PORT valueFrom: configMapKeyRef: name: nacos-cm key: mysql.port - name: MYSQL_SERVICE_USER valueFrom: configMapKeyRef: name: nacos-cm key: mysql.user - name: MYSQL_SERVICE_PASSWORD valueFrom: configMapKeyRef: name: nacos-cm key: mysql.password - name: NACOS_SERVER_PORT value: "8848" - name: PREFER_HOST_MODE value: "hostname" - name: NACOS_SERVERS value: "nacos-0.nacos.senyint.svc.cluster.local.:8848 nacos-1.nacos.senyint.svc.cluster.local.:8848 nacos-2.nacos.senyint.svc.cluster.local.:8848" volumes: - name: sidecar #共享agent文件夹 emptyDir: {} restartPolicy: Always selector: matchLabels: app: nacos
使用initcontainers 共享磁盘空间, 172.16.230.29/senyint/skywalking-agent:202004101053, 启动ssh,agent 在 /data目录中,
k8s pod中,通过引用 env 环境变量 JAVA_OPT 引入
环境变量配置:
参考
https://skywalking.apache.org/downloads/
https://github.com/evanxuhe/skywalking-kubernetes/tree/master/6.1.0/apm-springcloud-demo