<p>How can I inject code/files directly into a container in Kubernetes on Google Cloud Engine, similar to the way that you can mount host files / directories with Docker, e.g.</p>

<pre><code>docker run -d --name nginx -p 443:443 -v "/nginx.ssl.conf:/etc/nginx/conf.d/default.conf"
</code></pre>

<p>Thanks</p>

<p>It is possible to use ConfigMaps to achieve that goal:</p>

<p>The following example mounts a mariadb configuration file into a mariadb POD:</p>



<p><strong>ConfigMap</strong></p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
data:
  charset.cnf: |
    [client]
    # Default is Latin1, if you need UTF-8 set this (also in server section)
    default-character-set = utf8 

    [mysqld]
    #
    # * Character sets
    #
    # Default is Latin1, if you need UTF-8 set all this (also in client section)
    #
    character-set-server  = utf8 
    collation-server      = utf8_unicode_ci 

kind: ConfigMap
metadata:
  name: mariadb-configmap
</code></pre>

<p><strong>MariaDB deployment</strong></p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mariadb
  labels:
    app: mariadb  
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: mariadb
        version: 10.1.16
    spec:
      containers:
      - name: mariadb
        image: mariadb:10.1.16
        ports:
        - containerPort: 3306
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mariadb
              key: rootpassword
        volumeMounts:
        - name: mariadb-data
          mountPath: /var/lib/mysql
        - name: mariadb-config-file
          mountPath: /etc/mysql/conf.d   
      volumes:
      - name: mariadb-data
        hostPath: 
          path: /var/lib/data/mariadb
      - name: mariadb-config-file
        configMap:
          name: mariadb-configmap
</code></pre>

<p>It is also possible to use subPath feature that is available in kubernetes from version 1.3, as stated <a href="https://github.com/kubernetes/kubernetes/issues/23748#issuecomment-230390309" rel="noreferrer">here</a>.</p>
