Kubernetes: Perform command shell only container

6/22/2018

I'm using this spec that contains one init container and two containers.

Init container creates a file on /etc/secrets/secrets.env that the first container has to source: source /etc/secrets/secrets.env.

I'm trying to do that using this spec:

    spec:
      containers:
      - name: source-envs
        image: ????
        command: ["/bin/sh", "-c", "source /etc/secrets/secrets.env"]

      volumes:
      - name: sidekick-backend-volume
        emptyDir: {}

I don't quite figure out how to do that.

Any ideas?

-- Jordi
kubernetes

1 Answer

6/22/2018

It should work by sharing a volume between the init container and the first container, mounted on /etc/secrets:

spec:
  initContainers:
  - name: create-envs
    image: ????
    command: ["/bin/sh", "-c", "touch /etc/secrets/secrets.env"]
    volumeMounts:
     - mountPath: /etc/secrets/
       name: sidekick-backend-volume
  containers:
  - name: source-envs
    image: ????
    command: ["/bin/sh", "-c", "source /etc/secrets/secrets.env"]
    volumeMounts:
     - mountPath: /etc/secrets/
       name: sidekick-backend-volume

  volumes:
  - name: sidekick-backend-volume
    emptyDir: {}
-- Ignacio Millán
Source: StackOverflow