拉取镜像
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.1
docker 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: skywalking
namespace: kube-public
labels:
app: skywalking
spec:
type: NodePort
ports:
- name: oap-http
port: 12800
targetPort: 12800
nodePort: 12800
- name: grpc
port: 11800
targetPort: 11800
nodePort: 11800
- name: ui-http
port: 22800
targetPort: 8080
nodePort: 22800
selector:
app: skywalking
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: skywalking
namespace: kube-public
spec:
replicas: 1
revisionHistoryLimit: 0 #Replica Sets中的历史数量
selector:
matchLabels:
app: skywalking
template:
metadata:
labels:
app: skywalking
spec:
# 第一次运行的时候初始化一次
# 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: skywalking
imagePullPolicy: Always
image: xxx/xxx/skywalking:10.0.1
# 导入环境变量
envFrom:
# 使用configMap
- configMapRef:
# name为configMap中的metadata name
name: app-public-cm
- secretRef:
name: app-public-secret
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: SW_STORAGE
value: "postgresql"
- name: SW_JDBC_URL
value: "jdbc:postgresql://xxx:5432/skywalking"
- name: SW_DATA_SOURCE_USER
value: "skywalking"
- name: SW_DATA_SOURCE_PASSWORD
value: "skywalking"
ports:
- containerPort: 11800
protocol: TCP
name: grpc
- containerPort: 12800
protocol: TCP
name: oap-http
- containerPort: 8080
protocol: TCP
name: ui-http
livenessProbe:
httpGet:
path: /internal/l7check
port: 12800
initialDelaySeconds: 300
timeoutSeconds: 30
periodSeconds: 60
successThreshold: 1
failureThreshold: 10
readinessProbe:
httpGet:
path: /internal/l7check
port: 12800
initialDelaySeconds: 300
timeoutSeconds: 30
periodSeconds: 10
successThreshold: 1
failureThreshold: 5
startupProbe:
httpGet:
path: /internal/l7check
port: 12800
initialDelaySeconds: 300
timeoutSeconds: 30
periodSeconds: 10
successThreshold: 1
failureThreshold: 5
resources:
requests:
cpu: 0.2
memory: 1Gi
limits:
cpu: 1
memory: 2Gi
imagePullSecrets:
- name: puller
agent环境变量
- name: SW_AGENT_NAME
value: "Your_ApplicationName"
# skywalking oap 地址
- name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
value: "skywalking.kube-public:11800"
# 日志路径
- name: SW_LOGGING_DIR
value: "/xxx/skywalking-agent/logs"
# 日志级别,默认: INFO
- name: SW_LOGGING_LEVEL
value: "WARN"
# 日志文件最大数量
- name: SW_LOGGING_MAX_HISTORY_FILES
value: "10"
- 微服务启动的时候增加启动参数:
-javaagent:/xxx/skywalking-agent/skywalking-agent.jar
- skywalking-agent的其它参数由上面的环境变量进行设置
运行截图
参考资料
配置文件参考:
https://github.com/apache/skywalking/blob/master/oap-server/server-starter/src/main/resources/application.yml
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.
表格往右拖动,可以看到环境变量名称和默认值。