Mounting a ConfigMap as a volume in Kubernetes: how do I calculate the value of defaultMode?

Viewed 60

Defining the defaultMode in a Kubernetes volume field within a deployment element can become quite tricky.

It expects three decimals, corresponding to the binary UNIX permissions.

As an example, to mount the ConfigMap with permissions r------, you'd need to specify 256.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: foo
  namespace: foo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: foo
  template:
    metadata:
      labels:
        app: foo
    spec:
      containers:
        - image: php-fpm:latest
          volumeMounts:
            - name: phpini
              mountPath: /usr/local/etc/php/conf.d/99-settings.ini
              readOnly: true
              subPath: 99-settings.ini
      volumes:
        - configMap:
            defaultMode: 256
            name: phpini-configmap
            optional: false
          name: phpini
---
apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: foo
  namespace: foo
  name: phpini-configmap
data:
  99-settings.ini: |
    ; Enable Zend OPcache extension module
    zend_extension = opcache
1 Answers

Use the following table:

unix decimal unix readable binary equivalent defaultMode
400 r-------- 100000000 256
440 r--r----- 100100000 288
444 r--r--r-- 100100100 292
600 rw------- 110000000 384
600 rw-r----- 110100000 416
660 rw-rw---- 110110000 432
660 rw-rw-r-- 110110100 436
666 rw-rw-rw- 110110110 438
700 rwx------ 111000000 448
770 rwxrwx--- 111111000 504
777 rwxrwxrwx 111111111 511

A more direct way to do this is to use a base8 to base10 converter like this one

Related