26

Hi I am running kubernetes cluster where I run mailhog container.

But I need to run it with own docker run parameter. If I would run it in docker directly. I would use command:

docker run  mailhog/mailhog -auth-file=./auth.file

But I need to run it via Kubernetes pod. My pod looks like:

   apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: mailhog
    spec:
      replicas: 1
      revisionHistoryLimit: 1
      strategy:
          type: RollingUpdate
      template:
        metadata:
          labels:
            app: mailhog
        spec:
          containers:
          - name: mailhog
            image: us.gcr.io/com/mailhog:1.0.0
            ports:
            - containerPort: 8025

How to achieve to run Docker container with parameter -auth-file=./auth.file via kubernetes. Thanks.

I tried adding under containers

        command: ["-auth-file", "/data/mailhog/auth.file"]

but then I get

 Failed to start container with docker id 7565654 with error: Error response from daemon: Container command '-auth-file' not found or does not exist.
ushuz
  • 493
  • 5
  • 12
dina
  • 4,039
  • 6
  • 39
  • 67

4 Answers4

27

thanks to @lang2

here is my deployment.yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mailhog
spec:
  replicas: 1
  revisionHistoryLimit: 1
  strategy:
      type: RollingUpdate
  template:
    metadata:
      labels:
        app: mailhog
    spec:
      volumes:
      - name: secrets-volume
        secret:
            secretName: mailhog-login
      containers:
      - name: mailhog
        image: us.gcr.io/com/mailhog:1.0.0
        resources:
          limits:
            cpu: 70m
            memory: 30Mi
          requests:
            cpu: 50m
            memory: 20Mi
        volumeMounts:
        - name: secrets-volume
          mountPath: /data/mailhog
          readOnly: true
        ports:
        - containerPort: 8025
        - containerPort: 1025
        args:
          - "-auth-file=/data/mailhog/auth.file"
dina
  • 4,039
  • 6
  • 39
  • 67
10

In kubernetes, command is equivalent of ENTRYPOINT. In your case, args should be used.

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#container-v1-core

Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
lang2
  • 11,433
  • 18
  • 83
  • 133
9

You are on the right track. It's just that you also need to include the name of the binary in the command array as the first element. You can find that out by looking​ in the respective Dockerfile (CMD and/or ENTRYPOINT).

In this case: command: ["Mailhog", "-auth-file", "/data/mailhog/auth.file"]

Janos Lenart
  • 25,074
  • 5
  • 73
  • 75
2

I needed similar task (my aim was passing the application profile to app) and what I did is the following:

Setting an environment variable in Deployment section of the kubernetes yml file.

env:
- name: PROFILE
  value: "dev"

Using this environment variable in dockerfile as command line argument.

CMD java -jar -Dspring.profiles.active=${PROFILE} /opt/app/xyz-service-*.jar 
Utku A.
  • 738
  • 8
  • 8