在kubernetes容器中找不到由初始容器创建的文件和文件夹

时间:2020-02-29 07:05:57

标签: kubernetes

在容器启动之前,我正在使用初始容器(k8s版本:v1.15.2)到初始的skywalking(6.5.0)jar文件。但是我找不到初始容器创建的文件和目录,这是我的初始容器定义:

"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"
      }
    ]

现在初始容器执行成功,我正在检查日志输出,如下所示:

~/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

现在让我感到困惑的是目录位于何处?我要复制的文件在哪里?我正在登录我的容器,但找不到jar文件:

~/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 #

现在我要启动我的应用来收集指标数据,如下所示:

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

显然,它告诉我无法喜欢jar文件错误:

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

那我应该怎么做才能解决这个问题?我已经从Internet bu搜索了,没有找到解决我情况的有用方法。

1 个答案:

答案 0 :(得分:2)

所以您应该先阅读本文档

https://kubernetes.io/docs/concepts/storage/volumes/#hostpath

使用hostPath作为示例

  volumes:
  - name: agent
    hostPath:
      # directory location on host
      path: /agent
      # this field is optional
      type: Directory

init容器和普通容器都需要引用它。