k8s 中 skywalking 链路监控(nacos 及服务部署)部署使用
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 配置,通过 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
agent image dockerfile
172.16.230.29/senyint/skywalking-agent:202004101053
FROM centos:centos7.7.1908
RUN yum -y install wget \
&& rm -rf /etc/yum.repos.d/* \
&& cd /etc/yum.repos.d/ \
&& wget http://mirrors.aliyun.com/repo/Centos-7.repo \
&& wget http://mirrors.aliyun.com/repo/epel-7.repo \
&& yum clean all \
&& yum install -y openssh-server openssh* openssl \
&& sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config \
&& sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config \
&& ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key \
&& ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key \
&& mkdir /var/run/sshd
COPY agent /data/agent
ADD localtime /etc/localtime
WORKDIR /root/
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
k8s中部署nacos,agent直接通过env 引入,
使用initcontainers 共享磁盘空间, 172.16.230.29/senyint/skywalking-agent:202004101053, 启动ssh,agent 在 /data目录中,
nacos的yaml为
--- apiVersion: v1 kind: Service metadata: namespace: senyint name: nacos-headless labels: app: nacos-headless spec: ports: - port: 8848 name: server targetPort: 8848 clusterIP: None 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-headless replicas: 3 template: metadata: labels: app: nacos annotations: pod.alpha.kubernetes.io/initialized: "true" spec: initContainers: - name: sidecar image: 172.16.230.84/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-headless topologyKey: "kubernetes.io/hostname" serviceAccountName: nfs-ssd-provisioner containers: - name: k8snacos imagePullPolicy: Always image: 172.16.230.84/source/nacos-server:1.2.1 #image: 172.16.91.64/source/nacos-server:latest resources: requests: memory: "2Gi" cpu: "500m" ports: - containerPort: 8848 name: client 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-headless.senyint.svc.cluster.local.:8848 nacos-1.nacos-headless.senyint.svc.cluster.local.:8848 nacos-2.nacos-headless.senyint.svc.cluster.local.:8848" volumeMounts: - name: datadir mountPath: /home/nacos/data - name: logdir mountPath: /home/nacos/logs - name: sidecar mountPath: /sidecar volumes: - name: sidecar #共享agent文件夹 emptyDir: {} volumeClaimTemplates: - metadata: name: datadir namespace: senyint annotations: volume.beta.kubernetes.io/storage-class: "managed-nfs-ssd" spec: accessModes: [ "ReadWriteMany" ] resources: requests: storage: 100Gi - metadata: name: logdir namespace: senyint annotations: volume.beta.kubernetes.io/storage-class: "managed-nfs-ssd" spec: accessModes: [ "ReadWriteMany" ] resources: requests: storage: 100Gi selector: matchLabels: app: nacos
k8s pod中,通过引用 env 环境变量 JAVA_OPT 引入
环境变量配置:
################################################################################################
使用mysql作为存储
需要下载mysql驱动包到 /data/skywalking/oap-libs/目录下
https://dev.mysql.com/downloads/connector/j/5.1.html
修复 使用mysql bug, entity_id 字符数量太小
alter table endpoint_relation_server_side modify column entity_id varchar(512) DEFAULT NULL;
参考
https://skywalking.apache.org/downloads/
https://github.com/apache/skywalking/blob/v8.0.1/docs/en/setup/service-agent/java-agent/README.md
https://github.com/evanxuhe/skywalking-kubernetes/tree/master/6.1.0/apm-springcloud-demo
https://github.com/apache/skywalking/blob/v8.0.1/docs/en/setup/service-agent/java-agent/README.md