Let user upload a file to a container's volume through the Management Console?

Hi,

Is it possible to let users upload files to a specific container’s volume path through the Managment Console Settings?

Using Kuberentes Scheduler.

Thanks,

1 Like

Yep – you can allow customers to upload files via the config section. The process for getting the files into Replicated is the same for all schedulers, and then there’s some kubernetes-specific things to know for mounting those files into your workloads.

Getting files – All Schedulers

You can use a Config Option of type file to create a file upload Widget on the “Settings” screen of the Replicated Admin console.

For example, you could use something like this in your config section:

config:
- name: config_files
  title: Custom Configuration Files
  description: |
    Upload a file below for advanced integration configuration. 
  items:
  - name: nginx_conf
    title: Custom Nginx Configs
    type: file
    required: true

Mounting in Kubernetes

To mount the contents of files in kubernetes, you can store them in a Secret or a ConfigMap, and then mount that into your Deployment/Pod/etc, as we did for Mounting SSL Certs:

yaml
---
# kind: scheduler-kubernetes
# A generic v1/Secret that stores the custom files
apiVersion: v1
kind: Secret
metadata:
  name: nginx_conf
data:
  nginx.conf: '{{repl ConfigOptionData "nginx_conf" | Base64Encode }}'
---
# kind: scheduler-kubernetes
# An example nginx deployment that consumes the secret
apiVersion: apps/v1
kind: Deployment
metadata:
  name: www
  labels:
    tier: www
spec:
  selector:
    matchLabels:
      tier: www
  replicas: 3
  template:
    metadata:
      labels:
        tier: www
    spec: 
      volumes:
      - name: nginx_conf
        secret:
          secretName: nginx_conf
      containers:
      - name: www-test-container
        image: nginx:latest
        volumeMounts:
        - name: nginx_conf
          readOnly: true
          mountPath: "/etc/nginx/extra_configs/"

This will cause the file to be mounted at /etc/nginx/extra_configs/nginx.conf.

Edit: Change ConfigOption to ConfigOptionData per Dan’s comment.

Thanks Dex! You were just missing ConfigOptionData instead of ConfigOption.

nginx.conf: '{{repl ConfigOptionData "nginx_conf" | Base64Encode }}'

This didn’t work out for me as I was looking to be able to upload a file larger than 1mb, but I guess this is not a good practice anyway.

Ah – good catch. Thanks @Dan_Peleg ! Updated