如何通过kubernetes pod传递docker运行标志
您好我正在运行kubernetes群集,我运行mailhog容器。
但我需要运行它自己的docker运行参数。 如果我会直接在docker中运行它。 我会使用命令:
docker run mailhog/mailhog -auth-file=./auth.file
但我需要通过Kubernetes吊舱运行。 我的豆荚看起来像:
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
如何通过kubernetes实现通过参数-auth-file = ./ auth.file来运行Docker容器。 谢谢。
我尝试在containers
下添加
command: ["-auth-file", "/data/mailhog/auth.file"]
但是我得到了
Failed to start container with docker id 7565654 with error: Error response from daemon: Container command '-auth-file' not found or does not exist.
你在正确的轨道上。 只是你还需要在command
数组中包含二进制文件的名称作为第一个元素。 您可以通过查看相应的Dockerfile
( CMD
和/或ENTRYPOINT
)来ENTRYPOINT
。
在这种情况下: command: ["Mailhog", "-auth-file", "/data/mailhog/auth.file"]
在kubernetes中, command
相当于进入ENTRYPOINT
。 在你的情况下,应该使用args
。
https://kubernetes.io/docs/api-reference/v1.6/#container-v1-core
感谢@ lang2
这里是我的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"