michaeljmarshall opened a new pull request, #266:
URL: https://github.com/apache/pulsar-helm-chart/pull/266

   Master Issue: https://github.com/apache/pulsar/issues/11269
   
   ### Motivation
   
   Apache Pulsar's docker images for 2.10.0 and above are non-root by default. 
In order to ensure there is a safe upgrade path, we need to expose the 
`securityContext` for the Bookkeeper and Zookeeper StatefulSets. Here is the 
relevant k8s documentation on this k8s feature: 
https://kubernetes.io/docs/tasks/configure-pod-container/security-context.
   
   Once released, all deployments using the default `values.yaml` configuration 
for the `securityContext` will pay a one time penalty on upgrade where the 
kubelet will recursively chown files to be root group writable. It's possible 
to temporarily avoid this penalty by setting `securityContext: {}`.
   
   ### Modifications
   
   * Add config blocks for the `bookkeeper.securityContext` and 
`zookeeper.securityContext`.
   * Default to `fsGroup: 0`. This is already the default group id in the 
docker image, and the docker image assumes the user has root group permission.
   * Default to `fsGroupChangePolicy: "OnRootMismatch"`. This configuration 
will work for all deployments where the user id is stable. If the user id 
switches between restarts, like it does in OpenShift, please set to `Always`.
   * Remove gc configuration writing to directory that the user lacks 
permission. (Perhaps we want to write to `/pulsar/log/bookie-gc.log`?) 
   * Add documentation to the README.
   
   ### Verifying this change
   
   I first attempted verification of this change with minikube. It did not work 
because minikube uses hostPath volumes by default. I then tested on EKS 
v1.21.9-eks-0d102a7. I tested by deploying the current, latest version of the 
helm chart (2.9.3) and then upgrading to this PR's version of the helm chart 
along with using the 2.10.0 docker image. I also tested upgrading from a 
default version 
   
   Test 1 is a plain upgrade using the default 2.9.3 version of the chart, then 
upgrading to this PR's version of the chart with the modification to use the 
2.10.0 docker images. It worked as expected.
   
   ```bash
   $ helm install test apache/pulsar
   $ # Wait for chart to deploy, then run the following, which uses Pulsar 
version 2.10.0:
   $  helm upgrade test -f charts/pulsar/values.yaml charts/pulsar/
   ```
   
   Test 2 is a plain upgrade using the default 2.9.3 version of the chart, then 
an upgrade to this PR's version of the chart, then an upgrade to this PR's 
version of the chart using 2.10.0 docker images. There is a minor error 
described in the `README.md`. The solution is to chown the bookie's data 
directory.
   
   ```bash
   $ helm install test apache/pulsar
   $ # Wait for chart to deploy, then run the following, which uses Pulsar 
version 2.9.2:
   $  helm upgrade test -f charts/pulsar/values.yaml charts/pulsar/
   $ # Upgrade using Pulsar version 2.10.0
   $  helm upgrade test -f charts/pulsar/values.yaml charts/pulsar/
   ```
   
   ### GC Logging
   
   In my testing, I ran into the following errors when using 
`-Xlog:gc:/var/log/bookie-gc.log`:
   
   ```
   pulsar-bookkeeper-verify-clusterid [0.008s] Error opening log file 
'/var/log/bookie-gc.log': Permission denied
   pulsar-bookkeeper-verify-clusterid [0.008s] Initialization of output 
'file=/var/log/bookie-gc.log' using options '(null)' failed.
   pulsar-bookkeeper-verify-clusterid [0.005s] Error opening log file 
'/var/log/bookie-gc.log': Permission denied
   pulsar-bookkeeper-verify-clusterid [0.006s] Initialization of output 
'file=/var/log/bookie-gc.log' using options '(null)' failed.
   pulsar-bookkeeper-verify-clusterid Invalid -Xlog option 
'-Xlog:gc:/var/log/bookie-gc.log', see error log for details.
   pulsar-bookkeeper-verify-clusterid Error: Could not create the Java Virtual 
Machine.
   pulsar-bookkeeper-verify-clusterid Error: A fatal exception has occurred. 
Program will exit.
   pulsar-bookkeeper-verify-clusterid Invalid -Xlog option 
'-Xlog:gc:/var/log/bookie-gc.log', see error log for details.
   pulsar-bookkeeper-verify-clusterid Error: Could not create the Java Virtual 
Machine.
   pulsar-bookkeeper-verify-clusterid Error: A fatal exception has occurred. 
Program will exit.
   ```
   
   I resolved the error by removing the setting.
   
   ### OpenShift Observations
   
   I wanted to seamlessly support OpenShift, so I investigated using 
configuring the bookkeeper and zookeeper process with `umask 002` so that they 
would create files and directories that are group writable (OpenShift has a 
stable group id, but gives the process a random user id). That worked for most 
tools when switching the user id, but not for RocksDB, which creates a lock 
file at `/pulsar/data/bookkeeper/ledgers/current/ledgers/LOCK` with the 
permission `0644` ignoring the umask. Here is the relevant error:
   
   ```
   2022-05-14T03:45:06,903+0000  ERROR org.apache.bookkeeper.server.Main - 
Failed to build bookie server
   java.io.IOException: Error open RocksDB database
       at 
org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorageRocksDB.<init>(KeyValueStorageRocksDB.java:199)
 ~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at 
org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorageRocksDB.<init>(KeyValueStorageRocksDB.java:88)
 ~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at 
org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorageRocksDB.lambda$static$0(KeyValueStorageRocksDB.java:62)
 ~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at 
org.apache.bookkeeper.bookie.storage.ldb.LedgerMetadataIndex.<init>(LedgerMetadataIndex.java:68)
 ~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at 
org.apache.bookkeeper.bookie.storage.ldb.SingleDirectoryDbLedgerStorage.<init>(SingleDirectoryDbLedgerStorage.java:169)
 ~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at 
org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorage.newSingleDirectoryDbLedgerStorage(DbLedgerStorage.java:150)
 ~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at 
org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorage.initialize(DbLedgerStorage.java:129)
 ~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at org.apache.bookkeeper.bookie.Bookie.<init>(Bookie.java:818) 
~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at 
org.apache.bookkeeper.proto.BookieServer.newBookie(BookieServer.java:152) 
~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at 
org.apache.bookkeeper.proto.BookieServer.<init>(BookieServer.java:120) 
~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at 
org.apache.bookkeeper.server.service.BookieService.<init>(BookieService.java:52)
 ~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at org.apache.bookkeeper.server.Main.buildBookieServer(Main.java:304) 
~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at org.apache.bookkeeper.server.Main.doMain(Main.java:226) 
[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       at org.apache.bookkeeper.server.Main.main(Main.java:208) 
[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
   Caused by: org.rocksdb.RocksDBException: while open a file for lock: 
/pulsar/data/bookkeeper/ledgers/current/ledgers/LOCK: Permission denied
       at org.rocksdb.RocksDB.open(Native Method) 
~[org.rocksdb-rocksdbjni-6.10.2.jar:?]
       at org.rocksdb.RocksDB.open(RocksDB.java:239) 
~[org.rocksdb-rocksdbjni-6.10.2.jar:?]
       at 
org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorageRocksDB.<init>(KeyValueStorageRocksDB.java:196)
 ~[org.apache.bookkeeper-bookkeeper-server-4.14.4.jar:4.14.4]
       ... 13 more
   ```
   
   As such, in order to support OpenShift, I exposed the `fsGroupChangePolicy`, 
which allows for OpenShift support, but not necessarily _seamless_ support.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to