bitnami / charts

Bitnami Helm Charts
https://bitnami.com
Other
9.03k stars 9.22k forks source link

[bitnami/wordpress] Unable to install plugins manually following successful helm chart install when pre-loading wp-content #6912

Closed hectoralicea closed 3 years ago

hectoralicea commented 3 years ago

Which chart: bitnami/wordpress 11.0.16

Describe the bug I'm able to install the wordpress chart quite nicely and when I use the default wordpress content, I'm able to install plugins. BUT when I try to load prior content and restore mysql data from one exported from a prior deployment, I'm not able to install plugins. I get the message: 'Update failed: Could not create directory.' on the plugin webpage.

Screen Shot 2021-07-09 at 5 50 36 PM

I suspect it has something to do with using the initContainer to pull the content from the git repo.

To Reproduce Steps to reproduce the behavior:

1.) first create a configmap which has the sql dump you want to load on initialization.

kubectl create configmap mysqldump \
      --namespace wp-bitnami  \
      --from-file=bitnami.sql

note: bitnami.sql is an sql dump export file from a prior deployment which worked just fine configured with using default install. e.g. ==> Configuring WordPress with settings provided via environment variables

2.) run the helm install chart, pass the wordpress-values.yaml which is shown below. Pay special attention to these lines: initContainers: which I clone a git repository which has the wp content I was to substitute in to the container.

helm upgrade bitnami bitnami/wordpress \
      --version  11.0.16 \
      --install \
      --namespace wp-bitnami \
      --debug \
      --wait \
      --timeout 20m \
      -f wordpress-values.yaml

Contents of wordpress-values.yaml

nameOverride: bitnami
fullnameOverride: bitnami
clusterDomain: rke2-dev.hla.us
image:
  debug: true
wordpressUsername: wp_admin
wordpressPassword: ********
wordpressEmail: hector_alicea@hla.us
wordpressFirstName: Hector
wordpressLastName: Alicea
wordpressPlugins: none
allowEmptyPassword: false
extraEnvVars: []
initContainers:
  - name: init
    image: 'bitnami/git:latest'
    imagePullPolicy: IfNotPresent
    env:
      - name: GIT_REPO_CRED_USER
        valueFrom:
          secretKeyRef:
            name: wp-bitnami-git-credential-secret
            key: username
      - name: GIT_REPO_CRED_USER_PASSWORD
        valueFrom:
          secretKeyRef:
            name: wp-bitnami-git-credential-secret
            key: password
      - name: GIT_DISCOVERY_ACROSS_FILESYSTEM
        value: '1'
    command:
      - sh
      - '-c'
      - >
        cd /bitnami/wordpress && 
        pwd && 
        git clone --branch main --verbose https://${GIT_REPO_CRED_USER}:${GIT_REPO_CRED_USER_PASSWORD}@gitlab.hla.us/eps/wp-sites-cicd/bitnami.git . && 
        ls -al && 
        git status || true
    volumeMounts:
      - mountPath: /bitnami/wordpress
        name: wordpress-data
        subPath: wordpress
service:
  type: ClusterIP
ingress:
  enabled: true
  hostname: bitnami.rke2-dev.hla.us
volumePermissions:
  enabled: false
mariadb:
  auth:
    rootPassword: *************
    database: bitnami
    username: db_admin
    password: *************
  initdbScriptsConfigMap: mysqldump

Expected behavior

It should work just as if I'm running using default autogenerated content and be able to install plugins.

Version of Helm and Kubernetes:

version.BuildInfo{Version:"v3.6.0", GitCommit:"7f2df6467771a75f5646b7f12afb408590ed1755", GitTreeState:"clean", GoVersion:"go1.16.3"}
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.0", GitCommit:"cb303e613a121a29364f75cc67d3d580833a7479", GitTreeState:"clean", BuildDate:"2021-04-08T16:31:21Z", GoVersion:"go1.16.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.8+rke2r1", GitCommit:"5575935422cc1cf5169dfc8847cb587aa47bac5a", GitTreeState:"clean", BuildDate:"2021-06-23T23:30:36Z", GoVersion:"go1.15.8b5", Compiler:"gc", Platform:"linux/amd64"}

