Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass a configuration file thought yaml on kubernetes to create new replication controller

Tags:

kubernetes

i am trying to pass a configuration file(which is located on master) on nginx container at the time of replication controller creation through kubernetes.. ex. as we are using ADD command in Dockerfile...

like image 381
Jogendra Kumar Avatar asked Dec 10 '22 19:12

Jogendra Kumar


2 Answers

There isn't a way to dynamically add file to a pod specification when instantiating it in Kubernetes.

Here are a couple of alternatives (that may solve your problem):

  1. Build the configuration file into your container (using the docker ADD command). This has the advantage that it works in the way which you are already familiar but the disadvantage that you can no longer parameterize your container without rebuilding it.

  2. Use environment variables instead of a configuration file. This may require some refactoring of your code (or creating a side-car container to turn environment variables into the configuration file that your application expects).

  3. Put the configuration file into a volume. Mount this volume into your pod and read the configuration file from the volume.

  4. Use a secret. This isn't the intended use for secrets, but secrets manifest themselves as files inside your container, so you can base64 encode your configuration file, store it as a secret in the apiserver, and then point your application to the location of the secret file that is created inside your pod.

like image 97
Robert Bailey Avatar answered Jan 04 '23 00:01

Robert Bailey


I believe you can also download config during container initialization. See example below, you may download config instead index.html but I would not use it for sensetive info like passwords.

apiVersion: v1
kind: Pod
metadata:
  name: init-demo
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - name: workdir
      mountPath: /usr/share/nginx/html
  # These containers are run during pod initialization
  initContainers:
  - name: install
    image: busybox
    command:
    - wget
    - "-O"
    - "/work-dir/index.html"
    - http://kubernetes.io
    volumeMounts:
    - name: workdir
      mountPath: "/work-dir"
  dnsPolicy: Default
  volumes:
  - name: workdir
    emptyDir: {}
like image 26
mapcuk Avatar answered Jan 04 '23 00:01

mapcuk