【问题标题】:Permission denied when chown on elasticsearch data directory in kubernetes statefulset在 kubernetes statefulset 中对 elasticsearch 数据目录进行 chown 时权限被拒绝
【发布时间】:2018-03-03 05:26:08
【问题描述】:

希望有人可以帮助我解决似乎是权限错误的问题。我正在尝试使用官方的弹性搜索泊坞窗图像启动一个 3 节点弹性搜索集群。当容器启动时,我从 /usr/share/elasticsearch/data/nodes 上的 elasticsearch 收到“拒绝访问”错误,所以我尝试添加一个命令以使 elasticsearch 成为 /usr/share/elasticsearch/data 的所有者...但是当我包含 chown 命令时出现这些错误:

chown: cannot read directory '/usr/share/elasticsearch/data/lost+found': Permission denied
chown: changing ownership of '/usr/share/elasticsearch/data': Operation not permitted

这是我的 statefulset yaml 文件:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: esnode
spec:
  serviceName: elasticsearch-transport
  replicas: 3
  template:
    metadata:
      labels:
        app: evo-pro-cluster
    spec:
      initContainers:
      - name: init-sysctl
        image: busybox
        imagePullPolicy: IfNotPresent
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
        securityContext:
          privileged: true
      containers:
      - name: elasticsearch
        securityContext:
          privileged: true
          capabilities:
            add:
            - IPC_LOCK
            - SYS_RESOURCE
        command: ["/bin/sh"]
        args: ["-c", "chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data"]
        image: docker.elastic.co/elasticsearch/elasticsearch:5.6.1
        imagePullPolicy: Always
        env:
        - name: "ES_JAVA_OPTS"
          value: "-Xms6g -Xmx6g"
        ports:
        - containerPort: 9200
          name: http
          protocol: TCP
        - containerPort: 9300
          name: transport
          protocol: TCP
        volumeMounts:
        - name: storage
          mountPath: /usr/share/elasticsearch/data
        - name: config
          mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
          subPath: elasticsearch.yml
      volumes:
        - name: config
          configMap:
            name: elasticsearch-config
  volumeClaimTemplates:
  - metadata:
      name: storage
      annotations:
        storageClassName: standard
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 110Gi

【问题讨论】:

  • 我将命令移动到初始化容器,它似乎工作:``` initContainers: - name: init-es-settings image:busybox imagePullPolicy: IfNotPresent securityContext: privileged: true command: ["sysctl ", "-w​​", "vm.max_map_count=262144"] 命令: ["/bin/sh"] 参数: ["-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"] volumeMounts: - name: storage mountPath: /usr/share/elasticsearch/data

标签: docker elasticsearch kubernetes


【解决方案1】:

这个特定的 docker 映像期望数据目录可由 uid 2000 写入。您可以通过添加 .spec.securityContext.fsGroup 来告诉 Kubernetes chown(某种程度)您 pod 的挂载点:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: esnode
spec:
  ...
  securityContext:
    fsGroup: 2000

(当然你可以摆脱 chown hack 或 initContainer)

fsGroup: integer:一个特殊的补充组,适用于 pod 中的所有容器。一些卷类型允许 Kubelet 将该卷的所有权更改为由 pod 拥有: 1. 拥有 GID 将是 FSGroup 2. setgid 位已设置(在卷中创建的新文件将归 FSGroup 所有) 3 . 权限位与 rw-rw 进行 OR'd---- 如果未设置,Kubelet 将不会修改任何卷的所有权和权限。

【讨论】:

  • 完美!谢谢亚诺斯。
  • 我设置为 1000...而不是 2000
  • containers:块中试过,得到error validating data: ValidationError(Deployment.spec.template.spec.containers[0].securityContext): unknown field "fsGroup" in io.k8s.api.core.v1.SecurityContext;
  • replicas:template: 之前尝试过。收到unknown field "securityContext" in io.k8s.api.extensions.v1beta1.DeploymentSpec
  • 首先通过使用elasticsearch图像运行测试pod/容器kubectl run elastic-test --rm -it --image=docker.elastic.co/elasticsearch/elasticsearch:7.9.2 --command -- id elasticsearchuid=1000(elasticsearch) gid=1000(elasticsearch) groups=1000(elasticsearch),0(root)来检查elasticsearch用户的gid会有所帮助@
猜你喜欢
  • 2020-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-08
  • 2013-06-28
  • 2020-08-27
  • 2016-06-25
  • 2011-01-16
相关资源
最近更新 更多