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:
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?
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
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.
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).