initialise config with initContainer in openshift OKD

9/2/2019

I am trying to run gitea 1.8.3 which now has a habit of wanting to write in generated JWT token into its own app.ini file. Previously the app.ini file could be mounted from a ConfigMap as read-only. Now I need to somehow populate the app.ini file with some data but also let the app write into that file.

I am trying to have an initContainer write out the config that is mounted in the main app. This is explained at here. When I try that example with minishift it tells me I cannot mount a hostPath due to a security constraint. I don't want to relax security so I am trying to put the configuration into a PVC. Here is the script:

#!/bin/bash
cat | oc create -f  - <<EOF
---
apiVersion: "v1"
kind: "PersistentVolumeClaim"
metadata:
  name: "config-data-claim"
spec:
  accessModes:
    - "ReadWriteMany"
  resources:
    requests:
      storage: "1Gi"
---
apiVersion: v1
kind: Pod
metadata:
  name: my-app
spec:
  containers:
  - name: realworld
    image: docker.io/simonmassey/react-redux-realworld:v0.0.2
    env:
    - name: API_ROOT
      value: https://conduit.productionready.io/api
    volumeMounts:
    - mountPath: /data
      name: config-data-claim
  initContainers:
  - name: config-data
    image: busybox
    command: ["echo","-n","{'address':'10.0.1.192:2379/db'}", ">","/data/config"]
    volumeMounts:
    - mountPath: /data
      name: config-data-claim
  volumes:
  - name: config-data-claim
    persistentVolumeClaim:
      claimName: config-data-claim
EOF

This creates fine but when I used the minishift web console to go into a terminal in the pod and run ls -al /data the pvc it is empty. The console shows that the initContainer ran successfully.

Why is the pvc folder /data not populated by the initContainer?

I am running:

$ oc version
Client Version: version.Info{Major:"4", Minor:"1+", GitVersion:"v4.1.0+b4261e0", GitCommit:"b4261e07ed", GitTreeState:"clean", BuildDate:"2019-07-06T03:16:01Z", GoVersion:"go1.12.6", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.0+d4cacc0", GitCommit:"d4cacc0", GitTreeState:"clean", BuildDate:"2019-08-30T20:25:39Z", GoVersion:"go1.10.8", Compiler:"gc", Platform:"linux/amd64"}

The server is minishift running opensheft 3.11 started with:

brew cask install minishift
minishift start --vm-driver virtualbox --cpus 2 --memory 8GB --disk-size 100GB --profile helm211 --openshift-version v3.11.0
eval $(minishift oc-env)
-- simbo1905
kubernetes
okd
openshift

0 Answers