adding docker run --log-opt arguments to deployments

1,015 views
Skip to first unread message

bal...@gmail.com

unread,
Jun 27, 2017, 6:20:40 PM6/27/17
to Kubernetes user discussion and Q&A
Hi all

We are trying to add docker logging options to our kubernetes deployments for log rolling e.g --log-opt max-size=10m

For example if we ran something like this directly using docker

docker run -it --log-opt max-size=10m --log-opt max-file=2 image-name

We can use docker inspect to see those options added to the LogConfig e.g

"LogConfig": {
"Type": "json-file",
"Config": {
"max-file": "2",
"max-size": "10m"
}
},

Here is what we have defined in our deployment:

containers:
- image: ourlocalrepo/deployments/our_pod:latest
command:
- java
- -Djava.security.egd=file:/dev/./urandom
- -Dlog4j.configurationFile=/etc/logs-config/log4j2.xml
- -Xms128m
- -Xmx256m
- -jar
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
imagePullPolicy: Always
name: "our_pod"
ports:
- containerPort: 80
protocol: TCP
args:
- "--log-opt max-size=10m"
- "--log-opt max-file=2"

But when this deployment is run and the pod comes up on a node i can use docker inspect and see that these args are added to Cmd:

"Cmd": [
"--log-opt max-size=10m",
"--log-opt max-file=2"
],

Instead of the LogConfig section as they should be - it still looks like this :

"LogConfig": {
"Type": "json-file",
"Config": {}
},

Can anyone point me the right direction to get the kubernetes deployment to add these log options?

thanks!!

Rodrigo Campos

unread,
Jun 27, 2017, 7:52:22 PM6/27/17
to kubernet...@googlegroups.com
IIUC, you are trying to give args to the docker daemon when running
this, rather than args to your container image. Is this correct?

If that is the case, that will never work. Command and args are like
used in Dockerfile (or docker cli, you can overwrite them there too).
But are options given to the container, they specify which command and
which arguments to use when running the image. And is not possible to
give options to the docker daemon there, AFAIK

Command and args spec definition are these:
https://kubernetes.io/docs/api-reference/v1.6/#container-v1-core (see
"args" and "command" there). Like CMD in the Dockerfile,
https://docs.docker.com/engine/reference/builder/#cmd, and ARG in the
Dockerfile, https://docs.docker.com/engine/reference/builder/#arg.

I don't know, though, how to change those options for the docker
daemon. Probably the kubelet might be involved, but never changed
those myself in kubernetes.
> --
> You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-use...@googlegroups.com.
> To post to this group, send email to kubernet...@googlegroups.com.
> Visit this group at https://groups.google.com/group/kubernetes-users.
> For more options, visit https://groups.google.com/d/optout.

Matthias Rampke

unread,
Jun 28, 2017, 3:07:17 AM6/28/17
to Kubernetes user discussion and Q&A


On Wed, Jun 28, 2017, 01:52 Rodrigo Campos <rodr...@gmail.com> wrote:

I don't know, though, how to change those options for the docker
daemon. Probably the kubelet might be involved, but never changed
those myself in kubernetes.

The kubelet doesn't start Docker itself, so you'll have to do this wherever your OS is configured to do that. On Debian, we set those options in /etc/defaults/docker.

/MR

Henry Hottelet

unread,
Dec 7, 2017, 2:15:40 PM12/7/17
to Kubernetes user discussion and Q&A
I see what you want to do with passing java arguments to the Kubernetes Pod definition.

I had the same problem described here:

Did you have any success resolving the problem of passing java arguments to a Kubernetes Pod service?

Please let me know.
Reply all
Reply to author
Forward
0 new messages