配置Kubernetes bitnami / mariadb容器以安装minikube卷

时间:2018-03-14 12:41:45

标签: docker kubernetes mariadb bitnami minikube

在尝试在Kubernetes& amp;中设置开发平台时,我遇到了错误。 minikube。配置正在创建服务 persistentVolume persistentVolumeClaim &的部署

部署正在根据bitnami/mariadb:latest

创建一个容器,其中包含一个容器

我通过以下方式将一个本地音量装入 minikube vm:

minikube mount <source-path>:/data

此本地卷正确安装,当我通过以下方式进入minikube vm时可以进行检查:minikube ssh

我现在跑:

kubectl create -f mariadb-deployment.yaml

启动平台,yaml config:

kind: Service
apiVersion: v1
metadata:
  name: mariadb-deployment
  labels:
    app: supertubes
spec:
  ports:
  - port: 3306
  selector:
    app: supertubes
    tier: mariadb
  type: LoadBalancer
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: local-db-pv
  labels:
    type: local
    tier: mariadb
    app: supertubes
spec:
  storageClassName: slow
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/staging/sumatra/mariadb-data"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: local-db-pv-claim
  labels:
    app: supertubes
spec:
  storageClassName: slow
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  selector:
    matchLabels:
      type: local
      tier: mariadb
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: mariadb-deployment
  labels:
    app: supertubes
spec:
  selector:
    matchLabels:
      app: supertubes
      tier: mariadb
  template:
    metadata:
      labels:
        app: supertubes
        tier: mariadb
    spec:
      securityContext:
        fsGroup: 1001
      containers:
      - image: bitnami/mariadb:latest
        name: mariadb
        env:
        - name: MARIADB_ROOT_PASSWORD
          value: <db-password>
        - name: MARIADB_DATABASE
          value: <db-name>
        ports:
        - containerPort: 3306
          name: mariadb
        volumeMounts:
        - name: mariadb-persistent-storage
          mountPath: /bitnami
      volumes:
      - name: mariadb-persistent-storage
        persistentVolumeClaim:
          claimName: local-db-pv-claim

以上配置无法启动 pod ,并检查minikube dashboard中的pod日志显示以下内容:

nami    INFO  Initializing mariadb
mariadb INFO  ==&gt; Cleaning data dir...
mariadb INFO  ==&gt; Configuring permissions...
mariadb INFO  ==&gt; Validating inputs...
mariadb INFO  ==&gt; Initializing database...
mariadb INFO  ==&gt; Creating 'root' user with unrestricted access...
mariadb INFO  ==&gt; Creating database pw_tbs...
mariadb INFO  ==&gt; Enabling remote connections...
Error executing 'postInstallation': EACCES: permission denied, mkdir '/bitnami/mariadb'

看看上面我相信问题是与Bitnami一起使用用户:1001来启动他们的mariadb图像:

https://github.com/bitnami/bitnami-docker-mariadb/issues/134

自从阅读上述问题以来,我一直在容器规范中使用securityContext。目前你会看到我把它设置为:

deployment.template.spec

securityContext:
  fsGroup: 1001

但这不起作用。我也试过了:

securityContext:
  privileged: true

但也没有得到任何一个。

我做的另一项检查是从 deployment.template.spec.containers 中删除volumeMount,看看没有它的情况下是否正常工作,他们这样做了吗?) < / p>

然后我在pod中打开了一个shell,以查看/bitnami上的权限是什么:

enter image description here

在上面发布的Bitnami问题上再读一点说用户:1001是根组的成员,因此我希望他们拥有必要的权限......在这个阶段我有点迷失至于出了什么问题。

如果有人能帮我理解如何在容器内正确设置这个minikube vm卷,这将是惊人的!

编辑15/03/18

根据@Anton Kostenko的建议,我添加了一个 busybox 容器作为initContainer,在chmod目录上运行了bitnami

...
spec:
  initContainers:
  - name: install
    image: busybox
    imagePullPolicy: Always
    command: ["chmod", "-R", "777", "/bitnami"]
    volumeMounts:
    - name: mariadb-persistent-storage
      mountPath: /bitnami
  containers:
  - image: bitnami/mariadb:latest
    name: mariadb
...

但是,即使设置了全局 rwx 权限(777),目录也无法挂载,因为MariaDB容器不允许用户1001执行此操作:

nami    INFO  Initializing mariadb
Error executing 'postInstallation': EPERM: operation not permitted, utime '/bitnami/mariadb/.restored'

另一个编辑15/03/18

现在尝试在我的本地计算机(MacBook)上设置用户:组,以便在传递给 minikube vm时,它们应该已经是正确的:

enter image description here

现在mariadb-data对eveyone和用户拥有rwx权限:1001,group:1001

然后我删除了initContainer,因为我不确定会添加什么。

SSH连接到minikube vm我可以看到权限和用户:组已被执行:

enter image description here

用户&amp;组现在被设置为 docker

启动此容器会导致同样的错误:

nami    INFO  Initializing mariadb
Error executing 'postInstallation': EIO: i/o error, utime '/bitnami/mariadb/.restored'

我尝试删除 securityContext ,并将其添加为runAsUser:1001,fsGroup:1001,但两者都没有任何区别。

1 个答案:

答案 0 :(得分:0)

Minikube中看起来是个问题。

您可以尝试使用init-container,它将在启动主容器之前修复权限,如下所示:

  ...........
    spec:
  initContainers:
  - name: "fix-non-root-permissions"
    image: "busybox"
    imagePullPolicy: "Always"
    command: [ "chmod", "-R", "g+rwX", "/bitnami" ]
    volumeMounts:
    - name: datadir
      mountPath: /bitnami
    containers:
  .........