Kubernetes 库伯内特斯没有';不允许将文件装载到容器

Kubernetes 库伯内特斯没有';不允许将文件装载到容器,kubernetes,Kubernetes,在kubernetes集群中部署应用程序时,我遇到了以下错误。看起来kubernetes不允许将文件装载到容器中,您知道可能的原因吗 部署配置文件 apiVersion: extensions/v1beta1 kind: Deployment metadata: name: model-loader-service namespace: "{{ .Values.nsPrefix }}-aai" spec: selector: matchLabels: app: m

在kubernetes集群中部署应用程序时,我遇到了以下错误。看起来kubernetes不允许将文件装载到容器中,您知道可能的原因吗

部署配置文件

apiVersion: extensions/v1beta1 kind: Deployment metadata: name: model-loader-service namespace: "{{ .Values.nsPrefix }}-aai" spec: selector: matchLabels: app: model-loader-service template: metadata: labels: app: model-loader-service name: model-loader-service spec: containers: - name: model-loader-service image: "{{ .Values.image.modelLoaderImage }}:{{ .Values.image.modelLoaderVersion }}" imagePullPolicy: {{ .Values.pullPolicy }} env: - name: CONFIG_HOME value: /opt/app/model-loader/config/ volumeMounts: - mountPath: /etc/localtime name: localtime readOnly: true - mountPath: /opt/app/model-loader/config/ name: aai-model-loader-config - mountPath: /var/log/onap name: aai-model-loader-logs - mountPath: /opt/app/model-loader/bundleconfig/etc/logback.xml name: aai-model-loader-log-conf subPath: logback.xml ports: - containerPort: 8080 - containerPort: 8443 - name: filebeat-onap-aai-model-loader image: {{ .Values.image.filebeat }} imagePullPolicy: {{ .Values.pullPolicy }} volumeMounts: - mountPath: /usr/share/filebeat/filebeat.yml name: filebeat-conf - mountPath: /var/log/onap name: aai-model-loader-logs - mountPath: /usr/share/filebeat/data name: aai-model-loader-filebeat volumes: - name: localtime hostPath: path: /etc/localtime - name: aai-model-loader-config hostPath: path: "/dockerdata-nfs/{{ .Values.nsPrefix }}/aai/model-loader/appconfig/" - name: filebeat-conf hostPath: path: /dockerdata-nfs/{{ .Values.nsPrefix }}/log/filebeat/logback/filebeat.yml

导致的“非目录”
有点不言自明。您使用的确切卷和卷数量定义是什么?您在申报单中使用了什么

编辑:更改

- name: filebeat-conf
  hostPath:
    path: /dockerdata-nfs/{{ .Values.nsPrefix }}/log/filebeat/logback/filebeat.yml


并将
子路径:filebeat.yml
添加到volumeMount

这是一个多节点集群吗?如果是这样,文件需要存在于所有Kubernetes节点上,因为pod通常安排在随机可用的主机上。在任何情况下,都是向容器提供静态/只读文件的更好方法。

SELinux也可能是罪魁祸首。登录到节点并执行
sestatus
。如果策略被禁用,您将看到输出为
SELINUX=disabled
,否则它将类似于以下内容:

SELinux状态:已启用
SELinuxfs装载:/sys/fs/selinux
SELinux根目录:/etc/SELinux
已加载的策略名称:mcs
当前模式:允许
配置文件中的模式:允许
策略MLS状态:已启用
策略拒绝\u未知状态:允许
最大内核策略版本:31
第一种选择: 您可以通过编辑
/etc/selinux/config
文件禁用selinux,并将
selinux=permissive
更新为
selinux=disabled
。完成后,重新启动计算机并部署以查看是否已修复。但是,这不是推荐的方式,可以看作是一个临时修复

第二种选择: 登录到节点并执行
ps-efZ | grep kubelet
,这将给出类似的结果

system\u:system\u r:kernel\u t:s0 root 1592 1 2 May 23?09:58:18/usr/local/bin/kubelet--anonymousauth=false
现在,从这个输出捕获字符串
system\u:system\r:kernel\u t:s0
,它可以在部署中更改为安全上下文,如下所示

securityContext:
选择选项:
用户:系统_
角色:系统\r
类型:spc\U t
级别:s0

部署应用程序并检查日志(如果已修复)。请告诉我这是否适用于您或是否需要任何进一步的帮助。

部署配置已添加到帖子中。为什么不使用configmaps?
$ docker version
Client:
 Version:      1.12.6
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   78d1802
 Built:        Tue Jan 10 20:38:45 2017
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.6
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   78d1802
 Built:        Tue Jan 10 20:38:45 2017
 OS/Arch:      linux/amd64

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"7", GitVersion:"v1.7.4", GitCommit:"793658f2d7ca7f064d2bdf606519f9fe1229c381", GitTreeState:"clean", BuildDate:"2017-08-17T08:48:23Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"8+", GitVersion:"v1.8.3-rancher3", GitCommit:"772c4c54e1f4ae7fc6f63a8e1ecd9fe616268e16", GitTreeState:"clean", BuildDate:"2017-11-27T19:51:43Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
- name: filebeat-conf
  hostPath:
    path: /dockerdata-nfs/{{ .Values.nsPrefix }}/log/filebeat/logback/filebeat.yml
- name: filebeat-conf
  hostPath:
    path: /dockerdata-nfs/{{ .Values.nsPrefix }}/log/filebeat/logback/