I am using a inital container(k8s version:v1.15.2) to initial skywalking(6.5.0) jar file before container startup.But I could not found the file and directory the intial container create,this is my initial container define:
"initContainers": [
{
"name": "init-agent",
"image": "registry.cn-shenzhen.aliyuncs.com/dabai_app_k8s/dabai_fat/skywalking-agent:6.5.0",
"command": [
"sh",
"-c",
"set -ex;mkdir -p /skywalking/agent;cp -r /opt/skywalking/agent/* /skywalking/agent;"
],
"resources": {},
"volumeMounts": [
{
"name": "agent",
"mountPath": "/skywalking/agent"
},
{
"name": "default-token-xnrwt",
"readOnly": true,
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount"
}
],
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"imagePullPolicy": "Always"
}
]
now the initial container execute success,I am check the log output like this:
~/Library/Mobile Documents/com~apple~CloudDocs/Document/source/dabai/microservice/soa-red-envelope on develop_jiangxiaoqiang! ⌚ 14:48:26
$ kubectl logs soa-red-envelope-service-85758d88cb-rmtcj -c init-agent
+ mkdir -p /skywalking/agent
+ cp -r /opt/skywalking/agent/activations /opt/skywalking/agent/bootstrap-plugins /opt/skywalking/agent/config /opt/skywalking/agent/logs /opt/skywalking/agent/optional-plugins /opt/skywalking/agent/plugins /opt/skywalking/agent/skywalking-agent.jar /skywalking/agent
now something I am confusing is where the directory locate? where is the file I am copy? I am login my container and do not find the jar file:
~/Library/Mobile Documents/com~apple~CloudDocs/Document/source/dabai/microservice/soa-red-envelope on develop_jiangxiaoqiang! ⌚ 14:50:55
$ kubectl exec -it soa-red-envelope-service-85758d88cb-rmtcj /bin/ash
/ # ls
bin data dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
/ # cd /opt/
/opt # ls
data
/opt #
now I am starting my app to collection metrics data like this:
ENTRYPOINT exec java -Xmx1g -Xms1g -Dapp.id=$APP_ID -javaagent:/skywalking/agent/skywalking-agent.jar -Dskywalking.agent.service_name=soa-red-envelope-service -Dskywalking.collector.backend_service=10.254.35.220:11800 -jar /root/soa-red-envelope-service-1.0.0-SNAPSHOT.jar
obviously it tell me could not fond the jar file error:
Error occurred during initialization of VM
agent library failed to init: instrument
Error opening zip file or JAR manifest missing : /skywalking/agent/skywalking-agent.jar
so what should I do to fix this? I already searching from internet bu found no useful way to solve my situation.
So you should go throught this document first
https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
use hostPath
as sample
volumes:
- name: agent
hostPath:
# directory location on host
path: /agent
# this field is optional
type: Directory
You need reference it for both init container and normal container.