本文主要是介绍【SkyWalking】使用PostgreSQL做存储K8s部署,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
拉取镜像
docker pull apache/skywalking-ui:10.0.1
docker tag apache/skywalking-ui:10.0.1 xxx/xxx/skywalking-ui:10.0.1
docker push xxx/xxx/skywalking-ui:10.0.1docker pull apache/skywalking-oap-server:10.0.1
docker tag apache/skywalking-oap-server:10.0.1 xxx/xxx/skywalking-oap-server:10.0.1
docker push xxx/xxx/skywalking-oap-server:10.0.1
源码制作镜像
# 拉取源码
git clone -b v10.0.1 https://github.com/apache/skywalking.git
# 进入源码目录
cd skywalking# 为了提高maven依赖下载速度,需要在~/.m2目录下创建settings.xml文件
# 修改settings.xml文件,指定私服nexus地址# 必须指定JAVA_HOME变量
export JAVA_HOME=/home/xxx/镜像制作/jdk-17.0.2
# 运行制作镜像脚本
nohup make docker SKIP_TEST=true OAP_NAME=skywalking-oap-server UI_NAME=skywalking-ui HUB=xxx/xxx TAG=10.0.1 &
# 查看制作的镜像
docker image ls | grep skywalking
官网下载程序包制作镜像
# 下载可直接运行的程序包
wget https://dlcdn.apache.org/skywalking/10.0.1/apache-skywalking-apm-10.0.1.tar.gz# 解压&编写Dockerfile&编写构建脚本
[root@k8s1 skywalking]# ll
total 8
drwxr-xr-x 9 root root 201 Jun 7 18:09 apache-skywalking-apm-bin
-rwxr-xr-x 1 root root 317 Jun 7 18:18 docker-build.sh
-rw-r--r-- 1 root root 2604 Jun 7 18:42 Dockerfile
Dockerfile
Dockerfile核心内容如下
FROM xxx/xxx/openjdk-utils:17.0.2
# 维护者
MAINTAINER best572@sina.com# 解决时区问题
ENV TIME_ZONE="Asia/Shanghai"
RUN ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && echo $TIME_ZONE > /etc/timezone# sleep几秒后,logs目录下才会有日志文件
ENTRYPOINT cd apache-skywalking-apm-bin/bin && ./startup.sh &&\pwd && sleep 10 && ls ../logs &&\tail -fn200 ../logs/skywalking-oap-server.log
构建脚本
version=10.0.1
APP_NAME=skywalking-${version}# 删除旧镜像
#docker rmi -f xxx/xxx/skywalking:$version
# 构建镜像
docker build -t xxx/xxx/skywalking:$version .
docker push xxx/xxx/skywalking:$version
数据库
初始化PostgreSQL数据库
CREATE DATABASE "skywalking" WITH ENCODING = 'UTF8' CONNECTION LIMIT = -1 IS_TEMPLATE = False;
CREATE ROLE skywalking WITH LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOREPLICATION NOBYPASSRLS CONNECTION LIMIT -1 PASSWORD 'skywalking';
COMMENT ON ROLE skywalking IS 'skywalking';
GRANT ALL PRIVILEGES ON DATABASE "skywalking" TO skywalking;
GRANT ALL ON SCHEMA PUBLIC TO skywalking;
k8s部署SkyWalking
kubectl apply -f skywalking.yaml
skywalking.yaml
如下
---
apiVersion: v1
kind: Service
metadata:name: skywalkingnamespace: kube-publiclabels:app: skywalking
spec:type: NodePortports:- name: oap-httpport: 12800targetPort: 12800nodePort: 12800- name: grpcport: 11800targetPort: 11800nodePort: 11800- name: ui-httpport: 22800targetPort: 8080nodePort: 22800selector:app: skywalking
---
apiVersion: apps/v1
kind: Deployment
metadata:name: skywalkingnamespace: kube-public
spec:replicas: 1revisionHistoryLimit: 0 #Replica Sets中的历史数量selector:matchLabels:app: skywalkingtemplate:metadata:labels:app: skywalkingspec:# 第一次运行的时候初始化一次
# initContainers:
# - name: oap-init
# image: xxx/xxx/skywalking:10.0.1
# imagePullPolicy: Always
# command: [ "sh" ]
# args: ["-c","pwd && ls -lhrt && cd apache-skywalking-apm-bin/bin && ./oapServiceInit.sh && pwd && sleep 10 && ls ../logs"]containers:- name: skywalkingimagePullPolicy: Alwaysimage: xxx/xxx/skywalking:10.0.1# 导入环境变量envFrom:# 使用configMap- configMapRef:# name为configMap中的metadata namename: app-public-cm- secretRef:name: app-public-secretenv:- name: POD_IPvalueFrom:fieldRef:fieldPath: status.podIP- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: SW_STORAGEvalue: "postgresql"- name: SW_JDBC_URLvalue: "jdbc:postgresql://xxx:5432/skywalking"- name: SW_DATA_SOURCE_USERvalue: "skywalking"- name: SW_DATA_SOURCE_PASSWORDvalue: "skywalking"ports:- containerPort: 11800protocol: TCPname: grpc- containerPort: 12800protocol: TCPname: oap-http- containerPort: 8080protocol: TCPname: ui-httplivenessProbe:httpGet:path: /internal/l7checkport: 12800initialDelaySeconds: 300timeoutSeconds: 30periodSeconds: 60successThreshold: 1failureThreshold: 10readinessProbe:httpGet:path: /internal/l7checkport: 12800initialDelaySeconds: 300timeoutSeconds: 30periodSeconds: 10successThreshold: 1failureThreshold: 5startupProbe:httpGet:path: /internal/l7checkport: 12800initialDelaySeconds: 300timeoutSeconds: 30periodSeconds: 10successThreshold: 1failureThreshold: 5resources:requests:cpu: 0.2memory: 1Gilimits:cpu: 1memory: 2GiimagePullSecrets:- name: puller
agent环境变量
- name: SW_AGENT_NAMEvalue: "Your_ApplicationName"
# skywalking oap 地址
- name: SW_AGENT_COLLECTOR_BACKEND_SERVICESvalue: "skywalking.kube-public:11800"
# 日志路径
- name: SW_LOGGING_DIRvalue: "/xxx/skywalking-agent/logs"
# 日志级别,默认: INFO
- name: SW_LOGGING_LEVELvalue: "WARN"
# 日志文件最大数量
- name: SW_LOGGING_MAX_HISTORY_FILESvalue: "10"
- 微服务启动的时候增加启动参数:
-javaagent:/xxx/skywalking-agent/skywalking-agent.jar
- skywalking-agent的其它参数由上面的环境变量进行设置
运行截图
参考资料
- skywalking源码
配置文件参考:
https://github.com/apache/skywalking/blob/master/oap-server/server-starter/src/main/resources/application.yml
- K8S部署skywalking9.3版本
- skywalking使用ES做存储在K8S上的部署,使用实践
- skywalking-helm
- skywalking-docker
Since SkyWalking 8.8.0, the Dockerfiles are merged into the OAP repo and the Java agent repo respectively, this repo is archived and not maintained anymore.
- 使用源码制作镜像
- skywalking-oap server 环境变量支持
表格往右拖动,可以看到环境变量名称和默认值。
这篇关于【SkyWalking】使用PostgreSQL做存储K8s部署的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!