How to reduce boilerplate of Kubernetes sidecar containers?

6/1/2016

I have several microservices running on Kubernetes. Each microservice is a pod consisting of the microservice container and sidecar container to handle logging. I end up having to define the sidecars for each service, and it is pretty verbose:

apiVersion: v1
kind: ReplicationController
metadata:
  name: thing-doer
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: thing-doer
    spec:
      containers:
      - name: thing-doer
        image: myregistry/thingdoer
        ports:
        - containerPort: 8080
        volumeMounts:
        - mountPath: /logs
          name: logs
      - name: logger
        image: myregistry/logger
        volumeMounts:
        - mountPath: /logs
          name: logs
        - mountPath: /logger-config
          name: logger-config
      volumes:
      - name: logs
        emptyDir: {}
      - name: logger-config
        configMap:
          name: logger-configmap
          items:
          - key: config-yaml
            path: config.yaml

I end up having to repeat these same steps for each microservice:

  1. Create log volume
  2. Create log-config volume populated from ConfigMap
  3. Create logger container
  4. Mount log volume to logger container
  5. Mount log volume to microservice container
  6. Mount log-config volume to logger container

Is there any to reduce this boilerplate and make it composable somehow? Can I just specify that I want this pod to be "loggable" and have it perform the steps I need?

-- Pixel Elephant
kubernetes

3 Answers

6/2/2016

Kubernetes has another project that is https://github.com/helm/charts https://github.com/kubernetes/helm but it is alpha stages. Helm is like package manager. Probably you could have chart with dependencies. I am not sure. But you could look into that.

HTH

-- Naveen
Source: StackOverflow

6/2/2016

You could maybe run the sidecar as a Daemonset on each host, and either write logs to a host volume or pick up logs from Docker and centralize them from there.

-- Steve Sloka
Source: StackOverflow

6/2/2016

Kubernetes doesn't provide any sort of config file templating or composition. But it wouldn't be difficult to write a tool that would do this and generate the YAML files (e.g. a pre-processing step).

-- Robert Bailey
Source: StackOverflow