cat deploy.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-name
namespace: your-namespace
annotations:
kubernetes.io/change-cause: 2.11.0-SNAPSHOT-20230420-46 # 版本说明 - 用于回滚等
labels:
app: app-name
spec:
replicas: 1
selector:
matchLabels:
app: app-name
template:
metadata:
labels:
app: app-name
spec:
initContainers: # 初始化容器挂载sky agent
- name: skywalking-agent
image: harbor.jiuqichina.com/public/sky-agent:8.8.0
imagePullPolicy: IfNotPresent
command: ['sh']
args: ['-c','cp -r /usr/skywalking/agent/* /home/skywalking-agent']
volumeMounts:
- mountPath: /home/skywalking-agent
name: skywalking-agent
containers:
- name: app-name
image: harbor.myregister.com/dev/app-name:2.11.0
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /home/skywalking-agent
name: skywalking-agent
ports:
- containerPort: server_port
env:
- name: MY_POD_NAME #获取容器名称 ,给后面的环境变量使用时需要先定义。有顺序,其余内置变量参考:https://kubernetes.io/zh-cn/docs/tasks/inject-data-application/environment-variable-expose-pod-information/
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: jvm_opts
value: "-Drocketmq.client.name=app_name-$(MY_POD_NAME) "
- name: sky_agent
value: "-javaagent:/home/skywalking-agent/skywalking-agent.jar -DSW_AGENT_NAME=app_name-DSW_AGENT_COLLECTOR_BACKEND_SERVICES=sky-server:11800"
- name: sky_agent_id
value: "-Dskywalking.agent.instance_name=test-app_name-$(MY_POD_NAME)"
resources:
requests:
memory: "512Mi"
cpu: "200m"
limits:
memory: "4Gi"
cpu: "2000m"
livenessProbe:
httpGet:
path: /actuator/health
port: server_port
initialDelaySeconds: 60
periodSeconds: 10
timeoutSeconds: 5
readinessProbe: # 就绪探针
httpGet:
path: /actuator/health
port: server_port
initialDelaySeconds: 120
periodSeconds: 10
timeoutSeconds: 5
lifecycle:
preStop: # pod停止前Hook - 优雅停机
exec:
command:
- "curl"
- "-XPOST"
- "http://127.0.0.1:server_port/actuator/shutdown"
imagePullSecrets:
- name: regcred
volumes:
- name: skywalking-agent
emptyDir: {}
kubectl apply -f app_name-deployment.yml
标签:java,name,示例,app,sky,agent,skywalking,port From: https://www.cnblogs.com/pgyLang/p/17335961.html