Additional context Add any other context about the problem here.

pablogalegoc commented 3 years ago

Hi @hectoralicea,

Thanks for the detailed explanation! I’m going to try to replicate your steps and see if I reproduce the issue. I’ll keep you updated.

hectoralicea commented 3 years ago

Hi @hectoralicea,

Thanks for the detailed explanation! I’m going to try to replicate your steps and see if I reproduce the issue. I’ll keep you updated.

Hi @pablogalegoc

Let me know how I can help. I can provide you the ansible playbook that builds this, but then again, that might be a bit too complicated, or it might be easier. I guess it depends on your environment.

pablogalegoc commented 3 years ago

Hi @hectoralicea!

I've not been able to reproduce the issue but I have the same suspicions as you, that it has something to do with the permissions set inside /bitnami/wordpress by the init container. Could you execute:

kubectl exec [POD-ID] -- ls -l /bitnami/wordpress
hectoralicea commented 3 years ago

Hi @hectoralicea!

I've not been able to reproduce the issue but I have the same suspicions as you, that it has something to do with the permissions set inside /bitnami/wordpress by the init container. Could you execute:

kubectl exec [POD-ID] -- ls -l /bitnami/wordpress
ansible$ kc exec -it -n wp-bitnami bitnami-5dcc7c7d6b-4pzrg -- ls -l /bitnami/wordpress
Defaulted container "wordpress" out of: wordpress, init (init)
total 728
-rw-r--r--. 1 root 1001    277 Jul 14 13:29 README.md
-rw-r--r--. 1 root 1001 727138 Jul 14 13:29 bitnami.sql
-rw-r--r--. 1 root 1001   4398 Jul 14 13:29 wp-config.php
drwxr-sr-x. 4 root 1001   4096 Jul 14 13:29 wp-content
x-eps-bartbox2 [~]
hectoralicea commented 3 years ago

I was able to get it to work. All I had to do was add the following to the initContainer

   securityContext:
     runAsNonRoot: true
     runAsUser: 1001
     runAsGroup: 1001

so the initContainer looks like this

initContainers:
 - name: init
   image: bitnami/git:latest
   imagePullPolicy: IfNotPresent
   securityContext:
     runAsNonRoot: true
     runAsUser: 1001
     runAsGroup: 1001
   env:
     - name: GIT_REPO_CRED_USER
       valueFrom: 
         secretKeyRef:
           name: {{ wordpress_git_credentials }}
           key: username
     - name: GIT_REPO_CRED_USER_PASSWORD
       valueFrom: 
         secretKeyRef:
           name: {{ wordpress_git_credentials }}
           key: password
     - name: GIT_DISCOVERY_ACROSS_FILESYSTEM
       value: "1"
   command: 
     - 'sh'
     - '-c'
     - >
       cd /bitnami/wordpress &&
       pwd &&
       git clone --branch {{ wordpress_site_git_repo_branch }} --verbose https://${GIT_REPO_CRED_USER}:${GIT_REPO_CRED_USER_PASSWORD}@{{ git_repo_host }}/{{ git_repo_org_owner }}/{{ git_repo_wp_sites_subgroup }}/{{ wordpress_site_git_repo }}.git . &&
       ls -al &&
       git status || true
   volumeMounts:
     - mountPath: /bitnami/wordpress
       name: wordpress-data
       subPath: wordpress  
pablogalegoc commented 3 years ago

Happy to hear that @hectoralicea!

I'm pretty sure it was a permissions issue since the ones set on the wp-content folder by the default installation of the chart are:

drwxrwxr-x 7 1001 root 4096 Jul 15 09:17 wp-content